Constant evaluator only considered access to this pointer to be
possible if this poitners was captured. However this can also appear if
there was a default member initializer.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thank you for this patch, it looks good.
clang/lib/AST/ExprConstant.cpp | ||
---|---|---|
8763–8766 | It might be worth it to review all the examples here: https://eel.is/c++draft/expr.prim.lambda and make sure the test we have actually covers all the scenarios. It looks like we capture most of them but I have not gone over them fully. | |
clang/test/SemaCXX/lambda-expressions.cpp | ||
673 | It would be helpful to add a comment about the implicit this access. |
clang/lib/AST/ExprConstant.cpp | ||
---|---|---|
8763–8766 | At least the ones about this capture seem to be working and covered. Not all of them have the same behavior as described though, for example on https://eel.is/c++draft/expr.prim.lambda#closure-6 clang complains about missing capture, though gcc agrees https://godbolt.org/z/hfxbEP5fW , so this is probably a bug in the example. Anyway I think this is a bit out of the scope of the patch. |
LGTM, the modules failures is a previous known issue.
clang/lib/AST/ExprConstant.cpp | ||
---|---|---|
8763–8766 | I will dig into that discrepancy. |
clang/lib/AST/ExprConstant.cpp | ||
---|---|---|
8763–8766 | If you move the lambda to be a global, it works: https://godbolt.org/z/84ax7518o which is what the original example has. |
Thanks for the review @shafik .
clang/lib/AST/ExprConstant.cpp | ||
---|---|---|
8763–8766 | Yes, this is understandable. But in the example there is also an assert which doesn't do well in global scope. BTW, in case this is interesting, another one that doesn't seem to be working with clang is https://eel.is/c++draft/expr.prim.lambda#capture-example-2 |
clang/lib/AST/ExprConstant.cpp | ||
---|---|---|
8763–8766 |
Oh interesting, I missed that one!
Another interesting one, if we change it to int y clang diagnoses it: https://godbolt.org/z/rjx71qj8j I am not sure what the (y) means I think that should be ill-formed, seems like a clang bug. Let me look at it some more. Thank you for doing this deeper look. |
clang/lib/AST/ExprConstant.cpp | ||
---|---|---|
8763–8766 | (y) is a type b/c it is a template parameter, duh! I filed a bug report against clang: https://github.com/llvm/llvm-project/issues/61105 |
It might be worth it to review all the examples here: https://eel.is/c++draft/expr.prim.lambda
and make sure the test we have actually covers all the scenarios. It looks like we capture most of them but I have not gone over them fully.