Open Quuxplusone opened 5 years ago
Attached CMakeLists.txt
(152 bytes, text/plain): BUILD SCRIPT FOR MAIN.CPP
I filed a related bug on libc++ https://bugs.llvm.org/show_bug.cgi?id=40349
Clang has a number of extensions that are enabled by default, some for GCC
compatibility, some for compatibility with commonly-used code, and some merely
because we don't want to pedantically reject code where the intent is obvious
(especially for use of later-standards-mode features in earlier standards
modes). Most of those generate warnings by default, which is sufficient to meet
the standard's requirements for conformance ("shall issue at least one
diagnostic message").
You can request errors for all such extensions with the -pedantic-errors flag.
(The above is all true for GCC and ICC as well.)
> The way CMake interprets my request for EXTENSIONS OFF when targeting clang
is to insert -std=c++11
That is a CMake bug. EXTENSIONS OFF should pass -pedantic-errors (to turn off
extensions) in addition to a -std= flag, to all compilers with a GCC-compatible
driver interface.
> this is *still* a bug insofar as it is a documentation bug
Agreed. Our documentation here is very much lacking.
GCC documents this behavior here:
https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#index-std-1
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-pedantic-1
(As a general rule, Clang's GCC-compatible driver attempts to follow GCC's
behavior. But that is no excuse for our documentation not covering this.)
Thanks. I do intend to file a bug with CMake and I will refer your statements
in this bug when I do so… first though I want to test MSVC a little more
because I'm discovering they also appear to accept *some* C99 extensions in
C++11 mode, just not all of them. I have not yet located the documentation
explaining why D:
Can you confirm two things?
1. If I pass -pedantic-errors then -Werror=c99-extensions is not needed? -
pedantic-errors implies -Werror=c99-extensions, yes?
2. There are certain compiler-specific extensions which are "expected
extensions", that is, rather than being new language features per se they are
designated areas for conveying compiler-specific semantics. I am specifically
here thinking of __attribute__ and #pragma. Will using -pedantic-errors cut off
these features in Clang? (Looking at the description of -pedantic-errors in
https://clang.llvm.org/docs/UsersManual.html it appears the answer is "no", but
that sections seems to only specifically address C.)
One more thought. The -pedantic-errors section in UsersManual.html mentions
some C macros which are defined certain ways so that #ifdef et al can detect
features being on or off. It would be great if the current clang settings wrt
extensions (c99 extensions, all extensions, etc) were similarly detectable
using macro checks in C++ also. And of course it would be great if any such
macros were documented (if they weren't already).
> I want to test MSVC a little more because I'm discovering they also
> appear to accept *some* C99 extensions in C++11 mode
I believe the option corresponding to -pedantic-errors in MSVC is /permissive-
(https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=vs-2017)
> 1. If I pass -pedantic-errors then -Werror=c99-extensions is not needed?
> -pedantic-errors implies -Werror=c99-extensions, yes?
Yes.
> 2. Will using -pedantic-errors cut off these features in Clang?
No. Features hidden behind reserved identifiers and #pragma are unaffected (so,
for instance, you can still use "_Complex double" in C++ under -pedantic-
errors, etc).
> It would be great if the current clang settings wrt extensions (c99
extensions,
> all extensions, etc) were similarly detectable using macro checks in C++ also.
Some of them are, but many aren't. (For example, __has_extension(X) for X in
{c_alignas, c_alignof, c_atomic, c_generic_selections, c_static_assert,
c_thread_local} can be used to detect support for those C extensions in earlier
C dialects and in C++, and those respond appropriately to -pedantic-errors.)
Those extensions for which we provide such feature-test mechanisms are
documented here: https://clang.llvm.org/docs/LanguageExtensions.html#checks-for-
standard-language-features
CMakeLists.txt
(152 bytes, text/plain)