diff options
-rw-r--r-- | lib/AST/ExprConstant.cpp | 3 | ||||
-rw-r--r-- | test/SemaCXX/constant-expression-cxx11.cpp | 6 |
2 files changed, 9 insertions, 0 deletions
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<PointerType>()->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}} +} |