This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the EGCS project.
inappropriate warning from const typedef
- To: <egcs-bugs@egcs.cygnus.com>
- Subject: inappropriate warning from const typedef
- From: "Brian St. Pierre" <bstpierre@xiox.com>
- Date: Thu, 29 Jul 1999 15:10:10 -0400
Hi -
I see the following two warnings when compiling the attached cpp file (full
output is given):
gcc version egcs-2.91.57 19980901 (egcs-1.1 release)
c:\cygnus\cygwin-b20\H-i586-cygwin32\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\
cpp
.exe -lang-c++ -v -iprefix
c:\cygnus\cygwin-b20\H-i586-cygwin32\lib\gcc-lib\i586
-cygwin32\egcs-2.91.57\ -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__G
NUC_
MINOR__=91 -Di386 -D_WIN32 -DWINNT -D_X86_=1 -D__STDC__=1 -D__stdcall=__attr
ibut
e__((__stdcall__)) -D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__at
trib
ute__((x)) -D__i386__ -D_WIN32 -D__WINNT__ -D_X86_=1 -D__STDC__=1 -D__stdcal
l=__
attribute__((__stdcall__)) -D__cdecl=__attribute__((__cdecl__)) -D__declspec
(x)=
__attribute__((x)) -D__i386 -D__WINNT -Asystem(winnt) -Acpu(i386) -Amachine(
i386
) -D__EXCEPTIONS -remap -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386
__ -
Di586 -Dpentium -D__i586 -D__i586__ -D__pentium -D__pentium__ -D__CYGWIN32__
-D_
_CYGWIN__ const-cpp.cpp const-cpp.ii
GNU CPP version egcs-2.91.57 19980901 (egcs-1.1 release) (80386, BSD syntax)
#include "..." search starts here:
#include <...> search starts here:
c:\cygnus\cygwin-b20\H-i586-cygwin32\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\
..\
..\..\..\..\include\g++
c:\cygnus\cygwin-b20\H-i586-cygwin32\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\
..\
..\..\..\..\include
c:\cygnus\cygwin-b20\H-i586-cygwin32\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\
..\
..\..\..\i586-cygwin32\include
c:\cygnus\cygwin-b20\H-i586-cygwin32\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\
inc
lude
\cygnus\cygwin-b20\H-i586-cygwin32\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..
\..
\..\..\..\include\g++
\cygnus\cygwin-b20\H-i586-cygwin32\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..
\..
\..\..\..\include
\cygnus\cygwin-b20\H-i586-cygwin32\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\..
\..
\..\..\i586-cygwin32\include
\cygnus\cygwin-b20\H-i586-cygwin32\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\in
clu
de
End of search list.
c:\cygnus\cygwin-b20\H-i586-cygwin32\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\
cc1
plus.exe const-cpp.ii -quiet -dumpbase const-cpp.cc -version -o const-cpp.s
GNU C++ version egcs-2.91.57 19980901 (egcs-1.1 release) (i586-cygwin32)
compile
d by GNU C version egcs-2.91.57 19980901 (egcs-1.1 release).
const-cpp.cpp: In function `int compare2(const char *, const char *)':
const-cpp.cpp:22: warning: passing `const char *' as argument 1 of
`isSame2(char
*, char *)' discards const
const-cpp.cpp:22: warning: passing `const char *' as argument 2 of
`isSame2(char
*, char *)' discards const
c:\cygnus\cygwin-b20\H-i586-cygwin32\lib\gcc-lib\i586-cygwin32\egcs-2.91.57\
..\
..\..\..\i586-cygwin32\bin\as.exe -o objconst-cpp.o const-cpp.s
The warnings are inappropriate because isSame2() accepts constString2 args,
which is typedef-ed to be 'const'. The warnings go away if a second
(redundant) const is inserted into the prototype (see the third case).
This only happens with C++ code, not with C. This is a stock cygnus dist
running on WinNT. The attached file is as stripped down as I could get,
including a workaround (the third case). This also occurs when running egcs
on WinNT, cross-compiling for MIPS (--version gives: egcs-2.91.66 here too).
I haven't bothered attaching output for this -- hopefully it won't be
necessary.
I hope this is sufficient info. Let me know if you need to know more. (I
realize this is probably --understandably -- low priority...)
Thank you.
-Brian St. Pierre
bstpierre@xiox.com
Attachments:
const-cpp.cpp - test file to provide the warning
build.sh - gives the command line that I'm using
const-cpp.ii - preprocessor output
const-cpp.s - compiler assembly output
const-cpp.cpp
const-cpp.ii
const-cpp.s
build.sh