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