[4/11/22] I am updating this patch and syncing it up w the current working tree - hopefully will post something within a week or so - and address wyatts comments too.
This patch attempts to address the following bugs involving lambda-captures:
- /https://bugs.llvm.org/show_bug.cgi?id=25627 which emits a false positive diagnostic for the following code: `void f() { constexpr int I = 10; [](auto a) { return I; }; };`
- this occurs because our current logic does not recognize that even though our expressions are not instantiation dependent, if that expression is being used to initialize some dependent entity, an lvalue-to-rvalue conversion might still be introduced during the instantiation, which might avert odr-use. (we do not do return type deduction until instantiation).
- to address this, I pass in the destination type to ActOnFullExpr, if the expression might be used in such an initialization, and use a PotentialResultsVisitor to determine the potential results of the full-expression, and then use all that information to avoid such false positive diagnostics.
- it fixes any unnecessary odr-uses triggered in discarded-value expressions and thus some tests marked as FIXMES.
- we simply make a call to CheckLValueToRValueConversionOperand() that rebuilds the relevant AST marking each potential result as non-odr-used for discarded value expressions even in the absence of an lvalue-to-rvalue conversion.
- I do have some questions, regarding the intended behavior (assuming a constexpr local-entity I in the enclosing scope):
[] (auto a) { if constexpr (false) { const int& i = I; <-- This is diagnosed, should it be - even though it is never instantiated? } }; [](auto a) { if constexpr (sizeof(a) < 0) { const int &i = I; <-- This is diagnosed, should it be - even though it is never instantiated? } } struct X { constexpr static int s = 10; int i = 10; }; void f() { constexpr X x; [] { int i = x.s; // <-- This is diagnosed, should it be - even though it does not really use 'x' since 's' is static int j = x.i; // this does not odr-use x. }; }
Thank you!
clang-format: please reformat the code