<div class="gmail_quote">On Wed, Aug 29, 2012 at 1:44 AM, Hans Wennborg <span dir="ltr"><<a href="mailto:hans@hanshq.net" target="_blank">hans@hanshq.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: hans<br>
Date: Wed Aug 29 03:44:49 2012<br>
New Revision: 162835<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=162835&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=162835&view=rev</a><br>
Log:<br>
The address of a TLS var is not compile-time constant (PR13720)<br>
<br>
This makes Clang produce an error for code such as:<br>
<br>
  __thread int x;<br>
  int *p = &x;<br>
<br>
The lvalue of a thread-local variable cannot be evaluated at compile<br>
time.<br>
<br>
Modified:<br>
    cfe/trunk/lib/AST/ExprConstant.cpp<br>
    cfe/trunk/test/Sema/init.c<br>
<br>
Modified: cfe/trunk/lib/AST/ExprConstant.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=162835&r1=162834&r2=162835&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=162835&r1=162834&r2=162835&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)<br>
+++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Aug 29 03:44:49 2012<br>
@@ -2832,6 +2832,8 @@<br>
 }<br>
<br>
 bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl *VD) {<br>
+  if (VD->isThreadSpecified())<br>
+    return false;<br></blockquote><div><br></div><div>That should be 'return Error(E);' (constant expression evaluation shouldn't fail without producing a diagnostic). As a testcase, we should reject this:</div>
<div><br></div><div>__thread int n;</div><div>constexpr int &f() { return n; }</div></div>