[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 01:50:02 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:
I feel I need to clarify that this crash occurred because during the template declaration phase, A::B was not marked as an invalid declaration (nor should it be, since non-instantiated templates shouldn't undergo semantic analysis). During the instantiation phase, because B's context is related to A. B, viewed in isolation, is also a valid declaration (you can't say that int A::B, viewed alone, is an invalid declaration). Therefore, the scheme of marking it as invalid is inherently flawed.
https://github.com/llvm/llvm-project/pull/196772
More information about the cfe-commits
mailing list