[try2] PR28943 Unusable error message when using a conditional-expression with multiple type arguments
Manuel López-Ibáñez
lopezibanez@gmail.com
Tue Feb 13 23:05:00 GMT 2007
On 31 Jan 2007 04:15:12 -0600, Gabriel Dos Reis <gdr@cs.tamu.edu> wrote:
> "Manuel López-Ibáñez" <lopezibanez@gmail.com> writes:
>
> I would prefer the "improved" diagnostic to say something like
>
> third operand to the conditional operator is of type 'void', but
> the second operand is neither a throw-expression nor of type 'void'
>
> and swap second/third the other around to cover the symmetric case.
>
Here is the improved patch. Bootstrapped and regression tested. I hope
this is what you wanted.
Cheers,
Manuel.
2007-02-12 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR c++/28943
cp/
* call.c (build_conditional_expr): Improve error message.
testsuite/
* g++.dg/warn/pr28943.C: New.
-------------- next part --------------
Index: gcc/testsuite/g++.dg/warn/pr28943.C
===================================================================
--- gcc/testsuite/g++.dg/warn/pr28943.C (revision 0)
+++ gcc/testsuite/g++.dg/warn/pr28943.C (revision 0)
@@ -0,0 +1,15 @@
+// PR c++/28943 void and non-void in conditional expression
+// { dg-do compile }
+// { dg-options "" }
+
+void debug (const char * string)
+{
+ return;
+}
+
+int f()
+{
+ ( true == false ? 0 : debug ("Some string")); // { dg-error "third operand to the conditional operator is of type 'void', but the second operand is neither a throw-expression nor of type 'void'" }
+ ( true == false ? debug ("Some string") : 0 ); // { dg-error "second operand to the conditional operator is of type 'void', but the third operand is neither a throw-expression nor of type 'void'" }
+ return 0;
+}
Index: gcc/cp/call.c
===================================================================
--- gcc/cp/call.c (revision 121678)
+++ gcc/cp/call.c (working copy)
@@ -3281,8 +3281,12 @@ build_conditional_expr (tree arg1, tree
result_type = void_type_node;
else
{
- error ("%qE has type %<void%> and is not a throw-expression",
- VOID_TYPE_P (arg2_type) ? arg2 : arg3);
+ if (VOID_TYPE_P (arg2_type))
+ error ("second operand to the conditional operator is of type %<void%>, "
+ "but the third operand is neither a throw-expression nor of type %<void%>");
+ else
+ error ("third operand to the conditional operator is of type %<void%>, "
+ "but the second operand is neither a throw-expression nor of type %<void%>");
return error_mark_node;
}
More information about the Gcc-patches
mailing list