On 12/29/2017 12:06 PM, David Malcolm wrote:
One issue I ran into was that fold_for_warn doesn't eliminate
location wrappers when processing_template_decl, leading to
failures of the template-based cases in
g++.dg/warn/Wmemset-transposed-args-1.C.

This is due to the early bailout when processing_template_decl
within cp_fold:

2078      if (processing_template_decl
2079          || (EXPR_P (x) && (!TREE_TYPE (x) || TREE_TYPE (x) == 
error_mark_node)))
2080        return x;

which dates back to the merger of the C++ delayed folding branch.

I've fixed that in this version of the patch by removing that
"processing_template_decl ||" condition from that cp_fold early
bailout.

Hmm, that makes me nervous. We might want to fold in templates when called from fold_for_warn, but not for other occurrences. But I see that we check processing_template_decl in cp_fully_fold and in the call to cp_fold_function, so I guess this is fine.

+    case VIEW_CONVERT_EXPR:
+    case NON_LVALUE_EXPR:
     case CAST_EXPR:
     case REINTERPRET_CAST_EXPR:
     case CONST_CAST_EXPR:
@@ -14937,6 +14940,15 @@ tsubst_copy (tree t, tree args, tsubst_flags_t 
complain, tree in_decl)
     case CONVERT_EXPR:
     case NOP_EXPR:
       {
+       if (location_wrapper_p (t))
+         {
+           /* Handle location wrappers by substituting the wrapped node
+              first, *then* reusing the resulting type.  Doing the type
+              first ensures that we handle template parameters and
+              parameter pack expansions.  */
+           tree op0 = tsubst_copy (TREE_OPERAND (t, 0), args, complain, 
in_decl);
+           return build1 (code, TREE_TYPE (op0), op0);
+         }

I'd rather handle location wrappers separately, and abort if VIEW_CONVERT_EXPR or NON_LVALUE_EXPR appear other than as wrappers.

@@ -24998,6 +25018,8 @@ build_non_dependent_expr (tree expr)
       && !expanding_concept ())
     fold_non_dependent_expr (expr);
+ STRIP_ANY_LOCATION_WRAPPER (expr);

Why is this needed?

Jason

Reply via email to