[Bug c++/32934] No warning when creating a non const derived function from a const virtual function

2007-07-30 Thread CyrusOmega at gmail dot com


--- Comment #2 from CyrusOmega at gmail dot com  2007-07-30 12:04 ---
(In reply to comment #1)
> Well it is valid as B::print hides A::print.
> Try doing:
> #include 
> class A {
> public:
> virtual char * print() const { return "A\n";}
> virtual ~A(){};
> };
> class B : public A {
> public:
> virtual char * print() { return "B\n";}
> using A::print;
> virtual ~B(){};
> };
> 
> int main ()
> {
> B b;
> A & a = b;
> const B &b1 = b;
> std::cout << a.print() << b1.print();
> }
> 
> Which shows that b1.print will call A::print.  If you don't include using
> A::print, then A::print wil be hidden in B.
> 

The problem I am seeing is that I want to inherit from a virtual const function
but I don't want MY derived function to be const. Just because my parent class
thought the member should be const doesn't mean I agree, or am I simply
restricted? 

Thanks, and again I am sorry if this is simply a lack of my understanding of
C++.

Andrew


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32934



[Bug c++/32934] No warning when creating a non const derived function from a const virtual function

2007-07-31 Thread fang at csl dot cornell dot edu


--- Comment #3 from fang at csl dot cornell dot edu  2007-07-31 21:32 
---
Try compiling with -Woverloaded-virtual (C++ only).  That catches the situation
you describe.  (I don't think it's enabled by -Wall or -Wextra.)


-- 

fang at csl dot cornell dot edu changed:

   What|Removed |Added

 CC||fang at csl dot cornell dot
   ||edu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32934



[Bug c++/32934] No warning when creating a non const derived function from a const virtual function

2007-07-31 Thread CyrusOmega at gmail dot com


--- Comment #4 from CyrusOmega at gmail dot com  2007-07-31 21:41 ---
Subject: Re:  No warning when creating a non const derived function from a
const virtual function

Wow, thanks. I thought that -Wall was ALL warnings. grumble grumble...

Andrew

On 31 Jul 2007 21:32:32 -, fang at csl dot cornell dot edu
<[EMAIL PROTECTED]> wrote:
>
>
> --- Comment #3 from fang at csl dot cornell dot edu  2007-07-31 21:32 
> ---
> Try compiling with -Woverloaded-virtual (C++ only).  That catches the 
> situation
> you describe.  (I don't think it's enabled by -Wall or -Wextra.)
>
>
> --
>
> fang at csl dot cornell dot edu changed:
>
>What|Removed |Added
> 
>  CC||fang at csl dot cornell dot
>||edu
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32934
>
> --- You are receiving this mail because: ---
> You reported the bug, or are watching the reporter.
>


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32934



[Bug c++/32934] No warning when creating a non const derived function from a const virtual function

2007-07-31 Thread pinskia at gcc dot gnu dot org


--- Comment #5 from pinskia at gcc dot gnu dot org  2007-07-31 21:49 ---
http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Warning-Options.html
-Wall
All of the above `-W' options combined. This enables all the warnings about
constructions that some users consider questionable, and that are easy to avoid
(or modify to prevent the warning), even in conjunction with macros. This also
enables some language-specific warnings described in C++ Dialect Options and
Objective-C and Objective-C++ Dialect Options.

And:
http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/C_002b_002b-Dialect-Options.html
Under:
The following -W... options are not affected by -Wall. 


-Woverloaded-virtual (C++ only)
Warn when a function declaration hides virtual functions from a base class.
For example, in:

  struct A {
virtual void f();
  };

  struct B: public A {
void f(int);
  };


the A class version of f is hidden in B, and code like:

  B* b;
  b->f();


will fail to compile. 


-- 

pinskia at gcc dot gnu dot org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32934