This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ PATCH for c++/85545, ICE with noexcept static_cast


On Fri, Apr 27, 2018 at 11:00 AM, Jason Merrill <jason@redhat.com> wrote:
> With Nathan's patch for 85437, constexpr evaluation now breaks open a
> PTRMEM_CST that has a non-qualification conversion.  Then actually
> performing the conversion means messing with the contents of the
> CONSTRUCTOR.

And some follow-on tweaks, for trunk only:
commit 92b7fa5697724db5fda39457a69d644a7f7b45f7
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Apr 27 12:49:50 2018 -0400

            * cvt.c (cp_fold_convert): Use convert_ptrmem.
    
            * typeck.c (convert_ptrmem): Add a NOP even if no adjustment.

diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 0f045e2ab12..d9e3cb520c3 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -601,16 +601,20 @@ cp_fold_convert (tree type, tree expr)
   tree conv;
   if (TREE_TYPE (expr) == type)
     conv = expr;
-  else if (TREE_CODE (expr) == PTRMEM_CST)
+  else if (TREE_CODE (expr) == PTRMEM_CST
+	   && same_type_p (TYPE_PTRMEM_CLASS_TYPE (type),
+			   PTRMEM_CST_CLASS (expr)))
     {
       /* Avoid wrapping a PTRMEM_CST in NOP_EXPR.  */
       conv = copy_node (expr);
       TREE_TYPE (conv) = type;
     }
-  else if (TREE_CODE (expr) == CONSTRUCTOR
-	   && TYPE_PTRMEMFUNC_P (type))
-    conv = build_ptrmemfunc (TYPE_PTRMEMFUNC_FN_TYPE (type), expr,
-			     true, false, tf_warning_or_error);
+  else if (TYPE_PTRMEM_P (type))
+    {
+      conv = convert_ptrmem (type, expr, true, false,
+			     tf_warning_or_error);
+      conv = cp_fully_fold (conv);
+    }
   else
     {
       conv = fold_convert (type, expr);
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 19db3154e81..05ae00ed6df 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -6844,15 +6844,16 @@ convert_ptrmem (tree type, tree expr, bool allow_inverse_p,
 
   if (TYPE_PTRDATAMEM_P (type))
     {
+      tree obase = TYPE_PTRMEM_CLASS_TYPE (TREE_TYPE (expr));
+      tree nbase = TYPE_PTRMEM_CLASS_TYPE (type);
       tree delta = (get_delta_difference
-		    (TYPE_PTRMEM_CLASS_TYPE (TREE_TYPE (expr)),
-		     TYPE_PTRMEM_CLASS_TYPE (type),
+		    (obase, nbase,
 		     allow_inverse_p, c_cast_p, complain));
 
       if (delta == error_mark_node)
 	return error_mark_node;
 
-      if (!integer_zerop (delta))
+      if (!same_type_p (obase, nbase))
 	{
 	  if (TREE_CODE (expr) == PTRMEM_CST)
 	    expr = cplus_expand_constant (expr);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]