[cfe-commits] r151399 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/SemaCXX/lambda-expressions.cpp

Richard Smith richard at metafoo.co.uk
Fri Feb 24 15:27:07 PST 2012


On Fri, Feb 24, 2012 at 2:54 PM, Eli Friedman <eli.friedman at gmail.com>wrote:

> On Fri, Feb 24, 2012 at 2:12 PM, Richard Smith
> <richard-llvm at metafoo.co.uk> wrote:
> > Author: rsmith
> > Date: Fri Feb 24 16:12:32 2012
> > New Revision: 151399
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=151399&view=rev
> > Log:
> > When checking whether a reference to a variable is an ICE, look at the
> type of
> > the declaration, not at the type of the DeclRefExpr, since within a
> lambda the
> > DeclRefExpr can be more const than the declaration is.
> >
> > Modified:
> >    cfe/trunk/lib/AST/ExprConstant.cpp
> >    cfe/trunk/test/SemaCXX/lambda-expressions.cpp
> >
> > Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=151399&r1=151398&r2=151399&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> > +++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Feb 24 16:12:32 2012
> > @@ -6379,12 +6379,12 @@
> >       return CheckEvalInICE(E, Ctx);
> >     return ICEDiag(2, E->getLocStart());
> >   }
> > -  case Expr::DeclRefExprClass:
> > +  case Expr::DeclRefExprClass: {
> >     if (isa<EnumConstantDecl>(cast<DeclRefExpr>(E)->getDecl()))
> >       return NoDiag();
> > -    if (Ctx.getLangOptions().CPlusPlus &&
> IsConstNonVolatile(E->getType())) {
> > -      const NamedDecl *D = cast<DeclRefExpr>(E)->getDecl();
> > -
> > +    const ValueDecl *D =
> dyn_cast<ValueDecl>(cast<DeclRefExpr>(E)->getDecl());
> > +    if (Ctx.getLangOptions().CPlusPlus &&
> > +        D && IsConstNonVolatile(D->getType())) {
> >       // Parameter variables are never constants.  Without this check,
> >       // getAnyInitializer() can find a default argument, which leads
> >       // to chaos.
> > @@ -6408,6 +6408,7 @@
> >       }
> >     }
> >     return ICEDiag(2, E->getLocStart());
> > +  }
> >   case Expr::UnaryOperatorClass: {
> >     const UnaryOperator *Exp = cast<UnaryOperator>(E);
> >     switch (Exp->getOpcode()) {
> >
> > Modified: cfe/trunk/test/SemaCXX/lambda-expressions.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/lambda-expressions.cpp?rev=151399&r1=151398&r2=151399&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/test/SemaCXX/lambda-expressions.cpp (original)
> > +++ cfe/trunk/test/SemaCXX/lambda-expressions.cpp Fri Feb 24 16:12:32
> 2012
> > @@ -101,3 +101,30 @@
> >     f(v, [](){});
> >   }
> >  }
> > +
> > +namespace NullPtr {
> > +  int &f(int *p);
> > +  char &f(...);
> > +  void g() {
> > +    int n = 0;
> > +    [=] {
> > +      char &k = f(n); // not a null pointer constant
> > +    } ();
> > +
> > +    const int m = 0;
> > +    [=] {
> > +      int &k = f(m); // a null pointer constant
> > +    } ();
> > +
> > +    // FIXME: At least the second of these cases should probably not be
> > +    // considered to be a null pointer constant.
> > +    [=] () -> bool {
> > +      int &k = f(m);  // a null pointer constant?
> > +      return &m == 0; // no, captured!
> > +    } ();
> > +
> > +    [m] {
> > +      int &k = f(m); // a null pointer constant?
> > +    } ();
>
> I don't follow what you're trying to test here... IIRC, whether a

variable is captured should have no effect on whether a particular use
> is an odr-use.


Ah, sorry, I missed that part of p17. I've taken out the FIXME in r151405,
but left the tests in.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120224/ac98a115/attachment.html>


More information about the cfe-commits mailing list