llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Crash in CodeGenModule::HandleCXXStaticMemberVarInstantiation for a static data member with a dependent nested-alias type missing typename

Open ICSE-27 opened this issue 2 months ago • 1 comments

Description

Clang crashes (release build without assertions) when instantiating the out-of-line definition of a static data member of a class template, when the member's type is a dependent nested alias written without typename:

template <class T>
struct Tester {
   struct Inner { using T2 = int; };
   static void test();
};
template <class T>
struct W { static Tester<T>::Inner::T2 m; };
template <class T>
Tester<T>::Inner::T2 W<T>::m = 0;
template struct W<int>;
clang++ -std=c++17 -c repro.cpp

Expected / Observed

Expected: a diagnostic error (missing typename — this is what GCC produces). Observed: crash with stack dump at CodeGenModule::HandleCXXStaticMemberVarInstantiation (clang/lib/CodeGen/CodeGenModule.cpp:5956), reached via ~PassToConsumerRAII / Sema::InstantiateVariableDefinition. Reproduces at every optimization level and language mode; also on Clang 19.1.7.

At minimum Clang should diagnose the program instead of crashing; the crash site is distinct from the return-type-driven getTypeInfoImpl failure shape of similar missing-typename reproducers.

ICSE-27 avatar Sep 28 '26 04:09 ICSE-27

@llvm/issue-subscribers-clang-codegen

Author: ICSE-27

## Description

Clang crashes (release build without assertions) when instantiating the out-of-line definition of a static data member of a class template, when the member's type is a dependent nested alias written without typename:

template &lt;class T&gt;
struct Tester {
   struct Inner { using T2 = int; };
   static void test();
};
template &lt;class T&gt;
struct W { static Tester&lt;T&gt;::Inner::T2 m; };
template &lt;class T&gt;
Tester&lt;T&gt;::Inner::T2 W&lt;T&gt;::m = 0;
template struct W&lt;int&gt;;
clang++ -std=c++17 -c repro.cpp

Expected / Observed

Expected: a diagnostic error (missing typename — this is what GCC produces). Observed: crash with stack dump at CodeGenModule::HandleCXXStaticMemberVarInstantiation (clang/lib/CodeGen/CodeGenModule.cpp:5956), reached via ~PassToConsumerRAII / Sema::InstantiateVariableDefinition. Reproduces at every optimization level and language mode; also on Clang 19.1.7.

At minimum Clang should diagnose the program instead of crashing; the crash site is distinct from the return-type-driven getTypeInfoImpl failure shape of similar missing-typename reproducers.