[clang] 7434610 - [Sema] Fixes templated friend member assertion
Mark de Wever via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 5 12:47:23 PST 2019
Author: Mark de Wever
Date: 2019-11-05T21:46:42+01:00
New Revision: 743461090a2027058cd438ed643ed5ed939cf1ca
URL: https://github.com/llvm/llvm-project/commit/743461090a2027058cd438ed643ed5ed939cf1ca
DIFF: https://github.com/llvm/llvm-project/commit/743461090a2027058cd438ed643ed5ed939cf1ca.diff
LOG: [Sema] Fixes templated friend member assertion
Fixes PR41792: Clang assertion failure on templated friend member function
Differential Revision: https://reviews.llvm.org/D69481
Added:
Modified:
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/temp/temp.spec/temp.expl.spec/p20.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 3f2d38630c36..a85fb6c1dc83 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2549,6 +2549,9 @@ struct DependencyChecker : RecursiveASTVisitor<DependencyChecker> {
/// list.
static bool
DependsOnTemplateParameters(QualType T, TemplateParameterList *Params) {
+ if (!Params->size())
+ return false;
+
DependencyChecker Checker(Params, /*IgnoreNonTypeDependent*/false);
Checker.TraverseType(T);
return Checker.Match;
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
index 86cdcf80cbeb..0283dba63b11 100644
--- a/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20.cpp
+++ b/clang/test/CXX/temp/temp.spec/temp.expl.spec/p20.cpp
@@ -3,7 +3,7 @@ template<typename T>
void f(T);
template<typename T>
-struct A { };
+struct A { }; // expected-note{{template is declared here}}
struct X {
template<> friend void f<int>(int); // expected-error{{in a friend}}
@@ -12,3 +12,12 @@ struct X {
friend void f<float>(float); // okay
friend class A<float>; // okay
};
+
+struct PR41792 {
+ // expected-error at +1{{cannot declare an explicit specialization in a friend}}
+ template <> friend void f<>(int);
+
+ // expected-error at +2{{template specialization declaration cannot be a friend}}
+ // expected-error at +1{{too few template arguments for class template 'A'}}
+ template <> friend class A<>;
+};
More information about the cfe-commits
mailing list