Hi,
since Manuel's patch http://gcc.gnu.org/ml/gcc-patches/2008-02/msg00962.html
a lot of C++ code is now accepted on mainline (when compiling without
special flags like -fpermissive and -pedantic), that used to be rejected.
Instead of getting closer to the standard we get away from it, which is a
bad idea IMHO - especially since the standard should be widely adopted by
now, given that it's about 10 years old. So here's a collection of some
warnings that I'd rather see as errors:
* Scopes in for-loops:
void foo()
{
for (int i=0; i<10; ++i) {}
i = 0;
}
warn.cc: In function 'void foo()':
warn.cc:4: warning: name lookup of 'i' changed for new ISO 'for' scoping
warn.cc:3: warning: using obsolete binding at 'i'
Btw, because the compiler tries to be smart to track new scoping and old
scoping at once it rejects valid code, accepts invalid code and even
generates wrong code in some cases (see PR10852).
* Declaration with no type:
foo() {}
warn.cc:1: warning: ISO C++ forbids declaration of 'foo' with no type
Or even worse IMHO:
struct A
{
i;
};
warn.cc:3: warning: ISO C++ forbids declaration of 'i' with no type
* Invalid use of 'template':
struct A
{
static void foo();
};
template<int> void bar()
{
A::template foo();
}
warn.cc: In function 'void bar()':
warn.cc:8: warning: 'A::foo()' is not a template
Btw, I don't know why we should accept this even with -fpermissive.
* Using 'struct' for a union:
union A {};
struct A a;
warn.cc:2: warning: 'struct' tag used in naming 'union A'
* Static members of local classes:
void foo()
{
struct A
{
static int i;
};
}
warn.cc: In function 'void foo()':
warn.cc:5: warning: local class 'struct foo()::A' shall not have static data
member 'int foo()::A::i'
* Return without value:
int foo()
{
return;
}
warn.cc: In function 'int foo()':
warn.cc:1: warning: return-statement with no value, in function returning
'int'
* Definition in wrong namespace:
struct A
{
void foo();
};
namespace N
{
void A::foo() {}
}
warn.cc:8: warning: definition of 'void A::foo()' is not in namespace
enclosing 'A'
* Operator new:
struct A
{
void* operator new(char);
};
warn.cc:3: warning: 'operator new' takes type 'size_t' ('unsigned int') as
first parameter
* Sizeof for function types:
void foo() { sizeof(foo); }
warn.cc: In member function 'void A::foo()':
warn.cc:1: warning: ISO C++ forbids applying 'sizeof' to an expression of
function type
What do you think?
Regards,
Volker