llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.02k stars 11.57k forks source link

Variadic template argument deduction - strange error and segfault in recent clang #34033

Open llvmbot opened 7 years ago

llvmbot commented 7 years ago
Bugzilla Link 34685
Version trunk
OS Linux
Attachments preprocessed source, run script
Reporter LLVM Bugzilla Contributor
CC @DougGregor

Extended Description

The following code-snipped produces an error message and a subsequent segfault with both clang 5.0.0 and the current master(7a69440) branch. It compiles fine with any c++11 compliant g++.

#include <initializer_list>

template <typename... T> struct B {};
template <typename T> struct gf {};
template <typename... A> B<A...> make_B(std::initializer_list<gf<A...>> const &V) { return {}; }

int main() {
  auto x = gf<int>{};
  auto b = make_B<int>({x, x, x}); // clang segfault
  //auto b = make_B({x, x, x}); // ok
}

The error message reads

test.cpp:5:26: error: too many template arguments for class template 'gf'
template <typename... A> B<A...> make_B(std::initializer_list<gf<A...>> const &V) { return {}; }
                         ^
test.cpp:9:12: note: in instantiation of function template specialization 'make_B<int>' 
requested here
  auto b = make_B<int>({x, x, x}); // clang crash
           ^
test.cpp:4:30: note: template is declared here
template <typename T> struct gf {};

Why does clang report an error here? The number of template arguments deduced for gf in the call to make_B should be one.

The crash backtrace reads

#&#8203;0 0x0000564f5228774a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x1db874a)                   
#&#8203;1 0x0000564f52285606 llvm::sys::RunSignalHandlers() (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x1db6606)                                   
#&#8203;2 0x0000564f5228574c SignalHandler(int) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x1db674c)                                               
#&#8203;3 0x00007f16fe149da0 __restore_rt (/usr/lib/libpthread.so.0+0x11da0)                                                                        
#&#8203;4 0x0000564f536c376c CheckOriginalCallArgDeduction(clang::Sema&, clang::Sema::OriginalCallArg, clang::QualType) [clone .isra.1573] (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x31f476c)
#&#8203;5 0x0000564f536f1e74 clang::Sema::FinishTemplateArgumentDeduction(clang::FunctionTemplateDecl*, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::Sema::OriginalCallArg> co$
st*, bool, llvm::function_ref<bool ()>) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x3222e74)                                                
#&#8203;6 0x0000564f536f68b7 clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>)>) (/$
ome/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x32278b7)                                                                                                                                                                                                                                        #&#8203;7 0x0000564f53611107 clang::Sema::AddTemplateOverloadCandidate(clang::FunctionTemplateDecl*, clang::DeclAccessPair, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool, bool) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x3142107)      #&#8203;8 0x0000564f5361337a clang::Sema::AddOverloadedCallCandidates(clang::UnresolvedLookupExpr*, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x314437a)                                                                      #&#8203;9 0x0000564f53613623 clang::Sema::buildOverloadedCallSet(clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::OverloadCandidateSet*, clang::ActionResult<clang::Expr*, true>*) (/home/nwentzel/opt/llvm-5.0/bin$clang-5.0+0x3144623)                                                                                                                                                                                                                                                                      #&#8203;10 0x0000564f5361748a clang::Sema::BuildOverloadedCallExpr(clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x314848a) #&#8203;11 0x0000564f5349865b clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2fc965b)
#&#8203;12 0x0000564f5309e87e clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2bcf87e)
#&#8203;13 0x0000564f53099acb clang::Parser::ParseCastExpression(bool, bool, bool&, clang::Parser::TypeCastState, bool) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2bcaacb)
#&#8203;14 0x0000564f5309beb4 clang::Parser::ParseCastExpression(bool, bool, clang::Parser::TypeCastState, bool) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2bcceb4)
#&#8203;15 0x0000564f53099aa9 clang::Parser::ParseCastExpression(bool, bool, bool&, clang::Parser::TypeCastState, bool) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2bcaaa9)
#&#8203;16 0x0000564f5309beb4 clang::Parser::ParseCastExpression(bool, bool, clang::Parser::TypeCastState, bool) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2bcceb4)
#&#8203;17 0x0000564f5309d53c clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2bce53c)                                                                                                                                       
#&#8203;18 0x0000564f53069eeb clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2b9aeeb)
#&#8203;19 0x0000564f5307a650 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, unsigned int, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2bab650)
#&#8203;20 0x0000564f5307d444 clang::Parser::ParseSimpleDeclaration(unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, bool, clang::Parser::ForRangeInit*) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2bae444)
#&#8203;21 0x0000564f5307d6cb clang::Parser::ParseDeclaration(unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2bae6cb)                                                                                             
#&#8203;22 0x0000564f530e2ab9 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::AllowedConstructsKind, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2c13ab9)
#&#8203;23 0x0000564f530e3160 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::AllowedConstructsKind, clang::SourceLocation*) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2c14160)
#&#8203;24 0x0000564f530e6f8c clang::Parser::ParseCompoundStatementBody(bool) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2c17f8c)
#&#8203;25 0x0000564f530e980b clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2c1a80b)
#&#8203;26 0x0000564f53059ed5 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2b8aed5)
#&#8203;27 0x0000564f5307a503 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, unsigned int, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2bab503)
#&#8203;28 0x0000564f53054641 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2b85641)
#&#8203;29 0x0000564f53054c91 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) [clone .part.150] (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2b85c91)
#&#8203;30 0x0000564f5305b7a5 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2b8c7a5)
#&#8203;31 0x0000564f5305c8a6 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2b8d8a6)
#&#8203;32 0x0000564f53050da2 clang::ParseAST(clang::Sema&, bool, bool) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2b81da2)
#&#8203;33 0x0000564f52b6af37 clang::CodeGenAction::ExecuteAction() (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x269bf37)
#&#8203;34 0x0000564f528259a6 clang::FrontendAction::Execute() (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x23569a6)
#&#8203;35 0x0000564f527eff8c clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x2320f8c)
#&#8203;36 0x0000564f528d39e3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x24049e3)
#&#8203;37 0x0000564f50d6f048 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x8a0048)
#&#8203;38 0x0000564f50cf7e48 main (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x828e48)
#&#8203;39 0x00007f16fcc28f6a __libc_start_main (/usr/lib/libc.so.6+0x20f6a)
#&#8203;40 0x0000564f50d6c8ca _start (/home/nwentzel/opt/llvm-5.0/bin/clang-5.0+0x89d8ca)
Stack dump:
0.      Program arguments: /home/nwentzel/opt/llvm-5.0/bin/clang-5.0 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name clang_bug.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim
-fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -resource-dir /home/nwentzel/opt/llvm-5.0/lib/clang/5.0.0 -I/usr/include/c++/7.1.1/x86_64-pc-linux-gnu -I/usr/include/c++/7.1.1 -I/usr/inclu$
e/python2.7 -I/home/nwentzel/opt/cubature-1.0.2 -I/usr/include/eigen3 -I/home/nwentzel/opt/clion-2017.2/include -I/home/nwentzel/opt/pomerol/include -I/home/nwentzel/opt/triqs/include -I/home/nwentzel/opt/gperftools/include -I/home/nwentzel/opt/llvm-5.0/include -I/usr/include/c++/$
.1.1/x86_64-pc-linux-gnu -I/usr/include/c++/7.1.1 -I/usr/include/python2.7 -I/home/nwentzel/opt/cubature-1.0.2 -I/usr/include/eigen3 -I. -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/7.2.0/../../../../include/c++/7.2.0 -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/7.$
.0/../../../../include/c++/7.2.0/x86_64-pc-linux-gnu -internal-isystem /usr/lib64/gcc/x86_64-pc-linux-gnu/7.2.0/../../../../include/c++/7.2.0/backward -internal-isystem /usr/local/include -internal-isystem /home/nwentzel/opt/llvm-5.0/lib/clang/5.0.0/include -internal-externc-isyst$
m /include -internal-externc-isystem /usr/include -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /home/nwentzel/Dropbox/Coding/TESTS -ferror-limit 19 -fmessage-length 282 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/$
lang_bug-65b1de.o -x c++ clang_bug.cpp
1.      clang_bug.cpp:11:32: current parser token ')'
2.      clang_bug.cpp:9:12: parsing function body 'main'
3.      clang_bug.cpp:9:12: in compound statement ('{}')
clang-5.0: error: unable to execute command: Segmentation fault (core dumped)
clang-5.0: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 5.0.0 (https://github.com/llvm-mirror/clang 7e8743f82ac7957c66d9c2444996be5b1218673b) (https://github.com/llvm-mirror/llvm 657c31173ea30090583e40c7a9204561d9c2d8c4)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/nwentzel/opt/llvm-5.0/bin
clang-5.0: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script.
clang-5.0: note: diagnostic msg:
Endilll commented 1 year ago

Still crashing as of post-17 trunk: https://godbolt.org/z/bWzjnz6ba

<source>:5:26: error: too many template arguments for class template 'gf'
    5 | template <typename... A> B<A...> make_B(std::initializer_list<gf<A...>> const &V) { return {}; }
      |                          ^
<source>:9:12: note: in instantiation of function template specialization 'make_B<int>' requested here
    9 |   auto b = make_B<int>({x, x, x}); // clang segfault
      |            ^
<source>:4:30: note: template is declared here
    4 | template <typename T> struct gf {};
      | ~~~~~~~~~~~~~~~~~~~~~        ^

clang++: /root/llvm-project/clang/include/clang/AST/Type.h:752:
const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const:
Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' 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++11 <source>
1.  <source>:9:33: current parser token ')'
2.  <source>:7:12: parsing function body 'main'
3.  <source>:7:12: in compound statement ('{}')
 #0 0x0000000003684c58 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3684c58)
 #1 0x0000000003682adc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3682adc)
 #2 0x00000000035ce518 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f294d95c420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f294d41f00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f294d3fe859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f294d3fe729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f294d40ffd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x000000000681ccf0 CheckOriginalCallArgDeduction(clang::Sema&, clang::sema::TemplateDeductionInfo&, clang::Sema::OriginalCallArg, clang::QualType) SemaTemplateDeduction.cpp:0:0
 #9 0x000000000686ce02 clang::Sema::FinishTemplateArgumentDeduction(clang::FunctionTemplateDecl*, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::Sema::OriginalCallArg> const*, bool, llvm::function_ref<bool ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x686ce02)
#10 0x000000000686ee2a void llvm::function_ref<void ()>::callback_fn<clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, bool, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>)>)::'lambda1'()>(long) SemaTemplateDeduction.cpp:0:0
#11 0x0000000005eeff01 clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5eeff01)
#12 0x0000000006878862 clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, bool, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6878862)
#13 0x00000000066903d2 clang::Sema::AddTemplateOverloadCandidate(clang::FunctionTemplateDecl*, clang::DeclAccessPair, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool, bool, bool, clang::CallExpr::ADLCallKind, clang::OverloadCandidateParamOrder, bool) (.constprop.1) SemaOverload.cpp:0:0
#14 0x00000000066921b6 clang::Sema::AddOverloadedCallCandidates(clang::UnresolvedLookupExpr*, llvm::ArrayRef<clang::Expr*>, clang::OverloadCandidateSet&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66921b6)
#15 0x000000000669257e clang::Sema::buildOverloadedCallSet(clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::OverloadCandidateSet*, clang::ActionResult<clang::Expr*, true>*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x669257e)
#16 0x000000000669d624 clang::Sema::BuildOverloadedCallExpr(clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x669d624)
#17 0x00000000063478a1 clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x63478a1)
#18 0x000000000634985c clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x634985c)
#19 0x0000000005e0b1a0 clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e0b1a0)
#20 0x0000000005e03401 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e03401)
#21 0x0000000005e048c5 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e048c5)
#22 0x0000000005e06587 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e06587)
#23 0x0000000005e06619 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e06619)
#24 0x0000000005dc779d clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5dc779d)
#25 0x0000000005dd4730 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5dd4730)
#26 0x0000000005ddca55 clang::Parser::ParseSimpleDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, bool, clang::Parser::ForRangeInit*, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ddca55)
#27 0x0000000005ddcef7 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5ddcef7)
#28 0x0000000005e7d290 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e7d290)
#29 0x0000000005e7df87 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e7df87)
#30 0x0000000005e7eee9 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e7eee9)
#31 0x0000000005e807da clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5e807da)
#32 0x0000000005dae891 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5dae891)
#33 0x0000000005dd4e38 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5dd4e38)
#34 0x0000000005da27db clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5da27db)
#35 0x0000000005da2f0f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#36 0x0000000005da9501 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5da9501)
#37 0x0000000005da9dfd clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5da9dfd)
#38 0x0000000005d9e18a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5d9e18a)
#39 0x00000000048dee68 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48dee68)
#40 0x0000000004145769 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4145769)
#41 0x00000000040c972e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40c972e)
#42 0x0000000004225e06 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4225e06)
#43 0x0000000000bce617 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbce617)
#44 0x0000000000bc6cca ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#45 0x0000000003f28ab9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#46 0x00000000035ce9c4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x35ce9c4)
#47 0x0000000003f290af clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#48 0x0000000003ef1975 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ef1975)
#49 0x0000000003ef23dd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ef23dd)
#50 0x0000000003efa335 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3efa335)
#51 0x0000000000bcc8ac clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbcc8ac)
#52 0x0000000000ac5a71 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xac5a71)
#53 0x00007f294d400083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#54 0x0000000000bc67ae _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbc67ae)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-frontend

Endilll commented 1 year ago

Notably GCC 13 accepts the example without issuing any diagnostics: https://godbolt.org/z/43GG55YhG

zygoloid commented 1 year ago

The

<source>:5:26: error: too many template arguments for class template 'gf'

diagnostic is implementing [temp.res.general]/6.4:

The program is ill-formed, no diagnostic required, if [...] every valid specialization of a variadic template requires an empty template parameter pack

... but that rule doesn't apply here, because explicit template argument substitution is not forming a new variadic template (and in any case, the substitution we're doing, replacing the pack T with <int, T...>, is an implementation detail rather than something the standard mandates). So we should suppress this check in this case.

The crash looks likely to be a bad error recovery after the original error, so we should fix that too, as the error case would presumably still be reachable even once we stop diagnosing this particular construct.