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();
}

[EMAIL PROTECTED]:~/working$ g++ -Wall -o gcc_bug gcc_bug.cpp
[EMAIL PROTECTED]:~/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();
}

[EMAIL PROTECTED]:~/working$ g++ -Wall -o gcc_bug gcc_bug.cpp
[EMAIL PROTECTED]:~/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

Reply via email to