diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -9188,6 +9188,7 @@ << Name << RemoveRange << FixItHint::CreateRemoval(RemoveRange) << FixItHint::CreateInsertion(InsertLoc, "<>"); + NewFD->setInvalidDecl(); } } } else { diff --git a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20.cpp b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20.cpp --- a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20.cpp +++ b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20.cpp @@ -13,11 +13,16 @@ friend class A; // okay }; +template struct PR41792 { // expected-error@+1{{cannot declare an explicit specialization in a friend}} - template <> friend void f<>(int); + template <> friend void f<>(int) {} // expected-error@+2{{template specialization declaration cannot be a friend}} // expected-error@+1{{too few template arguments for class template 'A'}} template <> friend class A<>; }; + +void foo(void) { + PR41792 a; +}