Missing warning (gcc version 2.97 20010122)

Martin Sebor sebor@roguewave.com
Mon Feb 5 14:28:00 GMT 2001


Carlo Wood wrote:
> 
> Perhaps I should have posted this to gcc@, but well - *I* think
> that a warning is missing here ;).
> 
> The following code example:
> 
> class A {
> public:
>   int f(void);
> };
> 
> namespace N {
> 
>   int i = 0;
> 
>   int A::f(void)
>   {
>     return i;           // line 12
>   }
> 
> }
> 
> gives as error:
> 
> test.cc: In member function `int A::f()':
> test.cc:12: `i' undeclared (first use this function)
> 
> The reason for this might be obvious in this small test case, but it
> is not in a large application.  Therefore I suggest to add this
> warning:
> 
> test.cc:10: warning: class A is not defined in namespace N

Not only that, it should be an error, since it violates 9.3, p2: "... A member
function
definition that appears outside of the class definition shall appear in a
namespace scope enclosing the class definition. ..."

Regards
Martin


More information about the Gcc-bugs mailing list