1

I’ve been wondering for the past few days whether it’s possible to make g++ and clang++ more pedantic than with -std=c++11 -w -pedantic.

Especially, I’d like these behaviors:

  • when replacing a virtual method, g++ and clang++ have to raise an error if the override keyword is not present in the prototype of the replaced method (I think it’s a warning for now);
  • all methods must have exception hint (noexcept or whatever), because it’s quite important, especially for ctor / dtor;
  • I’m also looking for any other pedantic features you’d have in mind.
Deduplicator
  • 41,806
  • 6
  • 61
  • 104
phaazon
  • 1,932
  • 14
  • 20
  • For the first bullet point, isn't that just a matter of using `-Werror` to convert warnings into errors? – Oliver Charlesworth Jun 25 '13 at 07:50
  • it is, but it’s too general: it applies to all warnings. It’s a way to do it yeah but I’d like something more precise. – phaazon Jun 25 '13 at 07:51
  • 1
    I believe you can use `-Werror=...` to convert specific warnings (although I don't know which warning missing overrides corresponds to, try perusing http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options). But why *wouldn't* you want all warnings as errors? – Oliver Charlesworth Jun 25 '13 at 07:53
  • 3
    because some warnings are not worth to be considered as errors imho, like the one that mentions unused variables – phaazon Jun 25 '13 at 07:56
  • `noexcept` isn't as important as you seem to think. – R. Martinho Fernandes Jun 25 '13 at 09:51
  • Well I think it should be used because calling a function in a dtor that throws exception is error-prone – phaazon Jun 25 '13 at 10:04
  • @phaazon: The thing is, with `noexcept` the function can still throw an exception, the compiler just guarantees that your program will be killed if it happens. It's a runtime check, not a compile time one. – sth Jul 10 '14 at 23:48

1 Answers1

1
$ g++ -Wall -Wextra -Werror -pedantic-errors
Andrew Tomazos
  • 58,923
  • 32
  • 156
  • 267