From: Eli Friedman Date: Sat, 17 Dec 2011 02:24:21 +0000 (+0000) Subject: Add a missing check before trying to evaluate a temporary. PR11595. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f59ff8c777379bd54137853a58c58b72fb869152;p=clang Add a missing check before trying to evaluate a temporary. PR11595. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146813 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 31b211eff6..0d32ebf1c6 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -2066,6 +2066,9 @@ public: return false; BaseTy = E->getBase()->getType()->getAs()->getPointeeType(); } else if (E->getBase()->isRValue()) { + if (!E->getBase()->getType()->isRecordType() || + !E->getBase()->getType()->isLiteralType()) + return false; if (!EvaluateTemporary(E->getBase(), Result, this->Info)) return false; BaseTy = E->getBase()->getType(); diff --git a/test/SemaCXX/constant-expression-cxx11.cpp b/test/SemaCXX/constant-expression-cxx11.cpp index 5105418af1..5b053e4ce6 100644 --- a/test/SemaCXX/constant-expression-cxx11.cpp +++ b/test/SemaCXX/constant-expression-cxx11.cpp @@ -919,3 +919,9 @@ static_assert(makeComplexWrap(1,0) == complex(1), ""); static_assert(makeComplexWrap(1,0) != complex(0, 1), ""); } + +namespace PR11595 { + struct A { constexpr bool operator==(int x) { return true; } }; + struct B { B(); ~B(); A& x; }; + static_assert(B().x == 3, ""); // expected-error {{constant expression}} +}