diff mbox

Fix PR bootstrap/51705

Message ID 20111230193141.GA54761@troutmask.apl.washington.edu
State New
Headers show

Commit Message

Steve Kargl Dec. 30, 2011, 7:31 p.m. UTC
On Fri, Dec 30, 2011 at 10:38:03AM +0100, Jakub Jelinek wrote:
> On Thu, Dec 29, 2011 at 08:12:51PM -0800, Steve Kargl wrote:
> > The audit trail in the PR pretty much sums up the problem.
> > OK to commit?
> 
> Can you tune up the comments a little bit?
> If you look up http://gcc.gnu.org/gcc-4.7/cxx0x_status.html
> you'll see that most of the C++11 features are already implemented
> (and e.g. at_quick_exit is implemented too in some libcs), so the
> __cplusplus macro isn't lying.  Clang apparently defines __cplusplus
> to 201103L much longer than GCC does, yet it supports much smaller subset
> of C++11.  Apparently it parses the C++11 generalized attribute syntax,
> but at least clang 3.0 doesn't complain at all about anything between
> the [[ and ]] pair, [[foobar, foobaz (bar, baz, 2, 6, 0x1z2)]] void bar (void);
> is parsed just fine, and with [[noreturn]] it miscompiles even the first
> [[noreturn]] trivial testcase I wrote.
> See
> http://gcc.gnu.org/ml/gcc-patches/2011-10/msg02027.html
> for why we set __cplusplus to the value we do.

I'm sorry, but I find "clang did this, so g++ better follow
suit" to be a rather uncompelling technical reason for 
defining __cplusplus to be 201103L [1].  The technical question
is fairly simple: "Does g++ conform to the C++11 standard?"
From my cursory scanning of n3242.pdf, the answer is obviously
'no' given that [[noreturn]] appears to be neither a 
conditionally-supported feature nor implementation-defined
behavior.  So, we now look at what n3242.pdf says about
__cplusplus:

Sec. 16.8 (p. 415)
 __cplusplus
   The name __cplusplus is defined to the value 201103L when compiling
   a C++ translation unit. [155]

155) It is intended that future versions of this standard will replace
the value of this macro with a greater value.  Non-conforming compilers
should use a value with at most five decimal digits.

201103 is 6 digits!

Again, a cursory scan of n3242.pdf does not reveal whether a footnote
is normative or non-normative text.  So, footnote [155] may simply
be a suggestion rather than a requirement.

[1] Interestly, in a 1334 page document, n3242.pdf does not state
how one is to interpret __cplusplus nor its value.

So, once again OK for trunk?

2011-12-29  Steven G. Kargl  <kargl@gcc.gnu.org>

	* inclhack.def: 'g++ -std=c++11' defines __cplusplus to 201103L,
	which suggests that 'g++ -std=c++11' is a compiler conforming
	to the C++ programming language defined by ISO/IEC 14882:2011.
	Setting __cplusplus to 201103L appears to be a direct violation
	of ISO/IEC 14882:2011.  The standard conforming sys/cdefs.h
	header file on FreeBSD 10 (and above) needs be (un)damaged, so
	GCC can use 'g++ -std=c++11' to build libstdc++v3 during bootstrap.
	* fixincl.x: Regenerated.
	* genfixes: Fix to version test.

Comments

Joseph Myers Dec. 30, 2011, 10:36 p.m. UTC | #1
On Fri, 30 Dec 2011, Steve Kargl wrote:

> I'm sorry, but I find "clang did this, so g++ better follow
> suit" to be a rather uncompelling technical reason for 
> defining __cplusplus to be 201103L [1].  The technical question
> is fairly simple: "Does g++ conform to the C++11 standard?"

I think this is just the same issue as where trouble.texi says:

    Sometimes people say that defining @code{__STDC__} in a compiler that
    does not completely conform to the ISO C standard somehow violates the
    standard.  This is illogical.  The standard is a standard for compilers
    that claim to support ISO C, such as @samp{gcc -ansi}---not for other
    compilers such as plain @command{gcc}.  Whatever the ISO C standard says
    is relevant to the design of plain @command{gcc} without @option{-ansi} only
    for pragmatic reasons, not as a requirement.

Note that -std=c++11 is documented to be incomplete, not to claim to 
support the full standard.  I think the most pragmatically useful value of 
__cplusplus is to reflect the intent - the C++ version followed insofar as 
differences between versions are implemented - and this does not mean the 
support is complete, just as __STDC_VERSION__ had the C99 value with 
-std=c99 even in versions predating the implementation of C99 inline 
semantics (for example).
diff mbox

Patch

Index: inclhack.def
===================================================================
--- inclhack.def	(revision 182738)
+++ inclhack.def	(working copy)
@@ -20,6 +20,27 @@  autogen definitions fixincl;
 FIXINC_DEBUG = yes;
 #endif
 
+/*
+ * 'g++ -std=c++11' defines __cplusplus to 201103L, which suggests
+ * that 'g++ -std=c++11' is a compiler conforming to the C++ programming
+ * language defined by ISO/IEC 14882:2011.  Setting __cplusplus to 
+ * 201103L appears to be a direct violation of ISO/IEC 14882:2011
+ * [as inferred from Secs. 1.4 and 16.8 in n3242.pdf (I'm not interested
+ * in spending CHF 352.00 for the actual standard)].  The standard
+ * conforming sys/cdefs.h header file on FreeBSD 10 (and above) needs be
+ * (un)damaged, so GCC can use 'g++ -std=c++11' to build libstdc++v3 
+ * during bootstrap. 
+ */
+fix = {
+    hackname  = cdef_cplusplus;
+    mach      = "*-*-freebsd10.*";
+    files     = sys/cdefs.h;
+    select    = "\\[\\[noreturn\\]\\]";
+    sed       = "s/\\[\\[noreturn\\]\\]/__attribute__\(\(__noreturn__\)\)/";
+    test_text = "#include <sys/cdefs.h>";
+};
+
+
 /* On AIX when _LARGE_FILES is defined stdio.h defines fopen to
  * fopen64 etc. and this causes problems when building with g++
  * because cstdio udefs everything from stdio.h, leaving us with
Index: fixincl.x
===================================================================
--- fixincl.x	(revision 182738)
+++ fixincl.x	(working copy)
@@ -2,11 +2,11 @@ 
  * 
  * DO NOT EDIT THIS FILE   (fixincl.x)
  * 
- * It has been AutoGen-ed  November  7, 2011 at 01:16:39 PM by AutoGen 5.10
+ * It has been AutoGen-ed  December 30, 2011 at 11:21:34 AM by AutoGen 5.12
  * From the definitions    inclhack.def
  * and the template file   fixincl
  */
-/* DO NOT SVN-MERGE THIS FILE, EITHER Mon Nov  7 13:16:39 EST 2011
+/* DO NOT SVN-MERGE THIS FILE, EITHER Fri Dec 30 11:21:34 PST 2011
  *
  * You must regenerate it.  Use the ./genfixes script.
  *
@@ -15,7 +15,7 @@ 
  * certain ANSI-incompatible system header files which are fixed to work
  * correctly with ANSI C and placed in a directory that GNU C will search.
  *
- * This file contains 222 fixup descriptions.
+ * This file contains 223 fixup descriptions.
  *
  * See README for more information.
  *
@@ -43,6 +43,42 @@  static char const sed_cmd_z[] = SED_PROG
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * *
  *
+ *  Description of Cdef_Cplusplus fix
+ */
+tSCC zCdef_CplusplusName[] =
+     "cdef_cplusplus";
+
+/*
+ *  File name selection pattern
+ */
+tSCC zCdef_CplusplusList[] =
+  "sys/cdefs.h\0";
+/*
+ *  Machine/OS name selection pattern
+ */
+tSCC* apzCdef_CplusplusMachs[] = {
+        "*-*-freebsd10.*",
+        (const char*)NULL };
+
+/*
+ *  content selection pattern - do fix if pattern found
+ */
+tSCC zCdef_CplusplusSelect0[] =
+       "\\[\\[noreturn\\]\\]";
+
+#define    CDEF_CPLUSPLUS_TEST_CT  1
+static tTestDesc aCdef_CplusplusTests[] = {
+  { TT_EGREP,    zCdef_CplusplusSelect0, (regex_t*)NULL }, };
+
+/*
+ *  Fix Command Arguments for Cdef_Cplusplus
+ */
+static const char* apzCdef_CplusplusPatch[] = { sed_cmd_z,
+    "-e", "s/\\[\\[noreturn\\]\\]/__attribute__((__noreturn__))/",
+    (char*)NULL };
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * *
+ *
  *  Description of Aab_Aix_Stdio fix
  */
 tSCC zAab_Aix_StdioName[] =
@@ -9034,14 +9070,15 @@  static const char* apzX11_SprintfPatch[]
  *
  *  List of all fixes
  */
-#define REGEX_COUNT          264
+#define REGEX_COUNT          265
 #define MACH_LIST_SIZE_LIMIT 181
-#define FIX_COUNT            222
+#define FIX_COUNT            223
 
 /*
  *  Enumerate the fixes
  */
 typedef enum {
+    CDEF_CPLUSPLUS_FIXIDX,
     AAB_AIX_STDIO_FIXIDX,
     AAB_DARWIN7_9_LONG_DOUBLE_FUNCS_FIXIDX,
     AAB_DARWIN7_9_LONG_DOUBLE_FUNCS_2_FIXIDX,
@@ -9267,6 +9304,11 @@  typedef enum {
 } t_fixinc_idx;
 
 tFixDesc fixDescList[ FIX_COUNT ] = {
+  {  zCdef_CplusplusName,    zCdef_CplusplusList,
+     apzCdef_CplusplusMachs,
+     CDEF_CPLUSPLUS_TEST_CT, FD_MACH_ONLY,
+     aCdef_CplusplusTests,   apzCdef_CplusplusPatch, 0 },
+
   {  zAab_Aix_StdioName,    zAab_Aix_StdioList,
      apzAab_Aix_StdioMachs,
      AAB_AIX_STDIO_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
Index: genfixes
===================================================================
--- genfixes	(revision 182738)
+++ genfixes	(working copy)
@@ -62,7 +62,7 @@  fi
 AG="autogen $AG"
 set -e
 
-if [ -z "`${AG} -v | fgrep 'Ver. 5.'`" ]
+if [ -z "`${AG} -v | fgrep '5.'`" ]
 then
   echo "AutoGen appears to be out of date or not correctly installed."
   echo "Please download and install:"