Author: Yuanfang Chen Date: 2021-12-15T10:26:55-08:00 New Revision: 1510595dce9c48b9e7ddd49becd422c4e5e66fc9
URL: https://github.com/llvm/llvm-project/commit/1510595dce9c48b9e7ddd49becd422c4e5e66fc9 DIFF: https://github.com/llvm/llvm-project/commit/1510595dce9c48b9e7ddd49becd422c4e5e66fc9.diff LOG: [Sema] Mark explicit specialization declaration in a friend invalid Down the path, if there is a implicit instantiation, this may trigger the assertion "Member specialization must be an explicit specialization" in `clang::FunctionDecl::setFunctionTemplateSpecialization`. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D113245 Added: clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp Modified: clang/lib/Sema/SemaDecl.cpp Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index b1312a7ccc512..5e9c92db81b4a 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -9202,6 +9202,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, << Name << RemoveRange << FixItHint::CreateRemoval(RemoveRange) << FixItHint::CreateInsertion(InsertLoc, "<>"); + Invalid = true; } } } else { diff --git a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp new file mode 100644 index 0000000000000..7bc5f13cd7375 --- /dev/null +++ b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20-2.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +template<typename T> +void f(T); + +template<typename T> +struct A { + // expected-error@+1{{cannot declare an explicit specialization in a friend}} + template <> friend void f<>(int) {} +}; + +// Makes sure implicit instantiation here does not trigger +// the assertion "Member specialization must be an explicit specialization" +void foo(void) { + A<int> a; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits