In <bo**********@chessie.cirr.com> Christopher Benson-Manica <at***@nospam.cyberspace.org> writes:
LBJ <lb****@yahoo.com> spoke thus:
/usr/bin/gcc -Wall -W -O2 -ansi -pedantic test.c
gives no messages whatsoever.
my mistake, i think gcc is the c compiler and g++ is the c++
compiler. but try to compile it with gcc again, except with the
-Wcast-qual option.
/usr/bin/gcc -Wall -W -O2 -ansi -pedantic -Wcast-qual still says nothing.
The compiler version is 3.3.1. I'm still waiting for someone authoritative to
state whether OP's observed behavior is legit or not... If it is, why is gcc
apparently allowed not to generate a diagnostic (without making it jump
through obscure command-line option hoops, at least)?
It would have helped if you left the original code in place:
const int* pData; //pointer to read only data
int* const pData2; //read only pointer
pData = pData2;
The relevant part of the standard (6.5.16.1p1 Simple assignment) is:
- both operands are pointers to qualified or unqualified versions
of compatible types, and the type pointed to by the left has
all the qualifiers of the type pointed to by the right;
The type pointed to by the left operand is const int and the type pointed
to by the right operand is plain int. Therefore, the above quoted
constraint is satisfied and no diagnostic is *required*. Otherwise,
the *only* options needed by gcc to emit the diagnostic would be
-ansi -pedantic.
OTOH, a compiler is free to diagnose anything it wants, including
perfectly legit code, so the compiler generating the misleading
diagnostic is still conforming, if the diagnostic has "warning" status
(i.e. the file is still correctly translated).
That's one of the most convoluted parts of the standard and there is no
wonder if some implementor didn't get it right.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email:
Da*****@ifh.de