diff mbox

C++ PATCH for core issue 941

Message ID 5171644F.5010801@redhat.com
State New
Headers show

Commit Message

Jason Merrill April 19, 2013, 3:35 p.m. UTC
The resolution of core 941 allows non-deleted specializations of deleted 
function templates.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.8.
diff mbox

Patch

commit d64070bb7f98ecbf0f1bec46f0a5acb018b60ab1
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Apr 16 13:30:34 2013 +0100

    	DR 941
    	* decl.c (duplicate_decls): Don't propagate DECL_DELETED_FN to
    	template specializations.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 01804d2..3328812 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -1764,12 +1764,16 @@  duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend)
 	  warning (OPT_Wredundant_decls, "previous declaration of %q+D", olddecl);
 	}
 
-      if (DECL_DELETED_FN (newdecl))
+      if (!(DECL_TEMPLATE_INSTANTIATION (olddecl)
+	    && DECL_TEMPLATE_SPECIALIZATION (newdecl)))
 	{
-	  error ("deleted definition of %qD", newdecl);
-	  error ("after previous declaration %q+D", olddecl);
+	  if (DECL_DELETED_FN (newdecl))
+	    {
+	      error ("deleted definition of %qD", newdecl);
+	      error ("after previous declaration %q+D", olddecl);
+	    }
+	  DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl);
 	}
-      DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl);
     }
 
   /* Deal with C++: must preserve virtual function table size.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted42.C b/gcc/testsuite/g++.dg/cpp0x/defaulted42.C
new file mode 100644
index 0000000..1ac25a9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted42.C
@@ -0,0 +1,10 @@ 
+// DR 941
+// { dg-require-effective-target c++11 }
+
+template <class T> T f(T) = delete;
+template<> int f(int) { return 42; }
+
+int main()
+{
+  f(42);
+}