<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/101304>101304</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang][C23] Assertion failure with invalid `constexpr` declaration with incomplete struct
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
MitalAshok
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/q4P5javej
```c++
constexpr struct X x = { 0 };
```
```
test.c:1:20: error: constexpr variable cannot have non-literal type 'const struct X'
1 | constexpr struct X x = { 0 };
| ^
clang: /llvm/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From *) [To = clang::CXXRecordDecl, From = clang::RecordDecl]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
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: /cmake-build-debug/bin/clang -cc1 -std=c23 test.c
1. test.c:1:22: current parser token '='
#0 0x00005625b90db92d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:11
#1 0x00005625b90dbe1b PrintStackTraceSignalHandler(void*) /llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
#2 0x00005625b90d9e86 llvm::sys::RunSignalHandlers() /llvm/llvm-project/llvm/lib/Support/Signals.cpp:105:5
#3 0x00005625b90dc5d5 SignalHandler(int) /llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
#4 0x00007f52fc6a1520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x00007f52fc6f59fc __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76
#6 0x00007f52fc6f59fc __pthread_kill_internal ./nptl/./nptl/pthread_kill.c:78:10
#7 0x00007f52fc6f59fc pthread_kill ./nptl/./nptl/pthread_kill.c:89:10
#8 0x00007f52fc6a1476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#9 0x00007f52fc6877f3 abort ./stdlib/./stdlib/abort.c:81:7
#10 0x00007f52fc68771b _nl_load_domain ./intl/./intl/loadmsgcat.c:1177:9
#11 0x00007f52fc698e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#12 0x00005625b94a5078 decltype(auto) llvm::cast<clang::CXXRecordDecl, clang::RecordDecl>(clang::RecordDecl*) /llvm/llvm-project/llvm/include/llvm/Support/Casting.h:579:10
#13 0x00005625bf61a6d7 clang::Sema::RequireLiteralType(clang::SourceLocation, clang::QualType, clang::Sema::TypeDiagnoser&) /llvm/llvm-project/clang/lib/Sema/SemaType.cpp:9270:29
#14 0x00005625bf61b0ac clang::Sema::RequireLiteralType(clang::SourceLocation, clang::QualType, unsigned int) /llvm/llvm-project/clang/lib/Sema/SemaType.cpp:9345:10
#15 0x00005625be1b99a7 clang::Sema::CheckVariableDeclarationType(clang::VarDecl*) /llvm/llvm-project/clang/lib/Sema/SemaDecl.cpp:8759:7
#16 0x00005625be1b6d15 clang::Sema::CheckVariableDeclaration(clang::VarDecl*, clang::LookupResult&) /llvm/llvm-project/clang/lib/Sema/SemaDecl.cpp:8809:7
#17 0x00005625be1b3fc4 clang::Sema::ActOnVariableDeclarator(clang::Scope*, clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*, clang::LookupResult&, llvm::MutableArrayRef<clang::TemplateParameterList*>, bool&, llvm::ArrayRef<clang::BindingDecl*>) /llvm/llvm-project/clang/lib/Sema/SemaDecl.cpp:7964:24
#18 0x00005625be1a9a92 clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) /llvm/llvm-project/clang/lib/Sema/SemaDecl.cpp:6405:9
#19 0x00005625be1a8cd0 clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) /llvm/llvm-project/clang/lib/Sema/SemaDecl.cpp:6046:15
#20 0x00005625bdca55cc clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) /llvm/llvm-project/clang/lib/Parse/ParseDecl.cpp:2754:14
#21 0x00005625bdca42fb clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) /llvm/llvm-project/clang/lib/Parse/ParseDecl.cpp:2559:9
#22 0x00005625bdbf612c clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /llvm/llvm-project/clang/lib/Parse/Parser.cpp:1249:10
#23 0x00005625bdbf560e clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /llvm/llvm-project/clang/lib/Parse/Parser.cpp:1271:12
#24 0x00005625bdbf4e99 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /llvm/llvm-project/clang/lib/Parse/Parser.cpp:1074:14
#25 0x00005625bdbf2cbc clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /llvm/llvm-project/clang/lib/Parse/Parser.cpp:763:12
#26 0x00005625bdbf2360 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /llvm/llvm-project/clang/lib/Parse/Parser.cpp:608:8
#27 0x00005625bdbed771 clang::ParseAST(clang::Sema&, bool, bool) /llvm/llvm-project/clang/lib/Parse/ParseAST.cpp:170:15
#28 0x00005625ba6403f1 clang::ASTFrontendAction::ExecuteAction() /llvm/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1194:1
#29 0x00005625ba63fe0c clang::FrontendAction::Execute() /llvm/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1082:7
#30 0x00005625ba55a556 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /llvm/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1061:23
#31 0x00005625ba81df3e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /llvm/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:280:8
#32 0x00005625b71dcb29 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /llvm/llvm-project/clang/tools/driver/cc1_main.cpp:285:13
#33 0x00005625b71cf472 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /llvm/llvm-project/clang/tools/driver/driver.cpp:215:5
#34 0x00005625b71ce1db clang_main(int, char**, llvm::ToolContext const&) /llvm/llvm-project/clang/tools/driver/driver.cpp:256:5
#35 0x00005625b72038d5 main /cmake-build-debug/tools/clang/tools/driver/clang-driver.cpp:17:3
#36 0x00007f52fc688d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#37 0x00007f52fc688e40 call_init ./csu/../csu/libc-start.c:128:20
#38 0x00007f52fc688e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#39 0x00005625b71cdc65 _start (/cmake-build-debug/clang+0x5bd2c65)
```
It also complains about a "non-literal type", which shouldn't be checked outside of C++
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWt9v4yoW_mvoC2qE8e-HPrhJs1tprm532h3dtwgDSbgl4Au4t92_fgV2EttNO-l0ZqUdVRPHmMP3fedwOOAQa8VGcX4F0muQLi5I67baXP0mHJGV3erHi1qzl6utc40FcQXwEuDlRrNaSzfTZgPw8j8AL_9K7tI_yRP_E6AFQFX_f4a6Pwrwtf8Ld6lW1vHnxkDrTEsd_AM-QxAvIMivIYIgX4D4emLgpNXuq-PWzSiIqwjEFUYgriA3Rht_cRzqiRh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