public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org
Cc: gcc-patches@gcc.gnu.org
Subject: Improving the cxx0x_warning.h diagnostic
Date: Thu, 26 Nov 2015 14:50:00 -0000	[thread overview]
Message-ID: <20151126144441.GP11200@redhat.com> (raw)

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!

--- 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

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?


             reply	other threads:[~2015-11-26 14:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-26 14:50 Jonathan Wakely [this message]
     [not found] ` <CAF1jjLte9e7nJx5o91s2DgcHzYkveHatMqmeSm404=4s+a0jMw@mail.gmail.com>
2015-11-27 18:55   ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151126144441.GP11200@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).