[PATCH] D63889: Check possible warnings on global initializers for reachability
Richard Smith - zygoloid via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 21 04:54:03 PDT 2019
rsmith added inline comments.
================
Comment at: clang/lib/Sema/SemaDeclCXX.cpp:352
SetParamDefaultArgument(Param, DefaultArg, EqualLoc);
+ CurContext->removeDecl(Param);
+ CurContext = Cur;
----------------
We may need to delay the diagnostics here until the default argument is *used*: if a default argument references a template instantiation, the instantiation is not performed until that point, which may mean that our semantic checking can't complete correctly until use.
================
Comment at: clang/lib/Sema/SemaExpr.cpp:16694
+ // initializer and check whether the context in question is reachable.
+ if (auto *VD = dyn_cast_or_null<VarDecl>(CurContext->getLastDecl())) {
+ if (VD->getDefinition()) {
----------------
It's not correct to assume that the last declaration in the context is the right one to be considering here. Instead, you should track whether you're in a variable initializer (and for what) in `Sema`. Examples:
```
int x = ([]{}(), x); // in C++; last decl is the lambda
```
```
int y = (struct Q { int n; }){y}; // in C; last decl is the struct
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63889/new/
https://reviews.llvm.org/D63889
More information about the cfe-commits
mailing list