From: Douglas Gregor Date: Wed, 23 Sep 2009 22:51:26 +0000 (+0000) Subject: Make C++ temporary-related expressions provide proper source-range information. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=96be6917e1c4ba1f4435a14c9e7c6c139571d086;p=clang Make C++ temporary-related expressions provide proper source-range information. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82665 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 0435d21483..3f66b1f40b 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -466,7 +466,9 @@ public: Expr *getSubExpr() { return cast(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 @@ public: 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 @@ public: const Expr *getSubExpr() const { return cast(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) { diff --git a/test/SemaCXX/references.cpp b/test/SemaCXX/references.cpp index 9067a8661d..e03abf4300 100644 --- a/test/SemaCXX/references.cpp +++ b/test/SemaCXX/references.cpp @@ -87,3 +87,18 @@ void test8(int& const,// expected-error{{'const' qualifier may not be applied to 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}} +}