[PATCH] D49085: [Sema] Emit a diagnostic for an invalid dependent function template specialization

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 9 09:42:27 PDT 2018


erik.pilkington created this revision.
erik.pilkington added reviewers: rjmccall, rsmith.
Herald added a subscriber: dexonsmith.

Previously, clang marked a decl as invalid without emitting a diagnostic. This lead to an assert in CodeGen for the attached test case.

rdar://41806724

Thanks for taking a look!
Erik


Repository:
  rC Clang

https://reviews.llvm.org/D49085

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp


Index: clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp
===================================================================
--- clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp
+++ clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp
@@ -359,3 +359,13 @@
   template void f2<int>(X<int> *);
   template void f2<float>(X<int> *); // expected-note{{in instantiation of function template specialization 'PR10913::f2<float, int>' requested here}}
 }
+
+namespace test16 {
+namespace s {
+template <class T> struct foo {};
+}
+using s::foo;
+template <class T> class A {
+  friend void foo<>(T); // expected-error{{dependent function template specialization of unknown function}}
+};
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -8023,8 +8023,10 @@
   }
   F.done();
 
-  // Should this be diagnosed here?
-  if (Previous.empty()) return true;
+  if (Previous.empty()) {
+    Diag(FD->getLocation(), diag::err_dependent_func_spec_does_not_specialize);
+    return true;
+  }
 
   FD->setDependentTemplateSpecialization(Context, Previous.asUnresolvedSet(),
                                          ExplicitTemplateArgs);
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4087,6 +4087,8 @@
 def err_explicit_specialization_inconsistent_storage_class : Error<
   "explicit specialization has extraneous, inconsistent storage class "
   "'%select{none|extern|static|__private_extern__|auto|register}0'">;
+def err_dependent_func_spec_does_not_specialize : Error<
+  "dependent function template specialization of unknown function">;
 
 // C++ class template specializations and out-of-line definitions
 def err_template_spec_needs_header : Error<


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49085.154627.patch
Type: text/x-patch
Size: 1962 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180709/b56dad85/attachment.bin>


More information about the cfe-commits mailing list