@@ -8585,6 +8585,42 @@ lvalue_error (enum lvalue_use use)
gcc_unreachable ();
}
}
+
+/* Print an error message for an invalid indirection of type TYPE.
+ ERRSTRING is the name of the operator for the indirection. */
+
+void
+invalid_indirection_error (location_t loc, tree type, ref_operator errstring)
+{
+ switch (errstring)
+ {
+ case RO_NULL:
+ error_at (loc, "invalid type argument (have %qT)", type);
+ break;
+ case RO_ARRAY_INDEXING:
+ error_at (loc,
+ "invalid type argument of array indexing (have %qT)",
+ type);
+ break;
+ case RO_UNARY_STAR:
+ error_at (loc,
+ "invalid type argument of unary %<*%> (have %qT)",
+ type);
+ break;
+ case RO_ARROW:
+ error_at (loc,
+ "invalid type argument of %<->%> (have %qT)",
+ type);
+ break;
+ case RO_IMPLICIT_CONVERSION:
+ error_at (loc,
+ "invalid type argument of implicit conversion (have %qT)",
+ type);
+ break;
+ default:
+ gcc_unreachable ();
+ }
+}
/* *PTYPE is an incomplete array. Complete it with a domain based on
INITIAL_VALUE. If INITIAL_VALUE is not present, use 1 if DO_DEFAULT
@@ -929,6 +929,7 @@ enum lvalue_use {
};
extern void lvalue_error (enum lvalue_use);
+extern void invalid_indirection_error (location_t, tree, ref_operator);
extern int complete_array_type (tree *, tree, bool);
@@ -2267,26 +2267,8 @@ build_indirect_ref (location_t loc, tree ptr, ref_operator errstring)
}
}
else if (TREE_CODE (pointer) != ERROR_MARK)
- switch (errstring)
- {
- case RO_ARRAY_INDEXING:
- error_at (loc,
- "invalid type argument of array indexing (have %qT)",
- type);
- break;
- case RO_UNARY_STAR:
- error_at (loc,
- "invalid type argument of unary %<*%> (have %qT)",
- type);
- break;
- case RO_ARROW:
- error_at (loc,
- "invalid type argument of %<->%> (have %qT)",
- type);
- break;
- default:
- gcc_unreachable ();
- }
+ invalid_indirection_error (loc, type, errstring);
+
return error_mark_node;
}
@@ -2804,23 +2804,8 @@ cp_build_indirect_ref (tree ptr, ref_operator errorstring,
gcc_unreachable ();
}
else if (pointer != error_mark_node)
- switch (errorstring)
- {
- case RO_NULL:
- error ("invalid type argument");
- break;
- case RO_ARRAY_INDEXING:
- error ("invalid type argument of array indexing");
- break;
- case RO_UNARY_STAR:
- error ("invalid type argument of unary %<*%>");
- break;
- case RO_IMPLICIT_CONVERSION:
- error ("invalid type argument of implicit conversion");
- break;
- default:
- gcc_unreachable ();
- }
+ invalid_indirection_error (input_location, type, errorstring);
+
return error_mark_node;
}