Hi Jason,

On 13/02/2018 15:35, Jason Merrill wrote:
OK.
Thanks. Unfortunately, I don't think I sent a complete solution for these issues. In fact we would still ICE on:


template<typename T> int foo()
{
  return sizeof(T) > 1 ? : 1;
}

because type_contains_placeholder_p doesn't know how to handle a TEMPLATE_TYPE_PARM. In fact, cp_save_expr teaches me something:

tree
cp_save_expr (tree expr)
{
  /* There is no reason to create a SAVE_EXPR within a template; if
     needed, we can create the SAVE_EXPR when instantiating the
     template.  Furthermore, the middle-end cannot handle C++-specific
     tree codes.  */
  if (processing_template_decl)
    return expr;
  return save_expr (expr);
}

would it be correct to just use it? Or we have to do something more complex? Note the issue only affects the GNU-extension with omitted middle operand, thus I believe we have *some* leeway...

Thanks!
Paolo.

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

Index: cp/call.c
===================================================================
--- cp/call.c   (revision 257627)
+++ cp/call.c   (working copy)
@@ -4805,7 +4805,7 @@ build_conditional_expr_1 (location_t loc, tree arg
       if (lvalue_p (arg1))
        arg2 = arg1 = cp_stabilize_reference (arg1);
       else
-       arg2 = arg1 = save_expr (arg1);
+       arg2 = arg1 = cp_save_expr (arg1);
     }
 
   /* If something has already gone wrong, just pass that fact up the
Index: testsuite/g++.dg/template/sizeof16.C
===================================================================
--- testsuite/g++.dg/template/sizeof16.C        (nonexistent)
+++ testsuite/g++.dg/template/sizeof16.C        (working copy)
@@ -0,0 +1,7 @@
+// PR c++/84333
+// { dg-options -Wno-pedantic }
+
+template<typename> int foo()
+{
+  return sizeof(int) > 1 ? : 1;
+}
Index: testsuite/g++.dg/template/sizeof17.C
===================================================================
--- testsuite/g++.dg/template/sizeof17.C        (nonexistent)
+++ testsuite/g++.dg/template/sizeof17.C        (working copy)
@@ -0,0 +1,7 @@
+// PR c++/84333
+// { dg-options -Wno-pedantic }
+
+template<typename T> int foo()
+{
+  return sizeof(T) > 1 ? : 1;
+}

Reply via email to