public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* deprecated conversion from string constant to 'char *'
@ 2006-07-07  0:13 Timothy C Prince
  2006-07-07  0:27 ` Ian Lance Taylor
  0 siblings, 1 reply; 13+ messages in thread
From: Timothy C Prince @ 2006-07-07  0:13 UTC (permalink / raw)
  To: gcc-help

g++ 4.2 rejects a quoted string constant, where the function prototype has char *.  It says warning, but the warning is fatal, even without -Werror.  -fpermissive doesn't let it pass.

info g++ lists an option -fconst-strings, but that option has been removed.

What is expected as a replacement for current source code  with 1000's of string constants, which up to now worked with char * prototype?
Tim Prince

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

* Re: deprecated conversion from string constant to 'char *'
  2006-07-07  0:13 deprecated conversion from string constant to 'char *' Timothy C Prince
@ 2006-07-07  0:27 ` Ian Lance Taylor
  2006-07-07  1:52   ` Tim Prince
  2006-07-07  4:18   ` Tim Prince
  0 siblings, 2 replies; 13+ messages in thread
From: Ian Lance Taylor @ 2006-07-07  0:27 UTC (permalink / raw)
  To: Timothy C Prince; +Cc: gcc-help

"Timothy C Prince" <tprince@myrealbox.com> writes:

> g++ 4.2 rejects a quoted string constant, where the function prototype has char *.  It says warning, but the warning is fatal, even without -Werror.  -fpermissive doesn't let it pass.
> 
> info g++ lists an option -fconst-strings, but that option has been removed.
> 
> What is expected as a replacement for current source code  with 1000's of string constants, which up to now worked with char * prototype?

This is what I get:

> cat foo.cc
extern void foo(char*);
void bar() { foo("Hello"); }
> g++ -c foo.cc
foo.cc: In function ‘void bar()’:
foo.cc:2: warning: deprecated conversion from string constant to ‘char*’'
> echo $?
0

Looks like a warning to me, not an error.  Please give a small source
code example and the command line you are using.

Ian

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

* Re: deprecated conversion from string constant to 'char *'
  2006-07-07  0:27 ` Ian Lance Taylor
@ 2006-07-07  1:52   ` Tim Prince
  2006-07-07 14:22     ` Gabriel Dos Reis
  2006-07-07  4:18   ` Tim Prince
  1 sibling, 1 reply; 13+ messages in thread
From: Tim Prince @ 2006-07-07  1:52 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: Timothy C Prince, gcc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=EUC-JP, Size: 1766 bytes --]

Ian Lance Taylor wrote:
> "Timothy C Prince" <tprince@myrealbox.com> writes:
> 
>> g++ 4.2 rejects a quoted string constant, where the function prototype has char *.  It says warning, but the warning is fatal, even without -Werror.  -fpermissive doesn't let it pass.
>>
>> info g++ lists an option -fconst-strings, but that option has been removed.
>>
>> What is expected as a replacement for current source code  with 1000's of string constants, which up to now worked with char * prototype?
> 
> This is what I get:
> 
>> cat foo.cc
> extern void foo(char*);
> void bar() { foo("Hello"); }
>> g++ -c foo.cc
> foo.cc: In function ¡Ævoid bar()¡Ç:
> foo.cc:2: warning: deprecated conversion from string constant to ¡Æchar*¡Ç'
>> echo $?
> 0
> 
> Looks like a warning to me, not an error.  Please give a small source
> code example and the command line you are using.
> 
> Ian
> 
> 
I haven't figured out yet whether build is permitted to continue below
some small number of occurrences.  If it requires a large number to make
it fatal, that example would not be small.  In my case, no .o or a.out
is generated, either on ia64 or x86-64 linux.
A plurality of opinions I have gathered are in favor of allowing
constant strings under a prototype 'const char *', and allowing an
unlimited number of warnings, neither of which works with the current
g++ 4.2.  That, or providing a minimum example, begins to look like a
PR, which might delay indefinitely any resolution.
I must check also whether such a warning can be obtained from other
compilers.
I am more interested in finding out what the g++ developers' intentions
are, what way they want the code changed, since they seem to be well set
on not permitting old code to run with minimal modification.
Thanks.

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

* Re: deprecated conversion from string constant to 'char *'
  2006-07-07  0:27 ` Ian Lance Taylor
  2006-07-07  1:52   ` Tim Prince
@ 2006-07-07  4:18   ` Tim Prince
  2006-07-07 14:23     ` Gabriel Dos Reis
                       ` (2 more replies)
  1 sibling, 3 replies; 13+ messages in thread
From: Tim Prince @ 2006-07-07  4:18 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: Timothy C Prince, gcc-help

Ian Lance Taylor wrote:
> "Timothy C Prince" <tprince@myrealbox.com> writes:
> 
>> g++ 4.2 rejects a quoted string constant, where the function prototype has char *.  It says warning, but the warning is fatal, even without -Werror.  -fpermissive doesn't let it pass.
>>
>> info g++ lists an option -fconst-strings, but that option has been removed.
>>
>> What is expected as a replacement for current source code  with 1000's of string constants, which up to now worked with char * prototype?
> 
> This is what I get:
> 
>> cat foo.cc
> extern void foo(char*);
> void bar() { foo("Hello"); }
>> g++ -c foo.cc
> foo.cc: In function ‘void bar()’:
> foo.cc:2: warning: deprecated conversion from string constant to ‘char*’'
>> echo $?
> 0
> 
> Looks like a warning to me, not an error.  Please give a small source
> code example and the command line you are using.
> 
> Ian
> 
> 
Ian,
Even in your example, gcc stops without making a .o file.  I did find
that correcting __all__ the relevant prototypes to 'const char *' fixed
my problem.  I had missed one tucked away in a long list.
Another compiler which I use frequently, which claims a high degree of
gcc compatibility, is unable to produce any warning.

Thanks,
Tim

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

* Re: deprecated conversion from string constant to 'char *'
  2006-07-07  1:52   ` Tim Prince
@ 2006-07-07 14:22     ` Gabriel Dos Reis
  0 siblings, 0 replies; 13+ messages in thread
From: Gabriel Dos Reis @ 2006-07-07 14:22 UTC (permalink / raw)
  To: tprince; +Cc: Ian Lance Taylor, gcc-help

Tim Prince <timothyprince@sbcglobal.net> writes:

[...]

| I am more interested in finding out what the g++ developers' intentions
| are, what way they want the code changed, since they seem to be well set
| on not permitting old code to run with minimal modification.

I concur with Ian.

-- Gaby

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

* Re: deprecated conversion from string constant to 'char *'
  2006-07-07  4:18   ` Tim Prince
@ 2006-07-07 14:23     ` Gabriel Dos Reis
  2006-07-07 15:37     ` Ian Lance Taylor
  2007-02-06 21:20     ` Derek Atkins
  2 siblings, 0 replies; 13+ messages in thread
From: Gabriel Dos Reis @ 2006-07-07 14:23 UTC (permalink / raw)
  To: tprince; +Cc: Ian Lance Taylor, gcc-help

Tim Prince <timothyprince@sbcglobal.net> writes:

| Even in your example, gcc stops without making a .o file.  I did find
| that correcting __all__ the relevant prototypes to 'const char *' fixed
| my problem.  I had missed one tucked away in a long list.
| Another compiler which I use frequently, which claims a high degree of
| gcc compatibility, is unable to produce any warning.

Are you sure you're using FSF GCC?

-- Gaby

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

* Re: deprecated conversion from string constant to 'char *'
  2006-07-07  4:18   ` Tim Prince
  2006-07-07 14:23     ` Gabriel Dos Reis
@ 2006-07-07 15:37     ` Ian Lance Taylor
  2007-02-06 21:20     ` Derek Atkins
  2 siblings, 0 replies; 13+ messages in thread
From: Ian Lance Taylor @ 2006-07-07 15:37 UTC (permalink / raw)
  To: tprince; +Cc: gcc-help

Tim Prince <timothyprince@sbcglobal.net> writes:

> >> cat foo.cc
> > extern void foo(char*);
> > void bar() { foo("Hello"); }
> >> g++ -c foo.cc
> > foo.cc: In function ‘void bar()’:
> > foo.cc:2: warning: deprecated conversion from string constant to ‘char*’'
> >> echo $?
> > 0
> > Looks like a warning to me, not an error.  Please give a small source
> > code example and the command line you are using.
> > Ian
> >
> Ian,
> Even in your example, gcc stops without making a .o file.

No, it doesn't.  It creates a .o files as expected.

There is nothing we can do if you can not give us a test case and a
command line.  We believe that everything works fine: g++ issues a
warning and carries on.  I'm willing to believe that something else
happens for you, but without a clear test case we can not help you.

Also, which version of gcc are you using?  I'm testing current
mainline--i.e., not any released version.

Also, by the way, g++ does not does not change behaviour when it emits
more than some number of warnings.

Ian

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

* Re: deprecated conversion from string constant to 'char *'
  2006-07-07  4:18   ` Tim Prince
  2006-07-07 14:23     ` Gabriel Dos Reis
  2006-07-07 15:37     ` Ian Lance Taylor
@ 2007-02-06 21:20     ` Derek Atkins
  2007-02-06 22:59       ` Ian Lance Taylor
  2 siblings, 1 reply; 13+ messages in thread
From: Derek Atkins @ 2007-02-06 21:20 UTC (permalink / raw)
  To: gcc-help; +Cc: Ian Lance Taylor

[-- Attachment #1: Type: text/plain, Size: 1120 bytes --]

Here's a test-case for you.  Save the attached source file as
/tmp/test.cpp and run the following g++ invocation:

g++ -c -g -O0 -fno-strict-aliasing -Wall -W -Wno-format-y2k \
  -Wpointer-arith -Wwrite-strings -o /tmp/test.o /tmp/test.cpp

When I run this command against the attached file I get:

/tmp/test.cpp: In function ‘int do_test()’:
/tmp/test.cpp:14: warning: deprecated conversion from string constant to ‘char*’'

But if you look the argument IS a const, just through a typedef.
I'm using g++ 4.1.1-1 on FC5:

Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.1 20060525 (Red Hat 4.1.1-1)

-derek


[-- Attachment #2: test case showing erroneous warning --]
[-- Type: text/plain, Size: 396 bytes --]


typedef char* PDFFileName;
typedef const char* PDFFileNameConst;

class Foo
{
public:
  // If you change this to PDFFileNameConst then the warning goes away
  static int Blah(const PDFFileName name);
};

int do_test()
{
  return Foo::Blah("bzz");
}


// Compile with:
// g++ -c -g -O0 -fno-strict-aliasing -Wall -W -Wno-format-y2k
// -Wpointer-arith -Wwrite-strings -o /tmp/test.o /tmp/test.cpp

[-- Attachment #3: Type: text/plain, Size: 261 bytes --]


-- 
       Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
       Member, MIT Student Information Processing Board  (SIPB)
       URL: http://web.mit.edu/warlord/    PP-ASEL-IA     N1NWH
       warlord@MIT.EDU                        PGP key available

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

* Re: deprecated conversion from string constant to 'char *'
  2007-02-06 21:20     ` Derek Atkins
@ 2007-02-06 22:59       ` Ian Lance Taylor
  2007-02-06 23:10         ` Derek Atkins
  0 siblings, 1 reply; 13+ messages in thread
From: Ian Lance Taylor @ 2007-02-06 22:59 UTC (permalink / raw)
  To: Derek Atkins; +Cc: gcc-help

Derek Atkins <warlord@MIT.EDU> writes:

> typedef char* PDFFileName;
> typedef const char* PDFFileNameConst;
> 
> class Foo
> {
> public:
>   // If you change this to PDFFileNameConst then the warning goes away
>   static int Blah(const PDFFileName name);
> };
> 
> int do_test()
> {
>   return Foo::Blah("bzz");
> }

This is expected behaviour.  "const PDFFileName" is not "const char*",
it is "char* const".

Ian

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

* Re: deprecated conversion from string constant to 'char *'
  2007-02-06 22:59       ` Ian Lance Taylor
@ 2007-02-06 23:10         ` Derek Atkins
  0 siblings, 0 replies; 13+ messages in thread
From: Derek Atkins @ 2007-02-06 23:10 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-help

Quoting Ian Lance Taylor <iant@google.com>:

> Derek Atkins <warlord@MIT.EDU> writes:
>
>> typedef char* PDFFileName;
>> typedef const char* PDFFileNameConst;
>>
>> class Foo
>> {
>> public:
>>   // If you change this to PDFFileNameConst then the warning goes away
>>   static int Blah(const PDFFileName name);
>> };
>>
>> int do_test()
>> {
>>   return Foo::Blah("bzz");
>> }
>
> This is expected behaviour.  "const PDFFileName" is not "const char*",
> it is "char* const".

I certainly wouldn't call this "expected"..

But with the expanation I at least understand why it's happening.
I guess that means if you typedef there's no way to actually
get the "const char*", which perhaps is a bug in the language definition.

Regardless, it IS annoying.

> Ian

-derek

-- 
       Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
       Member, MIT Student Information Processing Board  (SIPB)
       URL: http://web.mit.edu/warlord/    PP-ASEL-IA     N1NWH
       warlord@MIT.EDU                        PGP key available

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

* Re: deprecated conversion from string constant to 'char *'
  2006-07-08  1:57   ` Tim Prince
@ 2006-07-08 15:57     ` Ian Lance Taylor
  0 siblings, 0 replies; 13+ messages in thread
From: Ian Lance Taylor @ 2006-07-08 15:57 UTC (permalink / raw)
  To: tprince; +Cc: gcc-help

Tim Prince <timothyprince@sbcglobal.net> writes:

> The example you made up is good enough.

Let me try this again.  In my example, in which I showed precisely
what commands I executed, the compiler worked as you want it to.  It
issued a warning, had an exit status of 0, and created an object file.

If you want gcc to be fixed, you need to show an example just like
mine: show the source code, show the command line, show the compiler
output, show the exit status, show whether there is a .o file.  That
is what I have been asking you to do.

Perhaps it would help if you read
    http://gcc.gnu.org/bugs.html

Ian

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

* Re: deprecated conversion from string constant to 'char *'
  2006-07-07 21:43 ` Ian Lance Taylor
@ 2006-07-08  1:57   ` Tim Prince
  2006-07-08 15:57     ` Ian Lance Taylor
  0 siblings, 1 reply; 13+ messages in thread
From: Tim Prince @ 2006-07-08  1:57 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: Timothy C Prince, gdr, gcc-help

Ian Lance Taylor wrote:
> "Timothy C Prince" <tprince@myrealbox.com> writes:
> 
>> gcc built from last Saturday's post on gcc.gnu.org/pub/gcc/snapshots
>>
>> I've seen remarks about that not being a reliable source for FSF gcc.  If those aren't good to use, why not offer something better?
> 
> That is a reliable source for FSF gcc snapshots.
> 
> Of course snapshots are just that: a snapshot of the development in
> progress.  They are not guaranteed to work.
> 
> We still can't help with you without a complete and exact description
> of precisely what you are doing.
> 
> Ian
> 
> 
Ian,
The example you made up is good enough.  As you can see from the 
follow-ups, replacing 'char *' by 'const char *' in your example, or 
(consistently throughout) in my own case, solve the problem.  The 
question remains whether g++ should abort the compilation when the 
legacy source code is discovered.  If it does abort, with no option to 
continue (as it does in my testing), should it be reported as Error 
rather than warning?  Should g++ -m32 produce a diagnostic similar to 
g++ -m64?

In case it's of interest, I've investigated the following compilers:

g++ 4.2 x86-64 reports "deprecated conversion" (and aborts) when const 
is omitted

g++ 4.2 -m32 x86-64, and Windows 32-bit, fail on a bunch of libstdc++ 
problems relative to char * conversions, when const is omitted

Intel icpc 9.1 linux x86-64 doesn't care whether const is present, no 
warning available (consistent with g++ 4.0.2 as base installation)
Intel ICL 9.1 Windows x64 has STL problems when const is omitted (unable 
to verify whether that corresponds to behavior of base MSVC++ installation)
MSVC 2003 toolkit 32-bit fails on excessive warnings without const, if 
-Wall is set, otherwise accepts either version

So, I'm satisfied that 'const char *' is the correct solution, and that 
no consistent treatment of legacy code (warning/abort/no warning/STL 
failure) can be expected of current compilers.

Thanks,
Tim

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

* Re: deprecated conversion from string constant to 'char *'
  2006-07-07 21:17 Timothy C Prince
@ 2006-07-07 21:43 ` Ian Lance Taylor
  2006-07-08  1:57   ` Tim Prince
  0 siblings, 1 reply; 13+ messages in thread
From: Ian Lance Taylor @ 2006-07-07 21:43 UTC (permalink / raw)
  To: Timothy C Prince; +Cc: gdr, gcc-help

"Timothy C Prince" <tprince@myrealbox.com> writes:

> gcc built from last Saturday's post on gcc.gnu.org/pub/gcc/snapshots
> 
> I've seen remarks about that not being a reliable source for FSF gcc.  If those aren't good to use, why not offer something better?

That is a reliable source for FSF gcc snapshots.

Of course snapshots are just that: a snapshot of the development in
progress.  They are not guaranteed to work.

We still can't help with you without a complete and exact description
of precisely what you are doing.

Ian

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

end of thread, other threads:[~2007-02-06 23:10 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-07  0:13 deprecated conversion from string constant to 'char *' Timothy C Prince
2006-07-07  0:27 ` Ian Lance Taylor
2006-07-07  1:52   ` Tim Prince
2006-07-07 14:22     ` Gabriel Dos Reis
2006-07-07  4:18   ` Tim Prince
2006-07-07 14:23     ` Gabriel Dos Reis
2006-07-07 15:37     ` Ian Lance Taylor
2007-02-06 21:20     ` Derek Atkins
2007-02-06 22:59       ` Ian Lance Taylor
2007-02-06 23:10         ` Derek Atkins
2006-07-07 21:17 Timothy C Prince
2006-07-07 21:43 ` Ian Lance Taylor
2006-07-08  1:57   ` Tim Prince
2006-07-08 15:57     ` Ian Lance Taylor

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).