<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/117960>117960</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Crashes When Compiling Template Enum with Function and Static Assertions
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
iamanonymouscs
</td>
</tr>
</table>
<pre>
This crash can be observed in both LLVM 18 and LLVM trunk versions.[https://godbolt.org/z/v57annjGn](https://godbolt.org/z/v57annjGn)
# Command
`clang++ bug.cpp`
# Code
```cpp
template < typename T > struct A
{
enum E : T;
E h ();
};
A < int > a;
A < int >::E b = a.h () + 1;
int i = b.e ();
static_assert (i == 1, "i");
A::E e = b.e ();
static_assert (e, "");
A::E e = A::h () + 1;
template < typename T > enum A < T >::E : T { e };
template < typename T > typename A < T >::E A < T >::h ()
{
return e;
}
```
# Version
clang-18
```sh
Ubuntu clang version 18.1.8 (++20240731025011+3b5b5c1ec4a3-1~exp1~20240731145104.143)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```
# Error Output
```sh
Stack dump:
0. Program arguments: /usr/lib/llvm-18/bin/clang -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name bug.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/bugs -fcoverage-compilation-dir=/home/bugs -resource-dir /usr/lib/llvm-18/lib/clang/18 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../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 -dwarf-debug-flags "/usr/lib/llvm-18/bin/clang --driver-mode=g++ bug.cpp -dumpdir a-" -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/bug-2ab286.o -x c++ bug.cpp
1. bug.cpp:8:28: current parser token ';'
#0 0x00007fb2523ecb46 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib/x86_64-linux-gnu/libLLVM-18.so.18.1+0xd93b46)
#1 0x00007fb2523eaaf0 llvm::sys::RunSignalHandlers() (/lib/x86_64-linux-gnu/libLLVM-18.so.18.1+0xd91af0)
#2 0x00007fb2523ed210 (/lib/x86_64-linux-gnu/libLLVM-18.so.18.1+0xd94210)
#3 0x00007fb25123c090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)
#4 0x00007fb2598f2639 clang::ASTContext::getIntegerRank(clang::Type const*) const (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xc9b639)
#5 0x00007fb2598f30c5 clang::ASTContext::getIntegerTypeOrder(clang::QualType, clang::QualType) const (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xc9c0c5)
#6 0x00007fb25a2fcdf3 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x16a5df3)
#7 0x00007fb25a2fc132 clang::Sema::UsualArithmeticConversions(clang::ActionResult<clang::Expr*, true>&, clang::ActionResult<clang::Expr*, true>&, clang::SourceLocation, clang::Sema::ArithConvKind) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x16a5132)
#8 0x00007fb25a32095b clang::Sema::CheckAdditionOperands(clang::ActionResult<clang::Expr*, true>&, clang::ActionResult<clang::Expr*, true>&, clang::SourceLocation, clang::BinaryOperatorKind, clang::QualType*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x16c995b)
#9 0x00007fb25a30de92 clang::Sema::CreateBuiltinBinOp(clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr*, clang::Expr*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x16b6e92)
#10 0x00007fb25a5f3d74 clang::Sema::CreateOverloadedBinOp(clang::SourceLocation, clang::BinaryOperatorKind, clang::UnresolvedSetImpl const&, clang::Expr*, clang::Expr*, bool, bool, clang::FunctionDecl*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x199cd74)
#11 0x00007fb25a32cf2c (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x16d5f2c)
#12 0x00007fb25a32cb10 clang::Sema::BuildBinOp(clang::Scope*, clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr*, clang::Expr*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x16d5b10)
#13 0x00007fb25a2fba9f clang::Sema::ActOnBinOp(clang::Scope*, clang::SourceLocation, clang::tok::TokenKind, clang::Expr*, clang::Expr*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x16a4a9f)
#14 0x00007fb2598250a4 clang::Parser::ParseRHSOfBinaryExpression(clang::ActionResult<clang::Expr*, true>, clang::prec::Level) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xbce0a4)
#15 0x00007fb259823e8f clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xbcce8f)
#16 0x00007fb2597f44fe clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xb9d4fe)
#17 0x00007fb2597f1884 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xb9a884)
#18 0x00007fb2598a6e7a clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xc4fe7a)
#19 0x00007fb2598a6843 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xc4f843)
#20 0x00007fb2598a5aa6 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xc4eaa6)
#21 0x00007fb2598a3eda clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xc4ceda)
#22 0x00007fb2597dcc7e clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xb85c7e)
#23 0x00007fb25b614415 clang::FrontendAction::Execute() (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x29bd415)
#24 0x00007fb25b58e674 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x2937674)
#25 0x00007fb25b68e69e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x2a3769e)
#26 0x000055ecd5475c62 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-18/bin/clang+0x12c62)
#27 0x000055ecd5473095 (/usr/lib/llvm-18/bin/clang+0x10095)
#28 0x000055ecd5472256 clang_main(int, char**, llvm::ToolContext const&) (/usr/lib/llvm-18/bin/clang+0xf256)
#29 0x000055ecd547faf6 main (/usr/lib/llvm-18/bin/clang+0x1caf6)
#30 0x00007fb25121d083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#31 0x000055ecd546fb0e _start (/usr/lib/llvm-18/bin/clang+0xcb0e)
```
clang-truck
```sh
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 <source>
1. <source>:8:28: current parser token ';'
#0 0x00000000039bee18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x39bee18)
#1 0x00000000039bcf64 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x39bcf64)
#2 0x000000000390d898 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x0000791d8a842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x0000000007025f38 clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x7025f38)
#5 0x00007ffcdfa753a0
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWl9zo7iy_zTkRSUXiP8PeSB2vJu6u5W5k-yex5SQGqwNSFwhPM59OJ_9lsA24DiZZNZ3tk5q1wOiaf36p-5WC4m2rSglwLUT3jjh6op2ZqP0taA1lU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