This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/32934] New: No warning when creating a non const derived funtion from a const virtual funciton
- From: "CyrusOmega at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Jul 2007 01:48:15 -0000
- Subject: [Bug c++/32934] New: No warning when creating a non const derived funtion from a const virtual funciton
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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