Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -3113,6 +3113,7 @@ template static bool isExternC(T *D) { return D->isExternC(); } static bool isExternC(VarTemplateDecl *) { return false; } +static bool isExternC(FunctionTemplateDecl *) { return false; } /// Check whether a redeclaration of an entity introduced by a /// using-declaration is valid, given that we know it's not an overload @@ -3237,10 +3238,20 @@ return true; } - // Check whether the two declarations might declare the same function. - if (checkUsingShadowRedecl(*this, Shadow, New)) - return true; - OldD = Old = cast(Shadow->getTargetDecl()); + // Check whether the two declarations might declare the same function or + // function template. + if (FunctionTemplateDecl *NewTemplate = + New->getDescribedFunctionTemplate()) { + if (checkUsingShadowRedecl(*this, Shadow, + NewTemplate)) + return true; + OldD = Old = cast(Shadow->getTargetDecl()) + ->getAsFunction(); + } else { + if (checkUsingShadowRedecl(*this, Shadow, New)) + return true; + OldD = Old = cast(Shadow->getTargetDecl()); + } } else { Diag(New->getLocation(), diag::err_redefinition_different_kind) << New->getDeclName(); Index: clang/test/CXX/modules-ts/basic/basic.def.odr/p6/global-vs-module.cpp =================================================================== --- clang/test/CXX/modules-ts/basic/basic.def.odr/p6/global-vs-module.cpp +++ clang/test/CXX/modules-ts/basic/basic.def.odr/p6/global-vs-module.cpp @@ -9,7 +9,7 @@ using type = int; template extern int var_tpl; // expected-note {{previous declaration is here}} -template int func_tpl(); // expected-note-re {{{{previous declaration is here|target of using declaration}}}} +template int func_tpl(); // expected-note {{previous declaration is here}} template struct str_tpl; // expected-note {{previous declaration is here}} template using type_tpl = int; // expected-note {{previous declaration is here}} @@ -26,7 +26,7 @@ using ::str; using ::type; using ::var_tpl; -using ::func_tpl; // expected-note {{using declaration}} +using ::func_tpl; using ::str_tpl; using ::type_tpl; #endif @@ -41,8 +41,7 @@ using type = int; template extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module M follows declaration in the global module}} -// FIXME: Is this the right diagnostic in the -DUSING case? -template int func_tpl(); // expected-error-re {{{{declaration of 'func_tpl' in module M follows declaration in the global module|conflicts with target of using declaration}}}} +template int func_tpl(); // expected-error {{declaration of 'func_tpl' in module M follows declaration in the global module}} template struct str_tpl; // expected-error {{declaration of 'str_tpl' in module M follows declaration in the global module}} template using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module M follows declaration in the global module}} Index: clang/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-global.cpp =================================================================== --- clang/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-global.cpp +++ clang/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-global.cpp @@ -10,9 +10,9 @@ using type = int; template extern int var_tpl; // expected-error {{declaration of 'var_tpl' in the global module follows declaration in module M}} expected-note@global-vs-module.cpp:43 {{previous}} -template int func_tpl(); // expected-error {{declaration of 'func_tpl' in the global module follows declaration in module M}} expected-note@global-vs-module.cpp:45 {{previous}} -template struct str_tpl; // expected-error {{declaration of 'str_tpl' in the global module follows declaration in module M}} expected-note@global-vs-module.cpp:46 {{previous}} -template using type_tpl = int; // expected-error {{declaration of 'type_tpl' in the global module follows declaration in module M}} expected-note@global-vs-module.cpp:47 {{previous}} +template int func_tpl(); // expected-error {{declaration of 'func_tpl' in the global module follows declaration in module M}} expected-note@global-vs-module.cpp:44 {{previous}} +template struct str_tpl; // expected-error {{declaration of 'str_tpl' in the global module follows declaration in module M}} expected-note@global-vs-module.cpp:45 {{previous}} +template using type_tpl = int; // expected-error {{declaration of 'type_tpl' in the global module follows declaration in module M}} expected-note@global-vs-module.cpp:46 {{previous}} typedef int type; namespace ns { using ::func; } Index: clang/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-module.cpp =================================================================== --- clang/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-module.cpp +++ clang/test/CXX/modules-ts/basic/basic.def.odr/p6/module-vs-module.cpp @@ -34,9 +34,9 @@ using type = int; template extern int var_tpl; // expected-error {{declaration of 'var_tpl' in module N follows declaration in module M}} expected-note@global-vs-module.cpp:43 {{previous}} -template int func_tpl(); // expected-error {{declaration of 'func_tpl' in module N follows declaration in module M}} expected-note@global-vs-module.cpp:45 {{previous}} -template struct str_tpl; // expected-error {{declaration of 'str_tpl' in module N follows declaration in module M}} expected-note@global-vs-module.cpp:46 {{previous}} -template using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module N follows declaration in module M}} expected-note@global-vs-module.cpp:47 {{previous}} +template int func_tpl(); // expected-error {{declaration of 'func_tpl' in module N follows declaration in module M}} expected-note@global-vs-module.cpp:44 {{previous}} +template struct str_tpl; // expected-error {{declaration of 'str_tpl' in module N follows declaration in module M}} expected-note@global-vs-module.cpp:45 {{previous}} +template using type_tpl = int; // expected-error {{declaration of 'type_tpl' in module N follows declaration in module M}} expected-note@global-vs-module.cpp:46 {{previous}} typedef int type; namespace ns { using ::func; } Index: clang/test/SemaCXX/using-decl-templates.cpp =================================================================== --- clang/test/SemaCXX/using-decl-templates.cpp +++ clang/test/SemaCXX/using-decl-templates.cpp @@ -101,3 +101,33 @@ using Base::Base; // OK. Don't diagnose that 'Base' isn't a base class of Derived. }; } // namespace DontDiagnoseInvalidTest + +namespace func_templ { +namespace sss { +double foo(int, double); +template +T foo(T); +} // namespace sss + +namespace oad { +void foo(); +} + +namespace oad { +using sss::foo; +} + +namespace sss { +using oad::foo; +} + +namespace sss { +double foo(int, double) { return 0; } +// There used to be an error with the below declaration when the example should +// be accepted. +template +T foo(T t) { // OK + return t; +} +} // namespace sss +} // namespace func_templ