public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch/RFC] PR 58582
@ 2014-05-02 10:35 Paolo Carlini
  2014-05-02 18:05 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Paolo Carlini @ 2014-05-02 10:35 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jason Merrill

[-- Attachment #1: Type: text/plain, Size: 796 bytes --]

Hi,

this relatively old bug report is about an ICE during error recovery and 
some time ago I figured out that the below simple tweak to grokfndecl 
worked for it (we notice that duplicate_decls returned error_mark_node). 
Today, however, while formatting the original testcases, I noticed 
something slightly more interesting: at variance with both current clang 
and icc, we reject the below deleted6.C, thus we reject explicit 
instantiations of deleted template functions (without explaining that 
the function is deleted in the error message and still accepting the 
code with -fpermissive (?)). Thus the below tweak to instantiate_decl. 
Without it, 58582 is still fixed of course, only the testcases need a 
little adjusting.

Tested x86_64-linux.

Thanks,
Paolo.

//////////////////////

[-- Attachment #2: patch_58582 --]
[-- Type: text/plain, Size: 2090 bytes --]

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 210004)
+++ cp/decl.c	(working copy)
@@ -7822,6 +7822,8 @@ grokfndecl (tree ctype,
 		     decl, ctype);
 	      return NULL_TREE;
 	    }
+	  if (ok == error_mark_node)
+	    return NULL_TREE;
 	  return old_decl;
 	}
     }
Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 210004)
+++ cp/pt.c	(working copy)
@@ -19698,7 +19699,8 @@ instantiate_decl (tree d, int defer_ok,
 
       if (at_eof && !pattern_defined
 	  && DECL_EXPLICIT_INSTANTIATION (d)
-	  && DECL_NOT_REALLY_EXTERN (d))
+	  && DECL_NOT_REALLY_EXTERN (d)
+	  && (TREE_CODE (d) != FUNCTION_DECL || !DECL_DELETED_FN (d)))
 	/* [temp.explicit]
 
 	   The definition of a non-exported function template, a
Index: testsuite/g++.dg/cpp0x/deleted4.C
===================================================================
--- testsuite/g++.dg/cpp0x/deleted4.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/deleted4.C	(working copy)
@@ -0,0 +1,11 @@
+// PR c++/58582
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  template<int> void foo() = delete;
+};
+
+template<int> void A::foo() { int i; } // { dg-error "redefinition" }
+
+template void A::foo<0>();
Index: testsuite/g++.dg/cpp0x/deleted5.C
===================================================================
--- testsuite/g++.dg/cpp0x/deleted5.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/deleted5.C	(working copy)
@@ -0,0 +1,11 @@
+// PR c++/58582
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  template<int> void foo() = delete;
+};
+
+template<int> void A::foo() {} // { dg-error "redefinition" }
+
+template void A::foo<0>();
Index: testsuite/g++.dg/cpp0x/deleted6.C
===================================================================
--- testsuite/g++.dg/cpp0x/deleted6.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/deleted6.C	(working copy)
@@ -0,0 +1,9 @@
+// PR c++/58582
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  template<int> void foo() = delete;
+};
+
+template void A::foo<0>();

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [C++ Patch/RFC] PR 58582
  2014-05-02 10:35 [C++ Patch/RFC] PR 58582 Paolo Carlini
@ 2014-05-02 18:05 ` Jason Merrill
  2014-05-02 21:52   ` Paolo Carlini
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2014-05-02 18:05 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches

I'd tweak instantiate_decl differently; a deleted function is defined, 
so pattern_defined should be true.

Jason

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [C++ Patch/RFC] PR 58582
  2014-05-02 18:05 ` Jason Merrill
@ 2014-05-02 21:52   ` Paolo Carlini
  2014-05-03 13:11     ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Paolo Carlini @ 2014-05-02 21:52 UTC (permalink / raw)
  To: Jason Merrill, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 475 bytes --]

Hi,

On 05/02/2014 08:05 PM, Jason Merrill wrote:
> I'd tweak instantiate_decl differently; a deleted function is defined, 
> so pattern_defined should be true.
I see, thanks. Simply setting pattern_defined and nothing else appears 
to work very well. The only minor annoyance is that DECL_STRUCT_FUNCTION 
can be null and we have to check for that before using it (in fact, we 
do that in 2 other places too). Tested x86_64-linux.

Thanks again,
Paolo.

///////////////////

[-- Attachment #2: patch_58582_2 --]
[-- Type: text/plain, Size: 3180 bytes --]

Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 210004)
+++ cp/decl.c	(working copy)
@@ -7822,6 +7822,8 @@ grokfndecl (tree ctype,
 		     decl, ctype);
 	      return NULL_TREE;
 	    }
+	  if (ok == error_mark_node)
+	    return NULL_TREE;
 	  return old_decl;
 	}
     }
Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 210004)
+++ cp/pt.c	(working copy)
@@ -19616,7 +19617,8 @@ instantiate_decl (tree d, int defer_ok,
 
   if (TREE_CODE (d) == FUNCTION_DECL)
     pattern_defined = (DECL_SAVED_TREE (code_pattern) != NULL_TREE
-		       || DECL_DEFAULTED_OUTSIDE_CLASS_P (code_pattern));
+		       || DECL_DEFAULTED_OUTSIDE_CLASS_P (code_pattern)
+		       || DECL_DELETED_FN (code_pattern));
   else
     pattern_defined = ! DECL_IN_AGGR_P (code_pattern);
 
@@ -19858,14 +19860,17 @@ instantiate_decl (tree d, int defer_ok,
 		       tf_warning_or_error, tmpl,
 		       /*integral_constant_expression_p=*/false);
 
-	  /* Set the current input_location to the end of the function
-	     so that finish_function knows where we are.  */
-	  input_location
-	    = DECL_STRUCT_FUNCTION (code_pattern)->function_end_locus;
+	  if (DECL_STRUCT_FUNCTION (code_pattern))
+	    {
+	      /* Set the current input_location to the end of the function
+		 so that finish_function knows where we are.  */
+	      input_location
+		= DECL_STRUCT_FUNCTION (code_pattern)->function_end_locus;
 
-	  /* Remember if we saw an infinite loop in the template.  */
-	  current_function_infinite_loop
-	    = DECL_STRUCT_FUNCTION (code_pattern)->language->infinite_loop;
+	      /* Remember if we saw an infinite loop in the template.  */
+	      current_function_infinite_loop
+		= DECL_STRUCT_FUNCTION (code_pattern)->language->infinite_loop;
+	    }
 	}
 
       /* We don't need the local specializations any more.  */
Index: testsuite/g++.dg/cpp0x/deleted4.C
===================================================================
--- testsuite/g++.dg/cpp0x/deleted4.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/deleted4.C	(working copy)
@@ -0,0 +1,11 @@
+// PR c++/58582
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  template<int> void foo() = delete;
+};
+
+template<int> void A::foo() { int i; } // { dg-error "redefinition" }
+
+template void A::foo<0>();
Index: testsuite/g++.dg/cpp0x/deleted5.C
===================================================================
--- testsuite/g++.dg/cpp0x/deleted5.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/deleted5.C	(working copy)
@@ -0,0 +1,11 @@
+// PR c++/58582
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  template<int> void foo() = delete;
+};
+
+template<int> void A::foo() {} // { dg-error "redefinition" }
+
+template void A::foo<0>();
Index: testsuite/g++.dg/cpp0x/deleted6.C
===================================================================
--- testsuite/g++.dg/cpp0x/deleted6.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/deleted6.C	(working copy)
@@ -0,0 +1,9 @@
+// PR c++/58582
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  template<int> void foo() = delete;
+};
+
+template void A::foo<0>();

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [C++ Patch/RFC] PR 58582
  2014-05-02 21:52   ` Paolo Carlini
@ 2014-05-03 13:11     ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2014-05-03 13:11 UTC (permalink / raw)
  To: Paolo Carlini, gcc-patches

OK.

Jason

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-05-03 13:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-02 10:35 [C++ Patch/RFC] PR 58582 Paolo Carlini
2014-05-02 18:05 ` Jason Merrill
2014-05-02 21:52   ` Paolo Carlini
2014-05-03 13:11     ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).