This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Experimental C++0x mode


Hello all,

Last month, we discussed the introduction of an experimental
compilation mode for the upcoming C++0x standard. See, e.g.,

http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00031.html

This patch adds the flags -std=c++0x and -std=gnu++0x, which enable
C++0x mode (without and with GNU extensions, respectively). At
present, there are only two differences between C++0x mode and the
corresponding C++98 mode:

  - C++0x mode defines the macro __GXX_EXPERIMENTAL_CPP0X__
  - C++0x includes the C99 preprocessor changes

There are two patches included here: one for libcpp (so we use the
C99 preprocessor in C++0x mode) and one for the compiler and
documentation. When we get more significant additions to the C++0x
mode, we'll want to update the "Extensions to the C++ language" part
of the GCC manual.

Tested on i686-pc-linux-gnu; no new regressions.

Okay for mainline?

  Cheers,
  Doug

2006-11-01 Douglas Gregor <doug.gregor@gmail.com>

    * c-common.c (flag_cpp0x): New.
    * c-common.h (flag_cpp0x): New.
    * c-cppbuiltin.c (c_cpp_builtins): If C++0x extensions are
    supported, define __GXX_EXPERIMENTAL_CPP0X__.
    * c-opts.c (set_std_cxx0x): New.
    (c_common_handle_option): Handle -std=c++0x, -std=gnu++0x.
    * c.opt (std=c++0x): Document.
    (std=gnu++0x): Ditto.

2006-11-01 Douglas Gregor <doug.gregor@gmail.com>

    * include/cpplib.h (enum c_lang): Add CLK_GNUCXX0X and CLK_CXX0X
    for experimental C++0x mode.
    * init.c (lang_defaults): Add defaults for C++0x modes. C++0x has
    adopted the preprocessor changes introduced in C99.
Index: include/cpplib.h
===================================================================
--- include/cpplib.h	(revision 118379)
+++ include/cpplib.h	(working copy)
@@ -155,7 +155,7 @@ enum cpp_ttype
 
 /* C language kind, used when calling cpp_create_reader.  */
 enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_STDC89, CLK_STDC94, CLK_STDC99,
-	     CLK_GNUCXX, CLK_CXX98, CLK_ASM};
+	     CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX0X, CLK_CXX0X, CLK_ASM};
 
 /* Payload of a NUMBER, STRING, CHAR or COMMENT token.  */
 struct cpp_string GTY(())
Index: init.c
===================================================================
--- init.c	(revision 118379)
+++ init.c	(working copy)
@@ -80,18 +80,20 @@ struct lang_flags
 
 static const struct lang_flags lang_defaults[] =
 { /*              c99 c++ xnum xid std  //   digr  */
-  /* GNUC89 */  { 0,  0,  1,   0,  0,   1,   1     },
-  /* GNUC99 */  { 1,  0,  1,   0,  0,   1,   1     },
-  /* STDC89 */  { 0,  0,  0,   0,  1,   0,   0     },
-  /* STDC94 */  { 0,  0,  0,   0,  1,   0,   1     },
-  /* STDC99 */  { 1,  0,  1,   0,  1,   1,   1     },
-  /* GNUCXX */  { 0,  1,  1,   0,  0,   1,   1     },
-  /* CXX98  */  { 0,  1,  1,   0,  1,   1,   1     },
-  /* ASM    */  { 0,  0,  1,   0,  0,   1,   0     }
-  /* xid should be 1 for GNUC99, STDC99, GNUCXX and CXX98 when no
-     longer experimental (when all uses of identifiers in the compiler
-     have been audited for correct handling of extended
-     identifiers).  */
+  /* GNUC89   */  { 0,  0,  1,   0,  0,   1,   1     },
+  /* GNUC99   */  { 1,  0,  1,   0,  0,   1,   1     },
+  /* STDC89   */  { 0,  0,  0,   0,  1,   0,   0     },
+  /* STDC94   */  { 0,  0,  0,   0,  1,   0,   1     },
+  /* STDC99   */  { 1,  0,  1,   0,  1,   1,   1     },
+  /* GNUCXX   */  { 0,  1,  1,   0,  0,   1,   1     },
+  /* CXX98    */  { 0,  1,  1,   0,  1,   1,   1     },
+  /* GNUCXX0X */  { 1,  1,  1,   0,  0,   1,   1     },
+  /* CXX0X    */  { 1,  1,  1,   0,  1,   1,   1     },
+  /* ASM      */  { 0,  0,  1,   0,  0,   1,   0     }
+  /* xid should be 1 for GNUC99, STDC99, GNUCXX, CXX98, GNUCXX0X, and
+     CXX0X when no longer experimental (when all uses of identifiers
+     in the compiler have been audited for correct handling of
+     extended identifiers).  */
 };
 
 /* Sets internal flags correctly for a given language.  */
Index: c-common.c
===================================================================
--- c-common.c	(revision 118379)
+++ c-common.c	(working copy)
@@ -401,6 +401,11 @@ int flag_access_control = 1;
 
 int flag_check_new;
 
+/* Nonzero if we want to allow the use of experimental features that
+   are likely to become part of C++0x. */
+
+int flag_cpp0x = 0;
+
 /* Nonzero if we want the new ISO rules for pushing a new scope for `for'
    initialization variables.
    0: Old rules, set by -fno-for-scope.
Index: c-common.h
===================================================================
--- c-common.h	(revision 118379)
+++ c-common.h	(working copy)
@@ -521,6 +521,11 @@ extern int flag_access_control;
 
 extern int flag_check_new;
 
+/* Nonzero if we want to allow the use of experimental features that
+   are likely to become part of C++0x. */
+
+extern int flag_cpp0x;
+
 /* Nonzero if we want the new ISO rules for pushing a new scope for `for'
    initialization variables.
    0: Old rules, set by -fno-for-scope.
Index: c-cppbuiltin.c
===================================================================
--- c-cppbuiltin.c	(revision 118379)
+++ c-cppbuiltin.c	(working copy)
@@ -409,6 +409,8 @@ c_cpp_builtins (cpp_reader *pfile)
 	cpp_define (pfile, "__GXX_WEAK__=0");
       if (warn_deprecated)
 	cpp_define (pfile, "__DEPRECATED");
+      if (flag_cpp0x)
+        cpp_define (pfile, "__GXX_EXPERIMENTAL_CPP0X__");
     }
   /* Note that we define this for C as well, so that we know if
      __attribute__((cleanup)) will interface with EH.  */
Index: c-opts.c
===================================================================
--- c-opts.c	(revision 118379)
+++ c-opts.c	(working copy)
@@ -109,6 +109,7 @@ static size_t include_cursor;
 static void set_Wimplicit (int);
 static void handle_OPT_d (const char *);
 static void set_std_cxx98 (int);
+static void set_std_cxx0x (int);
 static void set_std_c89 (int, int);
 static void set_std_c99 (int);
 static void check_deps_environment_vars (void);
@@ -789,7 +790,7 @@ c_common_handle_option (size_t scode, co
     case OPT_fuse_cxa_atexit:
       flag_use_cxa_atexit = value;
       break;
-      
+
     case OPT_fuse_cxa_get_exception_ptr:
       flag_use_cxa_get_exception_ptr = value;
       break;
@@ -913,6 +914,12 @@ c_common_handle_option (size_t scode, co
 	set_std_cxx98 (code == OPT_std_c__98 /* ISO */);
       break;
 
+    case OPT_std_c__0x:
+    case OPT_std_gnu__0x:
+      if (!preprocessing_asm_p)
+	set_std_cxx0x (code == OPT_std_c__0x /* ISO */);
+      break;
+
     case OPT_std_c89:
     case OPT_std_iso9899_1990:
     case OPT_std_iso9899_199409:
@@ -1509,6 +1516,17 @@ set_std_cxx98 (int iso)
   flag_iso = iso;
 }
 
+/* Set the C++ 0x working draft "standard" (without GNU extensions if ISO).  */
+static void
+set_std_cxx0x (int iso)
+{
+  cpp_set_lang (parse_in, iso ? CLK_CXX0X: CLK_GNUCXX0X);
+  flag_no_gnu_keywords = iso;
+  flag_no_nonansi_builtin = iso;
+  flag_iso = iso;
+  flag_cpp0x = 1;
+}
+
 /* Handle setting implicit to ON.  */
 static void
 set_Wimplicit (int on)
Index: c.opt
===================================================================
--- c.opt	(revision 118379)
+++ c.opt	(working copy)
@@ -842,6 +842,13 @@ std=c++98
 C++ ObjC++
 Conform to the ISO 1998 C++ standard
 
+std=c++0x
+C++ ObjC++
+Conform to the ISO 1998 C++ standard, with extensions that are likely to
+become a part of the upcoming ISO C++ standard, dubbed C++0x. Note that the
+extensions enabled by this mode are experimental and may be removed in
+future releases of GCC.
+
 std=c89
 C ObjC
 Conform to the ISO 1990 C standard
@@ -858,6 +865,13 @@ std=gnu++98
 C++ ObjC++
 Conform to the ISO 1998 C++ standard with GNU extensions
 
+std=gnu++0x
+C++ ObjC++
+Conform to the ISO 1998 C++ standard, with GNU extensions and
+extensions that are likely to become a part of the upcoming ISO C++
+standard, dubbed C++0x. Note that the extensions enabled by this mode
+are experimental and may be removed in future releases of GCC.
+
 std=gnu89
 C ObjC
 Conform to the ISO 1990 C standard with GNU extensions
Index: doc/cpp.texi
===================================================================
--- doc/cpp.texi	(revision 118379)
+++ doc/cpp.texi	(working copy)
@@ -2094,6 +2094,13 @@ This macro is defined, with value 1, if 
 mechanism based on @code{setjmp} and @code{longjmp} for exception
 handling.
 
+@item __GXX_EXPERIMENTAL_CPP0X__
+This macro is defined when compiling a C++ source file with the option
+@option{-std=c++0x} or @option{-std=gnu++0x}. It indicates that some
+features likely to be included in C++0x are available. Note that these
+features are experimental, and may change or be removed in future
+versions of GCC.
+
 @item __GXX_WEAK__
 This macro is defined when compiling a C++ source file.  It has the
 value 1 if the compiler will use weak symbols, COMDAT sections, or
Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi	(revision 118379)
+++ doc/invoke.texi	(working copy)
@@ -1199,6 +1199,18 @@ The 1998 ISO C++ standard plus amendment
 @item gnu++98
 The same as @option{-std=c++98} plus GNU extensions.  This is the
 default for C++ code.
+
+@item c++0x
+The working draft of the upcoming ISO C++0x standard. This option
+enables experimental features that are likely to be included in
+C++0x. The working draft is constantly changing, and any feature that is
+enabled by this flag may be removed from future versions of GCC if it is
+not part of the C++0x standard.
+
+@item gnu++0x
+The same as @option{-std=c++0x} plus GNU extensions. As with
+@option{-std=c++0x}, this option enables experimental features that may
+be removed in future versions of GCC.
 @end table
 
 Even when this option is not specified, you can still use some of the

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]