Index: clang/lib/AST/Decl.cpp =================================================================== --- clang/lib/AST/Decl.cpp +++ clang/lib/AST/Decl.cpp @@ -391,11 +391,18 @@ bool considerVisibility = shouldConsiderTemplateVisibility(fn, specInfo); - // Merge information from the template parameters. FunctionTemplateDecl *temp = specInfo->getTemplate(); - LinkageInfo tempLV = + + // Merge information from the template declaration. + LinkageInfo tempLV = getLVForDecl(temp, computation); + // The linkage of the specialization should be consistent with the + // template declaration. + LV.setLinkage(tempLV.getLinkage()); + + // Merge information from the template parameters. + LinkageInfo paramsLV = getLVForTemplateParameterList(temp->getTemplateParameters(), computation); - LV.mergeMaybeWithVisibility(tempLV, considerVisibility); + LV.mergeMaybeWithVisibility(paramsLV, considerVisibility); // Merge information from the template arguments. const TemplateArgumentList &templateArgs = *specInfo->TemplateArguments; Index: clang/test/Modules/inconsist-export-template.cpp =================================================================== --- /dev/null +++ clang/test/Modules/inconsist-export-template.cpp @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -std=c++20 %s -fsyntax-only -verify +// expected-no-diagnostics +export module m; +export template +void f() { + +} + +template <> +void f() { + +} + +template +void f1() { + +} + +// FIXME: We should reject following specialization, +// since it tries to export a name which is already introduced. +export template <> +void f1() { + +} + +export template +class C { + +}; + +template<> +class C { + +};