[Bug c++/25992] New: condition expression and strings literal

2006-01-27 Thread anton dot kirillov at rd-software dot com
void foo( char* );

int main()
{
foo( 0 ? a : b ); // 
}

The type of expression (0 ? a : b) is const char[2] but it cannot be
transformed to char*, however it works.

Why?


-- 
   Summary: condition expression and strings literal
   Product: gcc
   Version: 3.4.5
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: anton dot kirillov at rd-software dot com


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



[Bug c++/25992] conditional expression and strings literal

2006-01-27 Thread anton dot kirillov at rd-software dot com


--- Comment #2 from anton dot kirillov at rd-software dot com  2006-01-27 
13:12 ---
(In reply to comment #1)
 earth:~g++ t.cc -pedantic -Wwrite-strings
 t.cc: In function ‘int main()’:
 t.cc:5: warning: deprecated conversion from string constant to ‘char*’'
 

Conversion from string constant to ‘char*’' it's legacy from C, but GCC should
not perceive it as const char*, because the type of expression is const char[]!

I think GCC have defined it as a compile-time constant, but it's infeasible
solution. 

In other situation it behaves correctly:

void foo( char* );

int main()
{
bool flag = false;
foo( flag ? a : b ); // error ( cannot convert from const char* to
char* )
}


-- 


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



[Bug c++/25992] conditional expression and strings literal

2006-01-27 Thread anton dot kirillov at rd-software dot com


--- Comment #4 from anton dot kirillov at rd-software dot com  2006-01-27 
14:20 ---
(In reply to comment #3)
 I have not looked into the standard yet but if GCC's warning message is 
 correct
 this is valid but deprecated code which allows for a compiler to accept it or
 not.
 

deprecated this converiont:

void foo( char* )
{
}

int main()
{
foo( lalala ); 
}

i.e. convresion from strings literal to char*, but the result of expression (0
? a : b) IS NOT STRING LITERAL!!! IT'S CONST CHAR[2]!!! ( See 5.16 )


-- 


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