Hi,

The attached patch attempts to fix http://llvm.org/bugs/show_bug.cgi?id=8295

My reasoning is that:

1. For a regular function template declaration, one would never have
template arguments
2. The same holds for overloading
3. For a function template explicit specialization ("full
specialization"), one would never have template parameters.

So, if a function template declaration has both template parameters
and template arguments, it must be an attempt at partial
specialization.

I would be grateful if someone with deeper C++ knowledge could verify
that this is correct.


Also, does C++0x change any of this?


Thanks,
Hans
Index: test/SemaTemplate/function-template-specialization.cpp
===================================================================
--- test/SemaTemplate/function-template-specialization.cpp	(revision 124117)
+++ test/SemaTemplate/function-template-specialization.cpp	(working copy)
@@ -41,3 +41,8 @@
 }
 template <> bool PR5833::f0<float>(float &t1) {}
 
+// PR8295
+namespace PR8295 {
+  template <typename T> void f(T t) {}
+  template <typename T> void f<T*>(T* t) {} // expected-error{{function template partial specialization is not allowed}}
+}
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td	(revision 124117)
+++ include/clang/Basic/DiagnosticSemaKinds.td	(working copy)
@@ -1683,6 +1683,8 @@
     "arguments to identify a particular function template">;
 def note_function_template_spec_matched : Note<
     "function template matches specialization %0">;
+def err_function_template_partial_spec : Error<
+    "function template partial specialization is not allowed">;
 
 // C++ Template Instantiation
 def err_template_recursion_depth_exceeded : Error<
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp	(revision 124117)
+++ lib/Sema/SemaDecl.cpp	(working copy)
@@ -3836,8 +3836,10 @@
       HasExplicitTemplateArgs = true;
     
       if (FunctionTemplate) {
-        // FIXME: Diagnose function template with explicit template
-        // arguments.
+        // Function template with explicit template arguments.
+        Diag(D.getIdentifierLoc(), diag::err_function_template_partial_spec)
+          << SourceRange(TemplateId->LAngleLoc, TemplateId->RAngleLoc);
+
         HasExplicitTemplateArgs = false;
       } else if (!isFunctionTemplateSpecialization && 
                  !D.getDeclSpec().isFriendSpecified()) {
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to