PR28943 Unusable error message when using a conditional-expression with multiple type arguments

Gabriel Dos Reis gdr@cs.tamu.edu
Wed Jan 31 16:14:00 GMT 2007


"Manuel López-Ibáñez" <lopezibanez@gmail.com> writes:

| 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:
| >
| > | :ADDPATCH c++:
| > |
| > | The error message for this code:
| > |
| > | void debug (const char * string)
| > | {
| > |   return;
| > | }
| > |
| > | int f()
| > | {
| > |   ( true == false ? 0 : debug ("Some string"));
| > |   return 0;
| > | }
| > |
| > | is:
| > |
| > | error: debug(((const char*)"Some string")) has type void and is not a
| > | throw-expression
| > |
| > | The following patch changes the message to:
| > |
| > | error: 'debug(((const char*)"Some string"))' of type 'void' is
| > | incompatible with '0' of type 'int'
| >
| > "incompatible" tends to have a precise meaning, especially when types
| > are involded.
| >
| > The rule is: if one the operand is of type void, then the other
| > operand must be of type void or a throw expression -- but both cannot
| > be a throw-expression.
| >
| >
| >
| > 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.
| >
| 
| Don't you think it is helpful to mention the type of the second
| operand or either of the operands? Just asking, I quite like the
| message but I think it could be more informative.

In this particular case, I don't think so; because we have already said
what it is not (i.e. what is expected).  If the type is shown, then the
phrase saying it is not something becomes confusing and at best
redundant. Showing the type does not really help figuring out what is
going on. (In a language where overload resolution is not bottom up,
that may have helped).

-- Gaby



More information about the Gcc-patches mailing list