public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/50645] New: old issue - deprecated conversion from string to char*
@ 2011-10-07 0:11 mike.c at rocketime dot com
2011-10-07 0:35 ` [Bug c/50645] " mike.c at rocketime dot com
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: mike.c at rocketime dot com @ 2011-10-07 0:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50645
Bug #: 50645
Summary: old issue - deprecated conversion from string to char*
Classification: Unclassified
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: mike.c@rocketime.com
While I know this is an old issue, I port a lot of code, so this keeps coming
up: (I know u can change the warning level).
If I declare:
const char *DowNames[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
NULL
};
as just char* instead of const char*, YES I WOULD LIKE TO GET A WARNING.
HOWEVER, if I have a function:
myfunction(char *buf) {}
I'd like to be able to call it like this
myfunction("hello world")
... WITH NO 'deprecated conversion from string to char*' WARNING
because char* as a parameter should be able to take a string as an argument --
this makes sense.
It's annoying to have to cast (char*)"hello world" every place in code, as
programmers always used to use, simply "hello world". (i know an option is to
change the warning level -- but that has other issues.)
PLEASE UNDEPRECATE! (Keep things simple, keep backward compatibility, as the
old-school way is often best, designed that way for simplicity!)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/50645] old issue - deprecated conversion from string to char*
2011-10-07 0:11 [Bug c/50645] New: old issue - deprecated conversion from string to char* mike.c at rocketime dot com
@ 2011-10-07 0:35 ` mike.c at rocketime dot com
2011-10-07 0:38 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: mike.c at rocketime dot com @ 2011-10-07 0:35 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50645
--- Comment #1 from mike.c at rocketime dot com 2011-10-07 00:35:20 UTC ---
The quick fix:
#pragma GCC diagnostic ignored "-Wwrite-strings"
... of course eliminates the warnings -- but logically, you DO WANT A WARNING
when you should be declaring
const char* (and you forget const)
but LOGICALLY you don't want I warning when passing a string literal to a char*
parameter in a function.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/50645] old issue - deprecated conversion from string to char*
2011-10-07 0:11 [Bug c/50645] New: old issue - deprecated conversion from string to char* mike.c at rocketime dot com
2011-10-07 0:35 ` [Bug c/50645] " mike.c at rocketime dot com
@ 2011-10-07 0:38 ` pinskia at gcc dot gnu.org
2011-10-07 0:41 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-10-07 0:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50645
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-10-07 00:37:40 UTC ---
IIRC it was the C standard which declared it as deprecated.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/50645] old issue - deprecated conversion from string to char*
2011-10-07 0:11 [Bug c/50645] New: old issue - deprecated conversion from string to char* mike.c at rocketime dot com
2011-10-07 0:35 ` [Bug c/50645] " mike.c at rocketime dot com
2011-10-07 0:38 ` pinskia at gcc dot gnu.org
@ 2011-10-07 0:41 ` redi at gcc dot gnu.org
2011-10-07 0:44 ` redi at gcc dot gnu.org
2011-10-07 1:11 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2011-10-07 0:41 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50645
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-10-07 00:41:25 UTC ---
(In reply to comment #0)
>
> If I declare:
>
> const char *DowNames[] = {
> "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
> NULL
> };
>
> as just char* instead of const char*, YES I WOULD LIKE TO GET A WARNING.
So you want a warning if non-const pointers point to const data. Makes sense.
> HOWEVER, if I have a function:
>
> myfunction(char *buf) {}
>
> I'd like to be able to call it like this
>
> myfunction("hello world")
>
> ... WITH NO 'deprecated conversion from string to char*' WARNING
So you don't want a warning if a non-const pointer points to const data.
Huh? How is that different from the earlier case.
> because char* as a parameter should be able to take a string as an argument --
> this makes sense.
Why? If a function takes char* it means it can change the contents of the char
or chars at that address, why is a warning not appropriate if you call it with
an argument that might cause a runtime error if the function changes the data?
> It's annoying to have to cast (char*)"hello world" every place in code, as
> programmers always used to use, simply "hello world". (i know an option is to
> change the warning level -- but that has other issues.)
Or, if your function really doesn't change the data, you could always fix its
signature to be myfunction(const char*).
Or use C, instead of C++ (you do realise the warning you're complaining about
is a C++ warning, not a C one, right?)
> PLEASE UNDEPRECATE! (Keep things simple, keep backward compatibility, as the
> old-school way is often best, designed that way for simplicity!)
That conversion is deprecated by the C++ standard, GCC cannot un-deprecate it.
Talk to the C++ committee (who will tell you to stop living in the 1970s and
get over it, type safety is a good thing.)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/50645] old issue - deprecated conversion from string to char*
2011-10-07 0:11 [Bug c/50645] New: old issue - deprecated conversion from string to char* mike.c at rocketime dot com
` (2 preceding siblings ...)
2011-10-07 0:41 ` redi at gcc dot gnu.org
@ 2011-10-07 0:44 ` redi at gcc dot gnu.org
2011-10-07 1:11 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2011-10-07 0:44 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50645
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-10-07 00:44:12 UTC ---
(In reply to comment #1)
> but LOGICALLY you don't want I warning when passing a string literal to a char*
> parameter in a function.
Yes you do. A string literal is immutable. A function taking a non-const char*
implies it might modify the characters pointed to. Modifying immutable data is
bad, mmmkay?
If your function won't change the data, change its signature to const char*.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c/50645] old issue - deprecated conversion from string to char*
2011-10-07 0:11 [Bug c/50645] New: old issue - deprecated conversion from string to char* mike.c at rocketime dot com
` (3 preceding siblings ...)
2011-10-07 0:44 ` redi at gcc dot gnu.org
@ 2011-10-07 1:11 ` redi at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2011-10-07 1:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50645
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |WAITING
Last reconfirmed| |2011-10-07
Ever Confirmed|0 |1
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-10-07 01:10:45 UTC ---
two points:
1) the component for this bug should surely be c++, since the "deprecated
conversion" warning is only issued by the C++ front end, the C front end says
passing argument 1 of ‘myfunction’ discards ‘const’ qualifier from pointer
target type
and even then, only with -Wwrite-strings, which is not enabled by -Wall -Wextra
2) unlike the PR's summary, the warning says "deprecated conversion from string
CONSTANT to 'char*'" (emphasis mine) which should be a pretty big clue that
it's warning you about a real problem.
I can't see any good reason this PR isn't INVALID, but will go for WAITING in
case you have a better case to make for changing the current behaviour, which
is entirely consistent with the C++ standard.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-10-07 1:11 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-07 0:11 [Bug c/50645] New: old issue - deprecated conversion from string to char* mike.c at rocketime dot com
2011-10-07 0:35 ` [Bug c/50645] " mike.c at rocketime dot com
2011-10-07 0:38 ` pinskia at gcc dot gnu.org
2011-10-07 0:41 ` redi at gcc dot gnu.org
2011-10-07 0:44 ` redi at gcc dot gnu.org
2011-10-07 1:11 ` redi at gcc dot gnu.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).