public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/28943]  New: Unusable error message when using a conditional-expression with multiple type arguments
@ 2006-09-03 19:35 lindevel at gmx dot net
  2006-09-03 19:36 ` [Bug c++/28943] " lindevel at gmx dot net
                   ` (9 more replies)
  0 siblings, 10 replies; 12+ messages in thread
From: lindevel at gmx dot net @ 2006-09-03 19:35 UTC (permalink / raw)
  To: gcc-bugs

When I use a conditional-expression(?:) with arguments whose type is not
matching, g++ gives an error message not telling me exactly what the problem
is.


Commandline:
----
g++ assert_testcase.cpp
----

Output:
----
assert_testcase.cpp: In function ‘int main()’:
assert_testcase.cpp:16: error: ‘debug(((const char*)"Some
string"))’ has type ‘void’ and is not a throw-expression
----

For this code (assert_testcase.cpp):
----
#include <stdio.h>

void debug( const char * string )
{
    printf( string );
}

int main()
{
    ( true == false ? 0 : debug( "Some string" ) );

    return 0;
}
----

Changing ( true == false ? 0 : debug( "Some string" ) ) to ( true == false ?
(void)0 : debug( "Some string" ) ) silences the error message.

And that has been found out after about a week of own research in our project
and then asking in ##c++ on FreeNode, because no one had a clue what it could
mean. (And even ##c++ needed several hours to find that out.)
So I think that error message is unusable because it is not clear about what
exactly the problem is.
Better would be IMHO something like "0 is of different type than debug(...)".


Other info:
----
i686-pc-linux-gnu-g++ (GCC) 4.1.1 (Gentoo 4.1.1)
----

Preprocessed file (assert_testcase.ii) will be attached.

I can provide more information if you like.


-- 
           Summary: Unusable error message when using a conditional-
                    expression with multiple type arguments
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: trivial
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: lindevel at gmx dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28943


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/28943] Unusable error message when using a conditional-expression with multiple type arguments
  2006-09-03 19:35 [Bug c++/28943] New: Unusable error message when using a conditional-expression with multiple type arguments lindevel at gmx dot net
@ 2006-09-03 19:36 ` lindevel at gmx dot net
  2006-09-03 19:36 ` lindevel at gmx dot net
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: lindevel at gmx dot net @ 2006-09-03 19:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from lindevel at gmx dot net  2006-09-03 19:36 -------
Created an attachment (id=12182)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12182&action=view)
Preprocessed testcase


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28943


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/28943] Unusable error message when using a conditional-expression with multiple type arguments
  2006-09-03 19:35 [Bug c++/28943] New: Unusable error message when using a conditional-expression with multiple type arguments lindevel at gmx dot net
  2006-09-03 19:36 ` [Bug c++/28943] " lindevel at gmx dot net
@ 2006-09-03 19:36 ` lindevel at gmx dot net
  2006-09-03 19:41 ` [Bug c++/28943] New: " Andrew Pinski
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: lindevel at gmx dot net @ 2006-09-03 19:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from lindevel at gmx dot net  2006-09-03 19:35 -------
Created an attachment (id=12181)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12181&action=view)
Testcase code


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28943


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Bug c++/28943]  New: Unusable error message when using a  conditional-expression with multiple type arguments
  2006-09-03 19:35 [Bug c++/28943] New: Unusable error message when using a conditional-expression with multiple type arguments lindevel at gmx dot net
  2006-09-03 19:36 ` [Bug c++/28943] " lindevel at gmx dot net
  2006-09-03 19:36 ` lindevel at gmx dot net
@ 2006-09-03 19:41 ` Andrew Pinski
  2006-09-03 19:41 ` [Bug c++/28943] " pinskia at physics dot uc dot edu
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Andrew Pinski @ 2006-09-03 19:41 UTC (permalink / raw)
  To: gcc-bugzilla; +Cc: gcc-bugs

On Sun, 2006-09-03 at 19:35 +0000, lindevel at gmx dot net wrote:
> assert_testcase.cpp: In function &#8216;int main()&#8217;:
> assert_testcase.cpp:16: error: &#8216;debug(((const char*)"Some
> string"))&#8217; has type &#8216;void&#8217; and is not a
> throw-expression 

That says to me that the expression `debug("Some string")' has a type of
void (and is not a throw expression) which is invalid for ?: if the
other type is not void.  I don't see where the problem is.  A throw
expression is valid (here by the C++ standard) even though it has a
expression type of void.

-- Pinski


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/28943] Unusable error message when using a conditional-expression with multiple type arguments
  2006-09-03 19:35 [Bug c++/28943] New: Unusable error message when using a conditional-expression with multiple type arguments lindevel at gmx dot net
                   ` (2 preceding siblings ...)
  2006-09-03 19:41 ` [Bug c++/28943] New: " Andrew Pinski
@ 2006-09-03 19:41 ` pinskia at physics dot uc dot edu
  2006-09-03 20:08 ` lindevel at gmx dot net
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: pinskia at physics dot uc dot edu @ 2006-09-03 19:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at physics dot uc dot edu  2006-09-03 19:41 -------
Subject: Re:   New: Unusable error message when using a
        conditional-expression with multiple type arguments

On Sun, 2006-09-03 at 19:35 +0000, lindevel at gmx dot net wrote:
> assert_testcase.cpp: In function &#8216;int main()&#8217;:
> assert_testcase.cpp:16: error: &#8216;debug(((const char*)"Some
> string"))&#8217; has type &#8216;void&#8217; and is not a
> throw-expression 

That says to me that the expression `debug("Some string")' has a type of
void (and is not a throw expression) which is invalid for ?: if the
other type is not void.  I don't see where the problem is.  A throw
expression is valid (here by the C++ standard) even though it has a
expression type of void.

-- Pinski


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28943


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/28943] Unusable error message when using a conditional-expression with multiple type arguments
  2006-09-03 19:35 [Bug c++/28943] New: Unusable error message when using a conditional-expression with multiple type arguments lindevel at gmx dot net
                   ` (3 preceding siblings ...)
  2006-09-03 19:41 ` [Bug c++/28943] " pinskia at physics dot uc dot edu
@ 2006-09-03 20:08 ` lindevel at gmx dot net
  2006-09-03 20:18   ` Andrew Pinski
  2006-09-03 20:18 ` pinskia at physics dot uc dot edu
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 12+ messages in thread
From: lindevel at gmx dot net @ 2006-09-03 20:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from lindevel at gmx dot net  2006-09-03 20:08 -------
You proved ##c++ wrong! They bet that I would be ignored. ;)

The thing is that a void itself is not invalid. Using (expr ? void : void)
works as you see in my report.
In ##c++ I was told that ( x ? y : z ) wants both y and z to be of the same
type. And that is stated in no way by the error message.

And even if void would be invalid, the message doesn't tell me that. It just
tells me "Hey I found a void.", but not that a void is invalid in a (?:).
The connection to (?:) is not made. Instead it tells me something about a
throw-expression. That might be a good message when you want to understand the
internal code g++ uses to validate the expression, but for an end user it is
not good.

Perhaps we first should clear up what exactly the error is with that code. (I
still don't know from the error message and you tell me something different
than what I was told in ##c++. (Who also didn't know what that message could
mean until someone said that the types don't match and g++ might be telling me
how it found out.))


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28943


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/28943] Unusable error message when using a conditional-expression with multiple type arguments
  2006-09-03 19:35 [Bug c++/28943] New: Unusable error message when using a conditional-expression with multiple type arguments lindevel at gmx dot net
                   ` (4 preceding siblings ...)
  2006-09-03 20:08 ` lindevel at gmx dot net
@ 2006-09-03 20:18 ` pinskia at physics dot uc dot edu
  2006-09-03 20:38 ` lindevel at gmx dot net
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: pinskia at physics dot uc dot edu @ 2006-09-03 20:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at physics dot uc dot edu  2006-09-03 20:18 -------
Subject: Re:  Unusable error message when using a
        conditional-expression with multiple type arguments

On Sun, 2006-09-03 at 20:08 +0000, lindevel at gmx dot net wrote:
> 
> ------- Comment #4 from lindevel at gmx dot net  2006-09-03 20:08 -------
> You proved ##c++ wrong! They bet that I would be ignored. ;)
> 
> The thing is that a void itself is not invalid. Using (expr ? void : void)
> works as you see in my report.
> In ##c++ I was told that ( x ? y : z ) wants both y and z to be of the same
> type. And that is stated in no way by the error message.

void is valid if the both sides of the : are void, otherwise it is
invalid.  And they don't have to be the same type either, they can be
different as long as one is convertible to the other (like float and int
or two classes where one is a base class of the other).


-- Pinski


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28943


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Bug c++/28943] Unusable error message when using a  conditional-expression with multiple type arguments
  2006-09-03 20:08 ` lindevel at gmx dot net
@ 2006-09-03 20:18   ` Andrew Pinski
  0 siblings, 0 replies; 12+ messages in thread
From: Andrew Pinski @ 2006-09-03 20:18 UTC (permalink / raw)
  To: gcc-bugzilla; +Cc: gcc-bugs

On Sun, 2006-09-03 at 20:08 +0000, lindevel at gmx dot net wrote:
> 
> ------- Comment #4 from lindevel at gmx dot net  2006-09-03 20:08 -------
> You proved ##c++ wrong! They bet that I would be ignored. ;)
> 
> The thing is that a void itself is not invalid. Using (expr ? void : void)
> works as you see in my report.
> In ##c++ I was told that ( x ? y : z ) wants both y and z to be of the same
> type. And that is stated in no way by the error message.

void is valid if the both sides of the : are void, otherwise it is
invalid.  And they don't have to be the same type either, they can be
different as long as one is convertible to the other (like float and int
or two classes where one is a base class of the other).


-- Pinski


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/28943] Unusable error message when using a conditional-expression with multiple type arguments
  2006-09-03 19:35 [Bug c++/28943] New: Unusable error message when using a conditional-expression with multiple type arguments lindevel at gmx dot net
                   ` (5 preceding siblings ...)
  2006-09-03 20:18 ` pinskia at physics dot uc dot edu
@ 2006-09-03 20:38 ` lindevel at gmx dot net
  2007-01-31  9:45 ` patchapp at dberlin dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: lindevel at gmx dot net @ 2006-09-03 20:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from lindevel at gmx dot net  2006-09-03 20:38 -------
Perhaps the message should then be "0 (int) is of incompatible type to
debug(...) (void)" or similar? At least it should be more clear about the fact
that the error is that both sides of the : need to be compatible (and are not).

I though about all kinds of other things, but not of an incompatibility,
because the error message tells me about void and throw expressions and not
about the specs for (?:).

Don't get me wrong, I don't want g++ to output a C++ beginners manual, but at
least it should be clear from an error message where the error is, otherwise
the message is useless.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28943


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/28943] Unusable error message when using a conditional-expression with multiple type arguments
  2006-09-03 19:35 [Bug c++/28943] New: Unusable error message when using a conditional-expression with multiple type arguments lindevel at gmx dot net
                   ` (6 preceding siblings ...)
  2006-09-03 20:38 ` lindevel at gmx dot net
@ 2007-01-31  9:45 ` patchapp at dberlin dot org
  2007-02-15 22:15 ` manu at gcc dot gnu dot org
  2007-02-15 22:35 ` manu at gcc dot gnu dot org
  9 siblings, 0 replies; 12+ messages in thread
From: patchapp at dberlin dot org @ 2007-01-31  9:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from patchapp at dberlin dot org  2007-01-31 09:45 -------
Subject: Bug number PR28943

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is
http://gcc.gnu.org/ml/gcc-patches/2007-01/msg02582.html


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28943


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/28943] Unusable error message when using a conditional-expression with multiple type arguments
  2006-09-03 19:35 [Bug c++/28943] New: Unusable error message when using a conditional-expression with multiple type arguments lindevel at gmx dot net
                   ` (7 preceding siblings ...)
  2007-01-31  9:45 ` patchapp at dberlin dot org
@ 2007-02-15 22:15 ` manu at gcc dot gnu dot org
  2007-02-15 22:35 ` manu at gcc dot gnu dot org
  9 siblings, 0 replies; 12+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-02-15 22:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from manu at gcc dot gnu dot org  2007-02-15 22:15 -------
Subject: Bug 28943

Author: manu
Date: Thu Feb 15 22:15:20 2007
New Revision: 122016

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122016
Log:
2007-02-15  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.

Added:
    trunk/gcc/testsuite/g++.dg/warn/pr28943.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28943


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug c++/28943] Unusable error message when using a conditional-expression with multiple type arguments
  2006-09-03 19:35 [Bug c++/28943] New: Unusable error message when using a conditional-expression with multiple type arguments lindevel at gmx dot net
                   ` (8 preceding siblings ...)
  2007-02-15 22:15 ` manu at gcc dot gnu dot org
@ 2007-02-15 22:35 ` manu at gcc dot gnu dot org
  9 siblings, 0 replies; 12+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-02-15 22:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from manu at gcc dot gnu dot org  2007-02-15 22:35 -------
Fixed in GCC 4.3


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.3.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28943


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2007-02-15 22:35 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-03 19:35 [Bug c++/28943] New: Unusable error message when using a conditional-expression with multiple type arguments lindevel at gmx dot net
2006-09-03 19:36 ` [Bug c++/28943] " lindevel at gmx dot net
2006-09-03 19:36 ` lindevel at gmx dot net
2006-09-03 19:41 ` [Bug c++/28943] New: " Andrew Pinski
2006-09-03 19:41 ` [Bug c++/28943] " pinskia at physics dot uc dot edu
2006-09-03 20:08 ` lindevel at gmx dot net
2006-09-03 20:18   ` Andrew Pinski
2006-09-03 20:18 ` pinskia at physics dot uc dot edu
2006-09-03 20:38 ` lindevel at gmx dot net
2007-01-31  9:45 ` patchapp at dberlin dot org
2007-02-15 22:15 ` manu at gcc dot gnu dot org
2007-02-15 22:35 ` manu at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).