[clang] [Clang] Fixed a crash when instantiating an invalid out-of-line static data member definition in a local class (PR #196772)
via cfe-commits
cfe-commits at lists.llvm.org
Sun May 10 02:05:34 PDT 2026
================
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template <class T> int f(T) {
+ struct A {
+ static int B; // expected-error {{static data member 'B' not allowed in local struct 'A'}}
+ };
+ int A::B; // expected-note {{previous definition is here}}
+ int A::B = 1; // expected-error {{redefinition of 'B'}}
+ return 0;
+}
+
+int x = f(0);
----------------
TPPPP72 wrote:
In fact, this is not just a feeling, but a proven fact.
In `VisitVarDecl`, I added these:
```cpp
if (D->getIdentifier()) {
llvm::errs() << "Checking VarDecl: " << D->getNameAsString() << "\n";
llvm::errs() << " D->isInvalidDecl(): " << D->isInvalidDecl() << "\n";
llvm::errs() << " Var->isInvalidDecl(): " << Var->isInvalidDecl() << "\n";
llvm::errs() << " Var Context Kind: " << Var->getDeclContext()->getDeclKindName() << "\n";
if (auto *FD = dyn_cast<FunctionDecl>(Var->getDeclContext())) {
llvm::errs() << " Var Context Name: " << FD->getNameAsString() << "\n";
}
}
```
```
Checking VarDecl: B
D->isInvalidDecl(): 0
Var->isInvalidDecl(): 0
Var Context Kind: Function
Var Context Name: f
```
I'm not saying the entire node is valid, but rather that it's valid specifically for B. Whether B's state is valid can only be determined by parsing the instantiation of A.
https://github.com/llvm/llvm-project/pull/196772
More information about the cfe-commits
mailing list