Subject: Is -Werror=pedantic necessary?

From: Christopher James Halse Rogers <[email-masked]>
Date: Fri, 15 Nov 2013 10:14:19 +1100

Hey all,

Just a quick one, but one that might generate lots of discussion: should
we be building with -Werror=pedantic? What does this buy us?

It *costs* us things like C99 designated-initialisers, which are nice.

As far as I can tell from the gcc manpage, -pedantic doesn't produce
errors for code where it's likely that the behaviour intended by the
programmer doesn't match the actual behaviour (ie: it doesn't seem like
it will help catch coding errors). -pedantic *explicitly* doesn't
provide a guarantee that code that builds with -pedantic set will build
on another ISO C++-compliant compiler, and we already get most of that
benefit by building with clang anyway.

This message brought to you by my latest build failing again because of
the use of C99 designated-initialisers where they're obviously
appropriate.

(If it turns out that we do get value from -Werror=pedantic; great! I
can refer back to the message next time I get annoyed at not being able
to use sensible features ☺).

Chris

---

From: Daniel van Vugt <[email-masked]>
Date: Fri, 15 Nov 2013 09:39:20 +0800

I would prefer to keep pedantic mode. Issues like using C99 
designated-initializers in C++ are actually compliance issues you should 
be told about. It's nice to know when you're no longer using the 
language standard you told the compiler you would use.

If you need to include other peoples' code which use non-compliant 
language features then why not just:

    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-pedantic"
    #include <noncompliant.h>
    #pragma GCC diagnostic pop

or localize the removal of pedantic (like we already do):

    string(REPLACE "-pedantic" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})

---

From: Christopher James Halse Rogers <[email-masked]>
Date: Fri, 15 Nov 2013 15:17:18 +1100

> language standard you told the compiler you would use.

This is what I'm asking - is it really? Especially given that using
-pedantic does *not* guarantee you're using the language standard you
told the compiler you would use anyway. 

The standard is useful to not tie you into a single compiler, but it's
not like any sensible compiler is going to support C++11 but *not* C99,
and our clang builds already guarantee that we're not tied into a single
compiler.

> language features then why not just:

It's not that I want to use other peoples' non-compliant code. It's that
*I* want to write non-compliant code. Or, rather, I want to write code
that I know all non-stupid compilers are going to interpret correctly,
but isn't strictly in the C++11 spec.

---

From: Daniel van Vugt <[email-masked]>
Date: Fri, 15 Nov 2013 12:44:24 +0800

Unfortunately C99 is not a subset of C++11. They're very different 
things. So to assume your compiler needs to support both simultaneously 
is a danger to portability.

Portability to other platforms is nice-to-have for Mir. But also within 
Linux, static analysis tools (and compilers) will typically only handle 
strong enforcement of one language spec at a time.

I would prefer we kept strong enforcement of a standard, any standard, 
rather than relaxing the rules and making Mir less portable.

"Strong" doesn't guarantee compliance, like you say. But it's better 
than weak.