<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/116807>116807</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang++: Instantiation of forward declared inner class causes crash
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          jreinking-git
      </td>
    </tr>
</table>

<pre>
    ## Problem

The following code causes the crash:

```cpp
#include <iostream>

template <typename T>
class MyClass
{
public:
 struct Inner;
    static constexpr Inner inner = Inner{};

 struct Inner {};
};

template <typename T>
constexpr typename MyClass<T>::Inner MyClass<T>::inner;

int main(int argc, char const *argv[])
{
    MyClass<int> obj;
    std::cout << &MyClass<int>::inner << std::endl;
    return 0;
}
```

```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-18.1.0/bin/clang-18 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -dumpdir /app/output.s- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name example.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -fno-verbose-asm -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -fdebug-compilation-dir=/app -fcoverage-compilation-dir=/app -resource-dir /opt/compiler-explorer/clang-18.1.0/lib/clang/18 -internal-isystem /opt/compiler-explorer/gcc-13.2.0/lib/gcc/x86_64-linux-gnu/13.2.0/../../../../include/c++/13.2.0 -internal-isystem /opt/compiler-explorer/gcc-13.2.0/lib/gcc/x86_64-linux-gnu/13.2.0/../../../../include/c++/13.2.0/x86_64-linux-gnu -internal-isystem /opt/compiler-explorer/gcc-13.2.0/lib/gcc/x86_64-linux-gnu/13.2.0/../../../../include/c++/13.2.0/backward -internal-isystem /opt/compiler-explorer/clang-18.1.0/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-13.2.0/lib/gcc/x86_64-linux-gnu/13.2.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/example-72530a.o -x c++ <source>
1.      <source>:8:43: current parser token ';'
2.      <source>:4:1: parsing struct/union/class body 'MyClass'
 #0 0x000000000351ae38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x351ae38)
 #1 0x00000000035187ac SignalHandler(int) Signals.cpp:0:0
 #2 0x0000749bfb642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x0000000006f7b394 clang::QualType::isNonConstantStorage(clang::ASTContext const&, bool, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x6f7b394)
 #4 0x0000000005f18a9f clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x5f18a9f)
 #5 0x0000000005f1d76f clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x5f1d76f)
 #6 0x0000000005c037e3 clang::Parser::ParseCXXClassMemberDeclaration(clang::AccessSpecifier, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject*) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x5c037e3)
 #7 0x0000000005c049cc clang::Parser::ParseCXXClassMemberDeclarationWithPragmas(clang::AccessSpecifier&, clang::ParsedAttributes&, clang::TypeSpecifierType, clang::Decl*) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x5c049cc)
 #8 0x0000000005c0512e clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x5c0512e)
 #9 0x0000000005c07461 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x5c07461)
#10 0x0000000005bd6a04 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x5bd6a04)
#11 0x0000000005cafb0a clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x5cafb0a)
#12 0x0000000005cb841a clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x5cb841a)
#13 0x0000000005cb86c3 clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x5cb86c3)
#14 0x0000000005be4be0 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x5be4be0)
#15 0x0000000005ba53d7 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x5ba53d7)
#16 0x0000000005ba6f27 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x5ba6f27)
#17 0x0000000005b963ba clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x5b963ba)
#18 0x0000000003d5a725 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x3d5a725)
#19 0x0000000003fe2aa1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x3fe2aa1)
#20 0x0000000003f6010b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x3f6010b)
#21 0x00000000040c2473 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0x40c2473)
#22 0x0000000000c19746 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0xc19746)
#23 0x0000000000c1211d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#24 0x0000000000c1687e clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0xc1687e)
#25 0x0000000000b0fa84 main (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0xb0fa84)
#26 0x0000749bfb629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#27 0x0000749bfb629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#28 0x0000000000c1191e _start (/opt/compiler-explorer/clang-18.1.0/bin/clang-18+0xc1191e)
clang++: error: unable to execute command: Segmentation fault (core dumped)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
```

[tmp.zip](https://github.com/user-attachments/files/17816498/tmp.zip)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWktz2zgS_jX0BQUVCVKvgw-KZM-4NtnJjl2ZualAoEkjBgEuADry_PotANSDsiInWc1UUo5EgUDj668bjcaDWitqBXCdjN8l49UV7dyjNtefDQj1JFSNa-GuSs1frhOSJyRHH40uJTRJukrSRfx8eARUaSn1F6FqxDQHxGhnwSL3CIgZah-TfHHYIpmk8Y-1bV9CcqGY7DigJF8KbZ0B2iT5zWEzB00rqQtV3EsLijaAHnaVmKTWog8vS__dt5u-iw9tV0rBdjCQdaZjDt0pBSbJ-0oIIWQddYIhppV1sGlNrIJE-EzyVd9k-i6ZrnYNTwhFx1VeVX9Lmx2C3cutavkyVMsXSb6InZ16Iwa6xU-hHGqoUAmZ-UdqapaQJWKP1ESVUUIW1NTP0R0SMj_i0VO070wol-Q3SJefjzjkEQLTnfPqJfkSJWRy3PAA57bWrikoLgdCDbjOKJQOGB1600kXiz8_vr9Z3N8g25WNcIiisquRgVYbh5xGj8611vdLbhNyWwv32JUjppuE3Er5vP3CrdGfgbmE3AprO7AJuUVUcbT13J27o5KyJ2coA89ua6A1moG1wJHVnYnFviW1VjNBHXBkOoUsM6J1owj53lH2hHjXtDu3TUdJOv9odG1o443XNaCcB44Scqtbj4zpphUSDIZNK7UB48skVTXOZqNslCbktvT23xUizFiGsDOilYA2s8l6UuBOPSn9RWEpVLfBteoQhkY4rMvPCDcGJN1gKiXCHh4XxvdP29aj6FzbuZHFCHNhaSkBVwYAYSaBGkytwyVU2gD2HIHi-3qB42cwohJgQjGjhuNnKjvAfgBYhL3z4krIWIBgQ5tWwoi1bcSlGXVCK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