title: Evaluating constant expressions in clang tools
body: <p>I'm writing a Clang tool and I'm trying to figure out how to evaluate a string literal given access to the program's AST. Given the following program:</p>
  
  <pre><code>class DHolder { 
  public:
    DHolder(std::string s) {}
  };
  
  DHolder x("foo");    
  </code></pre>
  
  <p>I have the following code in the Clang tool:</p>
  
  <pre><code>const CXXConstructExpr *ctor = ... // constructs `x` above
  const Expr *expr = ctor-&gt;getArg(0); // the "foo" expression
  ???
  </code></pre>
  
  <p>How can I get from the <code>Expr</code> representing the <code>"foo"</code> string literal to an actual C++ string in my tool? I've tried to do something like:</p>
  
  <pre><code>// From ExprConstant.cpp
  Evaluate(result, info, expr);
  </code></pre>
  
  <p>but I don't know how to initialize the <code>result</code> and <code>info</code> parameters.</p>
  
  <p>Any clues?</p>