Assertion triggers on valid code. ### SOURCE:> cat inlNsTmplSpec.cc inline namespace { template <typename T> int foo(T); } template <> int foo(int); Return: 0x00:0 ### COMPILER INVOCATION AND OUTPUT:> clang++ -std=c++11 inlNsTmplSpec.cc -c clang: /build/llvm-dev.src/tools/clang/lib/AST/Decl.cpp:1253: static clang::LinkageInfo clang::LinkageComputer::getLVForDecl(const clang::NamedDecl*, LVComputationKind): Assertion `!Old || Old->getCachedLinkage() == D->getCachedLinkage()' failed. 0 clang 0x0000000011ff51e4 llvm::sys::PrintStackTrace(_IO_FILE*) + 4279327012 1 clang 0x0000000011ff5450 2 clang 0x0000000011ff4c50 3 linux-vdso64.so.1 0x00000fff8edd0418 __kernel_sigtramp_rt64 + 0 4 libc.so.6 0x00000fff8e8ef7d0 gsignal + 4293466120 5 libc.so.6 0x00000fff8e8f18a4 abort + 4293473372 6 libc.so.6 0x00000fff8e8e63bc 7 libc.so.6 0x00000fff8e8e64ac __assert_fail + 4293432916 8 clang 0x000000001110e554 9 clang 0x000000001110edec clang::NamedDecl::getLinkageInternal() const + 4264372852 10 clang 0x000000001110f03c clang::FunctionDecl::getLanguageLinkage() const + 4264373348 11 clang 0x000000001110f1d4 clang::FunctionDecl::isExternC() const + 4264373732 12 clang 0x00000000107f2cc8 clang::Sema::CheckFunctionDeclaration(clang::Scope*, clang::FunctionDecl*, clang::LookupResult&, bool) + 4255407152 13 clang 0x00000000107f8f84 clang::Sema::ActOnFunctionDeclarator(clang::Scope*, clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*, clang::LookupResult&, llvm::MutableArrayRef<clang::TemplateParameterList*>, bool&) + 4255432332 14 clang 0x00000000107fa11c clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) + 4255436812 15 clang 0x00000000109fe120 clang::Sema::ActOnTemplateDeclarator(clang::Scope*, llvm::MutableArrayRef<clang::TemplateParameterList*>, clang::Declarator&) + 4257446408 16 clang 0x00000000106aa788 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) + 4254117496 17 clang 0x00000000106b0c18 clang::Parser::ParseDeclarationAfterDeclarator(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&) + 4254142784 18 clang 0x0000000010706b50 clang::Parser::ParseSingleDeclarationAfterTemplate(unsigned int, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::AccessSpecifier, clang::AttributeList*) + 4254483200 19 clang 0x00000000107075f8 clang::Parser::ParseTemplateDeclarationOrSpecialization(unsigned int, clang::SourceLocation&, clang::AccessSpecifier, clang::AttributeList*) + 4254485904 20 clang 0x00000000107078bc clang::Parser::ParseDeclarationStartingWithTemplate(unsigned int, clang::SourceLocation&, clang::AccessSpecifier, clang::AttributeList*) + 4254486564 21 clang 0x00000000106b8e24 clang::Parser::ParseDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) + 4254175644 22 clang 0x00000000106a1570 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) + 4254082472 23 clang 0x00000000106a1d0c clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 4254084396 24 clang 0x000000001069927c clang::ParseAST(clang::Sema&, bool, bool) + 4254051060 25 clang 0x00000000102cde5c clang::ASTFrontendAction::ExecuteAction() + 4250281660 26 clang 0x00000000104ae5fc clang::CodeGenAction::ExecuteAction() + 4252147284 27 clang 0x00000000102cf1b0 clang::FrontendAction::Execute() + 4250285960 28 clang 0x00000000102a9f60 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 4250138448 29 clang 0x000000001028cd68 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 4250028376 30 clang 0x0000000010286288 cc1_main(char const**, char const**, char const*, void*) + 4250001784 31 clang 0x0000000010272028 main + 4249918536 32 libc.so.6 0x00000fff8e8d49ec 33 libc.so.6 0x00000fff8e8d4bf4 __libc_start_main + 4293363212 Stack dump: 0. Program arguments: /bin/clang -cc1 -triple powerpc64-unknown-linux-gnu -S -disable-free -main-file-name inlNsTmplSpec.cc -mrelocation-model static -mdisable-fp-elim -fmath-errno -no-integrated-as -mconstructor-aliases -target-cpu ppc64 -target-linker-version 11 -coverage-file /tmp/inlNsTmplSpec-4c0298.s -resource-dir /bin/../lib/clang/3.5.0 -internal-isystem /usr/lib/gcc/ppc64-redhat-linux/4.4.6/../../../../include/c++/4.4.6 -internal-isystem /usr/lib/gcc/ppc64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/ppc64-redhat-linux -internal-isystem /usr/lib/gcc/ppc64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/backward -internal-isystem /usr/lib/gcc/ppc64-redhat-linux/4.4.6/../../../../include/ppc64-redhat-linux/c++/4.4.6 -internal-isystem /usr/local/include -internal-isystem /bin/../lib/clang/3.5.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++11 -fdeprecated-macro -fno-dwarf-directory-asm -fdebug-compilation-dir /tmp/hstong -ferror-limit 19 -fmessage-length 0 -mstackrealign -fno-signed-char -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -o /tmp/inlNsTmplSpec-4c0298.s -x c++ inlNsTmplSpec.cc 1. inlNsTmplSpec.cc:2:25: current parser token ';' clang: error: unable to execute command: Aborted (core dumped) clang: error: clang frontend command failed due to signal (use -v to see invocation) clang version 3.5.0 Target: powerpc64-unknown-linux-gnu Thread model: posix clang: 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: note: diagnostic msg: ******************** PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang: note: diagnostic msg: /tmp/inlNsTmplSpec-197dbd.cpp clang: note: diagnostic msg: /tmp/inlNsTmplSpec-197dbd.sh clang: note: diagnostic msg: ******************** Return: 0xfe:254 ### VERSION INFO:> clang++ -v clang version 3.5.0 Target: powerpc64-unknown-linux-gnu Thread model: posix Found candidate GCC installation: /usr/lib/gcc/ppc64-redhat-linux/4.4.4 Found candidate GCC installation: /usr/lib/gcc/ppc64-redhat-linux/4.4.6 Selected GCC installation: /usr/lib/gcc/ppc64-redhat-linux/4.4.6 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Selected multilib: .;@m64 Return: 0x00:0
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang: note: diagnostic msg: /tmp/inlNsTmplSpec-197dbd.cpp clang: note: diagnostic msg: /tmp/inlNsTmplSpec-197dbd.sh clang: note: diagnostic msg:
Created attachment 12635 [details] Preprocessed source
Created attachment 12636 [details] Invocation script
Sorry, I completely missed the test source it the original description. To summarize: clang -cc1 crashes on inline namespace { template <typename T> int foo(T); } template <> int foo(int);
The problem is that we don't reparent the template specialization into the inline namespace. I fixed a related issue for qualified redeclarations in r321770: inline namespace { void f(); } void ::f() {} A similar approach should work here.