diff mbox

[C++] PR 51327

Message ID 4F23E48C.60009@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Jan. 28, 2012, 12:05 p.m. UTC
Hi again,

and sorry about the delay.
> On 11/30/2011 06:41 PM, Paolo Carlini wrote:
>> Ok. The point is, locate_ctor turns an error_mark_node returned by
>> locate_fn_flags - meaning indeed not callable - into NULL_TREE. In fact,
>> uses elsewhere of locate_ctor / get_default_ctor always check for it.
> Ah, I see.  I guess what we want here is the GCC 4.5 version of 
> locate_ctor instead of the new one; once we've checked that we have a 
> default ctor and no user-provided default ctor, there must be a unique 
> defaulted ctor so just walking CLASSTYPE_CONSTRUCTORS is correct.  And 
> then we can call maybe_explain_implicit_delete if it's deleted.
So, is the below a good implementation? Tested x86_64-linux.

Thanks,
Paolo.

////////////////////
/cp
2012-01-28  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/51327
	* class.c (explain_non_literal_class): Correctly handle implicitly
	deleted constructors.

/testsuite
2012-01-28  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/51327
	* g++.dg/cpp0x/constexpr-ice6.C: New.

Comments

Jason Merrill Jan. 29, 2012, 9:24 p.m. UTC | #1
OK, just please add a comment about why we aren't using locate_ctor.

Jason
diff mbox

Patch

Index: testsuite/g++.dg/cpp0x/constexpr-ice6.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-ice6.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-ice6.C	(revision 0)
@@ -0,0 +1,11 @@ 
+// PR c++/51327
+// { dg-options -std=c++0x }
+
+struct A
+{
+  A(int);
+};
+
+struct B : A {};                   // { dg-error "no matching" }
+
+constexpr int foo(B) { return 0; } // { dg-error "invalid type" }
Index: cp/class.c
===================================================================
--- cp/class.c	(revision 183666)
+++ cp/class.c	(working copy)
@@ -4910,7 +4910,25 @@  explain_non_literal_class (tree t)
 	      "is not a copy or move constructor", t);
       if (TYPE_HAS_DEFAULT_CONSTRUCTOR (t)
 	  && !type_has_user_provided_default_constructor (t))
-	explain_invalid_constexpr_fn (locate_ctor (t));
+	{
+	  tree fns;
+	  for (fns = CLASSTYPE_CONSTRUCTORS (t); fns; fns = OVL_NEXT (fns))
+	    {
+	      tree fn = OVL_CURRENT (fns);
+	      tree parms = TYPE_ARG_TYPES (TREE_TYPE (fn));
+
+	      parms = skip_artificial_parms_for (fn, parms);
+
+	      if (sufficient_parms_p (parms))
+		{
+		  if (DECL_DELETED_FN (fn))
+		    maybe_explain_implicit_delete (fn);
+		  else
+		    explain_invalid_constexpr_fn (fn);
+		  break;
+		}
+	    }
+	}
     }
   else
     {