[cfe-commits] r162835 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/Sema/init.c

Richard Smith richard at metafoo.co.uk
Wed Aug 29 02:40:53 PDT 2012


On Wed, Aug 29, 2012 at 2:20 AM, Hans Wennborg <hans at chromium.org> wrote:

> On Wed, Aug 29, 2012 at 10:05 AM, Richard Smith <richard at metafoo.co.uk>
> wrote:
> > On Wed, Aug 29, 2012 at 1:44 AM, Hans Wennborg <hans at hanshq.net> wrote:
> >>  bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl
> *VD)
> >> {
> >> +  if (VD->isThreadSpecified())
> >> +    return false;
> >
> > That should be 'return Error(E);' (constant expression evaluation
> shouldn't
> > fail without producing a diagnostic). As a testcase, we should reject
> this:
> >
> > __thread int n;
> > constexpr int &f() { return n; }
>
> Thanks, Richard! Fixed in r162837.


Thanks.

I've looked into what's specified for C++11 constant expression semantics,
and it looks like this isn't the correct behavior there. C++11 thread_local
variables *can* be used in core constant expressions, but can't be part of
the eventual result of constant expression evaluation. It looks like the
check belongs in CheckLValueConstantExpression instead.

For instance, this is valid under the C++11 rules:

thread_local int n;
constexpr bool b = &n == &n;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120829/230ccf8d/attachment.html>


More information about the cfe-commits mailing list