diff mbox

Improving the cxx0x_warning.h diagnostic

Message ID 20151126144441.GP11200@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely Nov. 26, 2015, 2:44 p.m. UTC
We have lots of headers that do this:

#if __cplusplus < 201103L
# include <bits/c++0x_warning.h>
#else

and that file has a #error (not #warning as the name would suggest).

Unfortunately a #error does not stop compilation, so when users try to
compile C++11 source code (which includes standard headers) and they
don't use the right -std option, they are likely to get that #error
message, followed by a cascade of later errors due to the use of C++11
syntax or library types.

We could solve this!


When a header cannot be included we stop during preprocessing and
never even try to compile the C++11 code that follows , so the user
gets nothing more than:

In file included from /home/jwakely/gcc/6/include/c++/6.0.0/thread:35:0,
                 from th.cc:1:
/home/jwakely/gcc/6/include/c++/6.0.0/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for at least the ISO C++ 2011 standard, which must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for at least \
  ^~~~~

/home/jwakely/gcc/6/include/c++/6.0.0/bits/c++0x_warning.h:36:30: fatal error: __no_such_header__: No such file or directory
 #include <__no_such_header__>
                              ^

compilation terminated.


I'm not very happy with the __no_such_header__ part, but we could
bikeshed a better name. The point is that the compilation stops
immediately, and the last errors printed are the ones about using the
wrong -std option.

Is this a good idea?

Too late for 6.0?

Comments

Jonathan Wakely Nov. 27, 2015, 6:40 p.m. UTC | #1
On 27/11/15 12:53 -0500, NightStrike wrote:
>You could add a pragma that turns on -Wfatal-errors

That might be better, I'll try it, thanks.
diff mbox

Patch

--- a/libstdc++-v3/include/bits/c++0x_warning.h
+++ b/libstdc++-v3/include/bits/c++0x_warning.h
@@ -29,9 +29,11 @@ 
 #define _CXX0X_WARNING_H 1
 
 #if __cplusplus < 201103L
-#error This file requires compiler and library support for the \
-ISO C++ 2011 standard. This support is currently experimental, and must be \
-enabled with the -std=c++11 or -std=gnu++11 compiler options.
+#error This file requires compiler and library support for at least \
+the ISO C++ 2011 standard, which must be enabled with \
+the -std=c++11 or -std=gnu++11 compiler options.
+// Include a non-existent file to terminate compilation:
+#include <__no_such_header__>
 #endif
 
 #endif