This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Const-correctness broken for references to pointers.
- To: egcs-bugs at cygnus dot com
- Subject: Const-correctness broken for references to pointers.
- From: Hyman Rosen <hymie at prolifics dot com>
- Date: Tue, 7 Jul 1998 19:44:51 -0400
The compiler allows a reference to a pointer to constant to be initialized
by a pointer to non-constant. This allows const data to be changed, without
a peep from the compiler. Here's the test case:
/*----------------------------------------*/
extern "C" int printf(const char *, ...);
int main(int, char **)
{
volatile const int c = 42;
volatile int *p;
volatile const int *&r = p;
r = &c;
*p = 0;
if (c != 42)
printf("FAILED!\n");
}
/*----------------------------------------*/