[clang] [Clang] Fixed a crash when instantiating an invalid out-of-line static data member definition in a local class (PR #196772)
Younan Zhang via cfe-commits
cfe-commits at lists.llvm.org
Sun May 10 02:12:58 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);
----------------
zyn0217 wrote:
Did you read my example? I meant, the status quo of whatever D in the instantiator became could be incorrect, and what we need to do is to avoid meaningless instantiation early.
In this case when `A::B` is declared, a name lookup should have happened and that name lookup should find the invalid Decl. And We need to check if we missed a check somewhere that the decl is overlooked and get slipped into the instantiator, and if that's the case, we prevent it.
https://github.com/llvm/llvm-project/pull/196772
More information about the cfe-commits
mailing list