From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 37742 invoked by alias); 26 Nov 2015 14:44:48 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 37674 invoked by uid 89); 26 Nov 2015 14:44:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 26 Nov 2015 14:44:44 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id E0B0168E18; Thu, 26 Nov 2015 14:44:42 +0000 (UTC) Received: from localhost (ovpn-116-120.ams2.redhat.com [10.36.116.120]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tAQEig1G019468; Thu, 26 Nov 2015 09:44:42 -0500 Date: Thu, 26 Nov 2015 14:50:00 -0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org Cc: gcc-patches@gcc.gnu.org Subject: Improving the cxx0x_warning.h diagnostic Message-ID: <20151126144441.GP11200@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.5.24 (2015-08-30) X-SW-Source: 2015-11/txt/msg03248.txt.bz2 We have lots of headers that do this: #if __cplusplus < 201103L # include #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?