[PATCH] D29748: [cxx1z-constexpr-lambda] Implement captures - thus completing implementation of constexpr lambdas.

Hubert Tong via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 9 19:25:23 PST 2017


hubert.reinterpretcast added inline comments.


================
Comment at: lib/AST/ExprConstant.cpp:5061
+          APValue RVal;
+          // FIXME: We need to make sure we're passing the right type that
+          // maintains cv-qualifiers.
----------------
faisalv wrote:
> rsmith wrote:
> > faisalv wrote:
> > > I don't think we need this fixme - the type of the expression should be correct - all other const checks for mutability have already been performed, right?
> > When using `handleLValueToRValueConversion` to obtain the lvalue denoted by a reference, the type you pass should be the reference type itself (`FD->getType()`). This approach will give the wrong answer when using a captured volatile object:
> > ```
> > void f() {
> >   volatile int n;
> >   constexpr volatile int *p = [&]{ return &n; }(); // should be accepted
> > }
> > ```
> OK - but how is the address of a local variable a constant expression?
I guess this one is safer:
```
void f() {
  volatile int n;
  constexpr volatile int *p = [&]{ return false ? &n : nullptr; }();
}
```


https://reviews.llvm.org/D29748





More information about the cfe-commits mailing list