public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/25992] New: condition expression and strings literal
@ 2006-01-27 10:39 anton dot kirillov at rd-software dot com
2006-01-27 12:39 ` [Bug c++/25992] conditional " pinskia at gcc dot gnu dot org
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: anton dot kirillov at rd-software dot com @ 2006-01-27 10:39 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/25992] conditional expression and strings literal
2006-01-27 10:39 [Bug c++/25992] New: condition expression and strings literal anton dot kirillov at rd-software dot com
@ 2006-01-27 12:39 ` pinskia at gcc dot gnu dot org
2006-01-27 13:12 ` anton dot kirillov at rd-software dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-27 12:39 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 293 bytes --]
------- Comment #1 from pinskia at gcc dot gnu dot org 2006-01-27 12:39 -------
earth:~>g++ t.cc -pedantic -Wwrite-strings
t.cc: In function int main():
t.cc:5: warning: deprecated conversion from string constant to char*'
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25992
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/25992] conditional expression and strings literal
2006-01-27 10:39 [Bug c++/25992] New: condition expression and strings literal anton dot kirillov at rd-software dot com
2006-01-27 12:39 ` [Bug c++/25992] conditional " pinskia at gcc dot gnu dot org
@ 2006-01-27 13:12 ` anton dot kirillov at rd-software dot com
2006-01-27 13:59 ` pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: anton dot kirillov at rd-software dot com @ 2006-01-27 13:12 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 780 bytes --]
------- 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/25992] conditional expression and strings literal
2006-01-27 10:39 [Bug c++/25992] New: condition expression and strings literal anton dot kirillov at rd-software dot com
2006-01-27 12:39 ` [Bug c++/25992] conditional " pinskia at gcc dot gnu dot org
2006-01-27 13:12 ` anton dot kirillov at rd-software dot com
@ 2006-01-27 13:59 ` pinskia at gcc dot gnu dot org
2006-01-27 14:20 ` anton dot kirillov at rd-software dot com
2006-03-08 5:02 ` bangerth at dealii dot org
4 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-27 13:59 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pinskia at gcc dot gnu dot org 2006-01-27 13:59 -------
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.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25992
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/25992] conditional expression and strings literal
2006-01-27 10:39 [Bug c++/25992] New: condition expression and strings literal anton dot kirillov at rd-software dot com
` (2 preceding siblings ...)
2006-01-27 13:59 ` pinskia at gcc dot gnu dot org
@ 2006-01-27 14:20 ` anton dot kirillov at rd-software dot com
2006-03-08 5:02 ` bangerth at dealii dot org
4 siblings, 0 replies; 8+ messages in thread
From: anton dot kirillov at rd-software dot com @ 2006-01-27 14:20 UTC (permalink / raw)
To: gcc-bugs
------- 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/25992] conditional expression and strings literal
2006-01-27 10:39 [Bug c++/25992] New: condition expression and strings literal anton dot kirillov at rd-software dot com
` (3 preceding siblings ...)
2006-01-27 14:20 ` anton dot kirillov at rd-software dot com
@ 2006-03-08 5:02 ` bangerth at dealii dot org
4 siblings, 0 replies; 8+ messages in thread
From: bangerth at dealii dot org @ 2006-03-08 5:02 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from bangerth at dealii dot org 2006-03-08 05:02 -------
Confirmed. These two lines should behave the same, but don't:
--------------
extern bool flag;
int main()
{
char* p;
p = (true ? "a" : "lalala" );
p = (flag ? "a" : "lalala" );
}
--------------
g/x> /home/bangerth/bin/gcc-4.2*/bin/c++ -c x.cc -Wwrite-strings
x.cc: In function ‘int main()’:
x.cc:5: warning: deprecated conversion from string constant to
‘char*’'
x.cc:6: error: invalid conversion from ‘const char*’ to
‘char*’
W.
--
bangerth at dealii dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |diagnostic
Last reconfirmed|0000-00-00 00:00:00 |2006-03-08 05:02:36
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25992
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/25992] conditional expression and strings literal
[not found] <bug-25992-4@http.gcc.gnu.org/bugzilla/>
2014-07-15 12:43 ` paolo.carlini at oracle dot com
@ 2014-07-15 15:25 ` paolo.carlini at oracle dot com
1 sibling, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-07-15 15:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25992
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |NEW
Assignee|paolo.carlini at oracle dot com |unassigned at gcc dot gnu.org
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/25992] conditional expression and strings literal
[not found] <bug-25992-4@http.gcc.gnu.org/bugzilla/>
@ 2014-07-15 12:43 ` paolo.carlini at oracle dot com
2014-07-15 15:25 ` paolo.carlini at oracle dot com
1 sibling, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-07-15 12:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25992
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
CC|anton.kirillov@rd-software. |
|com, gcc-bugs at gcc dot gnu.org |
Assignee|unassigned at gcc dot gnu.org |paolo.carlini at oracle dot com
--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Mine.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-07-15 15:25 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-27 10:39 [Bug c++/25992] New: condition expression and strings literal anton dot kirillov at rd-software dot com
2006-01-27 12:39 ` [Bug c++/25992] conditional " pinskia at gcc dot gnu dot org
2006-01-27 13:12 ` anton dot kirillov at rd-software dot com
2006-01-27 13:59 ` pinskia at gcc dot gnu dot org
2006-01-27 14:20 ` anton dot kirillov at rd-software dot com
2006-03-08 5:02 ` bangerth at dealii dot org
[not found] <bug-25992-4@http.gcc.gnu.org/bugzilla/>
2014-07-15 12:43 ` paolo.carlini at oracle dot com
2014-07-15 15:25 ` paolo.carlini at oracle dot com
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).