Closed Quuxplusone closed 2 weeks ago
https://godbolt.org/z/bns6MrY9E
using T = int[1]; T a(42);
Compile with -std=c++20. Clang assert-fails with the message "Expression result is not a constant array type":
-std=c++20
clang++: /root/llvm-project/clang/lib/AST/ExprConstant.cpp:11423: bool {anonymous}::ArrayExprEvaluator::VisitCXXParenListInitExpr(const clang::CXXParenListInitExpr*): Assertion `dyn_cast<ConstantArrayType>(E->getType()) && "Expression result is not a constant array 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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 <source> 1. <source>:2:8: current parser token ';' [...] #8 0x000070eef7839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #9 0x00000000075eeb0d clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::ArrayExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0 #10 0x00000000075eecad EvaluateArray(clang::Expr const*, (anonymous namespace)::LValue const&, clang::APValue&, (anonymous namespace)::EvalInfo&) ExprConstant.cpp:0:0 #11 0x00000000075ba5e1 EvaluateInPlace(clang::APValue&, (anonymous namespace)::EvalInfo&, (anonymous namespace)::LValue const&, clang::Expr const*, bool) ExprConstant.cpp:0:0 #12 0x00000000075f7393 clang::Expr::EvaluateAsInitializer(clang::APValue&, clang::ASTContext const&, clang::VarDecl const*, llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x75f7393) #13 0x00000000074d1382 clang::VarDecl::evaluateValueImpl(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x74d1382) #14 0x00000000074d16d1 clang::VarDecl::checkForConstantInitialization(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x74d16d1) #15 0x000000000663d505 clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x663d505) #16 0x0000000006643dca clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6643dca) [...]
The same crash happens with these variations, all of which are accepted without complaint by GCC:
using Ta = int[2]; Ta a(42); using Tb = int[2]; Tb b(42,43); using Tc = int[]; Tc c(42); using Td = int[]; Td d(42,43);
Fixed in llvm#92299!
https://godbolt.org/z/bns6MrY9E
Compile with
-std=c++20
. Clang assert-fails with the message "Expression result is not a constant array type":The same crash happens with these variations, all of which are accepted without complaint by GCC: