Date: Sat, 2 May 2026 12:18:49 +0200
On 02/05/2026 07:50, Nate Eldredge via Std-Discussion wrote:
> Historically, GCC has always preferred to behave by default as a compiler for the "extended" GNU dialects of C or C++ respectively. This situation is much older than C++11. As far back as GCC 1.21 circa 1988, GCC provided extensions (including zero-length arrays) that were not in the forthcoming initial C standard (ANSI C / C89), and enabled them by default. Clearly Stallman felt that his extensions made for a better language than the one defined by the standard, and wanted to encourage the use of his "GNU C" dialect. He did include the `-pedantic` option to revert to plain ANSI C, but the slightly derogatory name suggests that he didn't really encourage its use. These extensions, and others, eventually carried over into C++, so that now GCC by default is a compiler for the "GNU C++" dialect (which still includes zero-length arrays), and not for ISO C++.
>
> I don't know whether today's GCC team has similar strong feelings about the GNU dialect's superiority, or if the "GNU dialect by default" behavior just remains for compatibility.
>
> But in any case, the fact remains that `g++ foo.cc` does NOT invoke a compiler of the ISO C++ language, and no official documentation claims that it does. And `g++ -std=c++23 foo.cc` is not quite doing so either; it follows ISO C++ more closely, but still allows GNU extensions where they're not in direct conflict with ISO C++. (Here "direct conflict" wouldn't simply be "ISO C++ forbids it", but rather "ISO C++ allows this but defines it as doing something else".) So indeed, to get something that really purports to be an ISO C++ compiler, issuing all diagnostics required by the standard, you need `g++ -std=c++23 -pedantic`.
>
> I agree that this fact is not well known by new users, and one could wish that GCC would advertise it more prominently, but the ISO committee has no say in that.
>
Modern GCC still defaults to the "gnu++??" or "gnu??" extensions of the
C++ or C standards (where ?? refers to the standards edition - newer gcc
versions use newer standards editions by default). But the number of
new language extensions in gcc has decreased dramatically since the
early days. The GCC developers prefer to work with the standards
committees to add new features to the language itself, rather than as a
GCC extension. Outside that, they prefer to use [[ ]] or __attribute__
syntax and __builtin_ functions as common ways to extend the language.
One thing they typically do, however, is allow some new features from
later standards to be used in code compiled to older standards - even
with "-std=c++17", or whatever, explicitly specified. Some features
from C are allowed in C++, and vice versa. Obviously this is limited to
features that do not conflict with otherwise valid code in the stated
standard.
This means that if you want gcc to get as close as it can (modulo bugs,
misinterpretations and missing features) to being a conforming, say,
C++17 compiler, you need to use "-std=c++17 -Werror=pedantic". I
recommend "-Werror=pedantic" rather than just "-Wpedantic", as warnings
can be ignored by users.
IMHO it would be better if that was the default treatment of
"-std=c++17". If you want to write basically C++17 with some newer
C++23 syntax as extensions, then it seems appropriate to choose
"-std=gnu++17". And it would be nice if the defaults were to use real
standards rather than the gnu extended standards. (I personally make
use of some of the -std=gnu?? and -std=gnu++?? extensions, but that's an
active choice.)
But as a system compiler and such a widespread tool, GCC is bound by
backwards compatibility, regardless of the GCC developers' opinions on
such things. (And I do not know their opinions here - I am a gcc user,
not a gcc developer.)
> Historically, GCC has always preferred to behave by default as a compiler for the "extended" GNU dialects of C or C++ respectively. This situation is much older than C++11. As far back as GCC 1.21 circa 1988, GCC provided extensions (including zero-length arrays) that were not in the forthcoming initial C standard (ANSI C / C89), and enabled them by default. Clearly Stallman felt that his extensions made for a better language than the one defined by the standard, and wanted to encourage the use of his "GNU C" dialect. He did include the `-pedantic` option to revert to plain ANSI C, but the slightly derogatory name suggests that he didn't really encourage its use. These extensions, and others, eventually carried over into C++, so that now GCC by default is a compiler for the "GNU C++" dialect (which still includes zero-length arrays), and not for ISO C++.
>
> I don't know whether today's GCC team has similar strong feelings about the GNU dialect's superiority, or if the "GNU dialect by default" behavior just remains for compatibility.
>
> But in any case, the fact remains that `g++ foo.cc` does NOT invoke a compiler of the ISO C++ language, and no official documentation claims that it does. And `g++ -std=c++23 foo.cc` is not quite doing so either; it follows ISO C++ more closely, but still allows GNU extensions where they're not in direct conflict with ISO C++. (Here "direct conflict" wouldn't simply be "ISO C++ forbids it", but rather "ISO C++ allows this but defines it as doing something else".) So indeed, to get something that really purports to be an ISO C++ compiler, issuing all diagnostics required by the standard, you need `g++ -std=c++23 -pedantic`.
>
> I agree that this fact is not well known by new users, and one could wish that GCC would advertise it more prominently, but the ISO committee has no say in that.
>
Modern GCC still defaults to the "gnu++??" or "gnu??" extensions of the
C++ or C standards (where ?? refers to the standards edition - newer gcc
versions use newer standards editions by default). But the number of
new language extensions in gcc has decreased dramatically since the
early days. The GCC developers prefer to work with the standards
committees to add new features to the language itself, rather than as a
GCC extension. Outside that, they prefer to use [[ ]] or __attribute__
syntax and __builtin_ functions as common ways to extend the language.
One thing they typically do, however, is allow some new features from
later standards to be used in code compiled to older standards - even
with "-std=c++17", or whatever, explicitly specified. Some features
from C are allowed in C++, and vice versa. Obviously this is limited to
features that do not conflict with otherwise valid code in the stated
standard.
This means that if you want gcc to get as close as it can (modulo bugs,
misinterpretations and missing features) to being a conforming, say,
C++17 compiler, you need to use "-std=c++17 -Werror=pedantic". I
recommend "-Werror=pedantic" rather than just "-Wpedantic", as warnings
can be ignored by users.
IMHO it would be better if that was the default treatment of
"-std=c++17". If you want to write basically C++17 with some newer
C++23 syntax as extensions, then it seems appropriate to choose
"-std=gnu++17". And it would be nice if the defaults were to use real
standards rather than the gnu extended standards. (I personally make
use of some of the -std=gnu?? and -std=gnu++?? extensions, but that's an
active choice.)
But as a system compiler and such a widespread tool, GCC is bound by
backwards compatibility, regardless of the GCC developers' opinions on
such things. (And I do not know their opinions here - I am a gcc user,
not a gcc developer.)
Received on 2026-05-02 10:18:54
