public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ warnings vs. errors
@ 2008-06-11 14:12 Volker Reichelt
  2008-06-11 14:48 ` Ian Lance Taylor
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Volker Reichelt @ 2008-06-11 14:12 UTC (permalink / raw)
  To: gcc

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

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2008-06-21 11:13 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-11 14:12 C++ warnings vs. errors Volker Reichelt
2008-06-11 14:48 ` Ian Lance Taylor
2008-06-11 18:48   ` Manuel López-Ibáñez
2008-06-11 20:24 ` Joe Buck
2008-06-11 23:06 ` Jonathan Wakely
2008-06-13 19:48   ` Mark Mitchell
2008-06-13 21:20     ` Manuel López-Ibáñez
2008-06-15 23:06     ` Jonathan Wakely
2008-06-16  2:32       ` Mark Mitchell
2008-06-16 10:13       ` Manuel López-Ibáñez
2008-06-17 19:48   ` Jonathan Wakely
2008-06-19  0:27     ` Mark Mitchell
2008-06-19  8:17       ` Jonathan Wakely
2008-06-19 22:08       ` Jonathan Wakely
2008-06-19 22:21         ` Mark Mitchell
2008-06-20  7:26         ` Gabriel Dos Reis
2008-06-19 23:47       ` Jonathan Wakely
2008-06-20 10:29         ` Mark Mitchell
2008-06-21 11:13           ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).