Re: deprecated conversion from string constant to 'char *'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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
-- 
       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@xxxxxxx                        PGP key available

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux