[cfe-commits] r82665 - in /cfe/trunk: include/clang/AST/ExprCXX.h test/SemaCXX/references.cpp

Douglas Gregor dgregor at apple.com
Wed Sep 23 15:51:26 PDT 2009


Author: dgregor
Date: Wed Sep 23 17:51:26 2009
New Revision: 82665

URL: http://llvm.org/viewvc/llvm-project?rev=82665&view=rev
Log:
Make C++ temporary-related expressions provide proper source-range information.

Modified:
    cfe/trunk/include/clang/AST/ExprCXX.h
    cfe/trunk/test/SemaCXX/references.cpp

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=82665&r1=82664&r2=82665&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Wed Sep 23 17:51:26 2009
@@ -466,7 +466,9 @@
   Expr *getSubExpr() { return cast<Expr>(SubExpr); }
   void setSubExpr(Expr *E) { SubExpr = E; }
 
-  virtual SourceRange getSourceRange() const { return SourceRange(); }
+  virtual SourceRange getSourceRange() const { 
+    return SubExpr->getSourceRange();
+  }
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Stmt *T) {
@@ -539,7 +541,13 @@
     Args[Arg] = ArgExpr;
   }
 
-  virtual SourceRange getSourceRange() const { return SourceRange(); }
+  virtual SourceRange getSourceRange() const { 
+    // FIXME: Should we know where the parentheses are, if there are any?
+    if (NumArgs == 0)
+      return SourceRange(); 
+    
+    return SourceRange(Args[0]->getLocStart(), Args[NumArgs - 1]->getLocEnd());
+  }
 
   static bool classof(const Stmt *T) {
     return T->getStmtClass() == CXXConstructExprClass ||
@@ -1289,7 +1297,9 @@
   const Expr *getSubExpr() const { return cast<Expr>(SubExpr); }
   void setSubExpr(Expr *E) { SubExpr = E; }
 
-  virtual SourceRange getSourceRange() const { return SourceRange(); }
+  virtual SourceRange getSourceRange() const { 
+    return SubExpr->getSourceRange();
+  }
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Stmt *T) {

Modified: cfe/trunk/test/SemaCXX/references.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/references.cpp?rev=82665&r1=82664&r2=82665&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/references.cpp (original)
+++ cfe/trunk/test/SemaCXX/references.cpp Wed Sep 23 17:51:26 2009
@@ -87,3 +87,18 @@
 
   typedef intref const intref_c; // okay. FIXME: how do we verify that this is the same type as intref?
 }
+
+
+class string {
+  char *Data;
+  unsigned Length;
+public:
+  string(); 
+  ~string();
+};
+
+string getInput();
+
+void test9() {
+  string &s = getInput(); // expected-error{{lvalue reference}}
+}





More information about the cfe-commits mailing list