[Bug c++/32934] New: No warning when creating a non const derived funtion from a const virtual funciton
CyrusOmega at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Jul 30 01:48:00 GMT 2007
Maybe this isn't a bug, but I can't see why this shouldn't at least be a
warning since it changes the output of the program...
==============C++ Source with B.print not const====================
#include <iostream>
class A {
public:
virtual char * print() const { return "A\n";}
virtual ~A(){};
};
class B : public A {
public:
virtual char * print() { return "B\n";}
virtual ~B(){};
};
int main ()
{
B b;
A & a = b;
std::cout << a.print() << b.print();
}
aewhite@aewhite-laptop:~/working$ g++ -Wall -o gcc_bug gcc_bug.cpp
aewhite@aewhite-laptop:~/working$ ./gcc_bug
A
B
=================C++ Source with B.print const=================
#include <iostream>
class A {
public:
virtual char * print() const { return "A\n";}
virtual ~A(){};
};
class B : public A {
public:
virtual char * print() const { return "B\n";}
virtual ~B(){};
};
int main ()
{
B b;
A & a = b;
std::cout << a.print() << b.print();
}
aewhite@aewhite-laptop:~/working$ g++ -Wall -o gcc_bug gcc_bug.cpp
aewhite@aewhite-laptop:~/working$ ./gcc_bug
B
B
What am I missing?
Andrew
--
Summary: No warning when creating a non const derived funtion
from a const virtual funciton
Product: gcc
Version: 4.0.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: CyrusOmega at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32934
More information about the Gcc-bugs
mailing list