[PATCH] D92733: Fix PR25627 - false positive diagnostics involving implicit-captures in dependent lambda expressions.
Faisal Vali via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 6 10:51:03 PST 2020
faisalv created this revision.
faisalv added reviewers: rsmith, aaron.ballman, wchilders, BRevzin.
faisalv added a project: clang.
faisalv requested review of this revision.
This patch attempts to address the following bugs involving lambda-captures:
1. /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.
2. 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.
3. I do have some questions, regarding the intended behavior:
[] {
if (false) {
const int& i = I; <-- This is diagnosed, should it be - even though it is never instantiated?
}
};
[](auto a) {
if (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!
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D92733
Files:
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/CXX/basic/basic.def.odr/p2.cpp
clang/test/CXX/drs/dr7xx.cpp
clang/test/SemaCXX/PR25627-generic-lambdas-capturing.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92733.309780.patch
Type: text/x-patch
Size: 32042 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201206/e3a13651/attachment-0001.bin>
More information about the cfe-commits
mailing list