aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2012-08-29 09:17:34 +0000
committerHans Wennborg <hans@hanshq.net>2012-08-29 09:17:34 +0000
commit29f431b3e310ae6bd367dccf5a2794ad1cac9592 (patch)
treef76a0369e22111d8634d7dd221e83c3bd292152a
parent0f87dd74fe1f4fc2bafe16f708500d68ed04d442 (diff)
Fix r162835 as per Richard's comments.
VisitVarDecl should return Error(E), and we should test that the address of a TLS var can't be used as a constexpr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162837 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/ExprConstant.cpp2
-rw-r--r--test/SemaCXX/constant-expression-cxx11.cpp7
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index 6b88246f82..ac21b46941 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -2833,7 +2833,7 @@ bool LValueExprEvaluator::VisitDeclRefExpr(const DeclRefExpr *E) {
bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl *VD) {
if (VD->isThreadSpecified())
- return false;
+ return Error(E);
if (!VD->getType()->isReferenceType()) {
if (isa<ParmVarDecl>(VD)) {
Result.set(VD, Info.CurrentCall->Index);
diff --git a/test/SemaCXX/constant-expression-cxx11.cpp b/test/SemaCXX/constant-expression-cxx11.cpp
index a3ead79a84..984ee1b08b 100644
--- a/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1374,3 +1374,10 @@ namespace ConditionalLValToRVal {
constexpr A a(4);
static_assert(f(a).v == 4, "");
}
+
+namespace TLS {
+ __thread int n;
+ constexpr int &f() { // expected-error {{constexpr function never produces a constant expression}}
+ return n; // expected-note {{subexpression not valid in a constant expression}}
+ }
+}