From 2d48e7811216b2a2d15dcf7e4be8f73ad48cc60a Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Sat, 19 Dec 2009 07:07:47 +0000 Subject: [PATCH] A CXXExprWithTemporaries expression is an lvalue if its subexpression is an lvalue. Fixes PR5787. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91765 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Expr.cpp | 10 ++++++++++ .../dcl.decl/dcl.init/dcl.init.ref/basic.cpp | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/CXX/dcl.decl/dcl.init/dcl.init.ref/basic.cpp diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index dcf4411d85..034b91ed0f 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1213,6 +1213,16 @@ Expr::isLvalueResult Expr::isLvalueInternal(ASTContext &Ctx) const { return LV_Valid; } + case Expr::CXXExprWithTemporariesClass: + return cast(this)->getSubExpr()->isLvalue(Ctx); + + case Expr::ObjCMessageExprClass: + if (const ObjCMethodDecl *Method + = cast(this)->getMethodDecl()) + if (Method->getResultType()->isLValueReferenceType()) + return LV_Valid; + break; + default: break; } diff --git a/test/CXX/dcl.decl/dcl.init/dcl.init.ref/basic.cpp b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/basic.cpp new file mode 100644 index 0000000000..885d11b9c2 --- /dev/null +++ b/test/CXX/dcl.decl/dcl.init/dcl.init.ref/basic.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// PR5787 +class C { + public: + ~C() {} +}; + +template +class E { + public: + E& Foo(const C&); + E& Bar() { return Foo(C()); } +}; + +void Test() { + E e; + e.Bar(); +} -- 2.40.0