]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-opts.c (set_std_cxx98, [...]): New.
authorNeil Booth <neil@daikokuya.co.uk>
Sat, 10 Aug 2002 20:58:45 +0000 (20:58 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Sat, 10 Aug 2002 20:58:45 +0000 (20:58 +0000)
* c-opts.c (set_std_cxx98, set_std_c89): New.
(COMMAND_LINE_OPTIONS): Move more from cppinit.c.
(c_common_decode_option): Handle new switches from cppinit.c.
Add -std=gnu++98.
* cppinit.c (set_lang): Rename cpp_set_lang.  Export.
(no_arg, no_num): Remove.
(COMMAND_LINE_OPTIONS): Move more to c-opts.c.  Drop all lang-
switches apart from -lang-objc and lang-asm.
(cpp_handle_option): Similarly.
* cpplib.h (cpp_set_lang): New.
* doc/cppopts.texi, doc/invoke.texi: Document -std=c++98,
-std=gnu++98.
* objc/lang-specs.h: Remove -ansi.
cp:
* lang-specs.h: Remove -ansi.

From-SVN: r56185

gcc/ChangeLog
gcc/c-opts.c
gcc/cp/ChangeLog
gcc/cp/lang-specs.h
gcc/cppinit.c
gcc/cpplib.h
gcc/doc/cppopts.texi
gcc/doc/invoke.texi
gcc/gcc.c
gcc/objc/lang-specs.h

index d62b26d28213c1f284bda5f0aab72ba174b72841..a1cf40980250260052f61a874581aa1fbe684395 100644 (file)
@@ -1,3 +1,19 @@
+2002-08-10  Neil Booth  <neil@daikokuya.co.uk>
+
+       * c-opts.c (set_std_cxx98, set_std_c89): New.
+       (COMMAND_LINE_OPTIONS): Move more from cppinit.c.
+       (c_common_decode_option): Handle new switches from cppinit.c.
+       Add -std=gnu++98.
+       * cppinit.c (set_lang): Rename cpp_set_lang.  Export.
+       (no_arg, no_num): Remove.
+       (COMMAND_LINE_OPTIONS): Move more to c-opts.c.  Drop all lang-
+       switches apart from -lang-objc and lang-asm.
+       (cpp_handle_option): Similarly.
+       * cpplib.h (cpp_set_lang): New.
+       * doc/cppopts.texi, doc/invoke.texi: Document -std=c++98,
+       -std=gnu++98.
+       * objc/lang-specs.h: Remove -ansi.
+
 Sat Aug 10 19:59:43 CEST 2002  Jan Hubicka  <jh@suse.cz>
                               Graham Stott
 
index 02f1ada8c2e260e6ea8cc8459d062b1803b2b67a..e6274d86f8efb6eac6b5382c05ffdd736ce6f430 100644 (file)
@@ -40,6 +40,8 @@ static void complain_wrong_lang PARAMS ((size_t));
 static void write_langs PARAMS ((char *, int));
 static void print_help PARAMS ((void));
 static void handle_OPT_d PARAMS ((const char *));
+static void set_std_cxx98 PARAMS ((int));
+static void set_std_c89 PARAMS ((int, int));
 
 #define CL_C_ONLY      (1 << 0) /* Only C.  */
 #define CL_OBJC_ONLY   (1 << 1) /* Only ObjC.  */
@@ -210,6 +212,8 @@ static void handle_OPT_d PARAMS ((const char *));
   OPT("fweak",                 CL_CXX,   OPT_fweak)                         \
   OPT("fxref",                 CL_CXX,   OPT_fxref)                         \
   OPT("gen-decls",             CL_OBJC,  OPT_gen_decls)                     \
+  OPT("lang-asm",              CL_C_ONLY, OPT_lang_asm)                     \
+  OPT("lang-objc",              CL_ALL,   OPT_lang_objc)                    \
   OPT("nostdinc",               CL_ALL,   OPT_nostdinc)                             \
   OPT("nostdinc++",             CL_ALL,   OPT_nostdincplusplus)                     \
   OPT("pedantic",              CL_ALL,   OPT_pedantic)                      \
@@ -220,6 +224,7 @@ static void handle_OPT_d PARAMS ((const char *));
   OPT("std=c89",               CL_C,     OPT_std_c89)                       \
   OPT("std=c99",               CL_C,     OPT_std_c99)                       \
   OPT("std=c9x",               CL_C,     OPT_std_c9x)                       \
+  OPT("std=gnu++98",           CL_CXX,   OPT_std_gnuplusplus98)             \
   OPT("std=gnu89",             CL_C,     OPT_std_gnu89)                     \
   OPT("std=gnu99",             CL_C,     OPT_std_gnu99)                     \
   OPT("std=gnu9x",             CL_C,     OPT_std_gnu9x)                     \
@@ -230,8 +235,8 @@ static void handle_OPT_d PARAMS ((const char *));
   OPT("traditional-cpp",       CL_ALL,   OPT_traditional_cpp)               \
   OPT("trigraphs",              CL_ALL,   OPT_trigraphs)                    \
   OPT("undef",                 CL_ALL,   OPT_undef)                         \
-  OPT("v",                      CL_ALL,      OPT_v)                         \
-  OPT("w",                      CL_ALL,      OPT_w)
+  OPT("v",                      CL_ALL,   OPT_v)                            \
+  OPT("w",                      CL_ALL,   OPT_w)
 
 #define OPT(text, flags, code) code,
 enum opt_code
@@ -823,6 +828,13 @@ c_common_decode_option (argc, argv)
       else
        warn_write_strings = on;
       break;
+      
+    case OPT_ansi:
+      if (c_language == clk_c)
+       set_std_c89 (false, true);
+      else
+       set_std_cxx98 (true);
+      break;
 
     case OPT_d:
       handle_OPT_d (arg);
@@ -1071,6 +1083,14 @@ c_common_decode_option (argc, argv)
       flag_gen_declaration = 1;
       break;
 
+    case OPT_lang_asm:
+      cpp_set_lang (parse_in, CLK_ASM);
+      break;
+
+    case OPT_lang_objc:
+      cpp_opts->objc = 1;
+      break;
+
     case OPT_nostdinc:
       /* No default include directories.  You must specify all
         include-file directories with -I.  */
@@ -1112,30 +1132,25 @@ c_common_decode_option (argc, argv)
       */
 
     case OPT_std_cplusplus98:
+    case OPT_std_gnuplusplus98:
+      set_std_cxx98 (code == OPT_std_cplusplus98);
       break;
 
+    case OPT_std_iso9899_199409:
     case OPT_std_c89:
     case OPT_std_iso9899_1990:
-    case OPT_std_iso9899_199409:
-    case OPT_ansi:
-      /* Note: -ansi is used by both the C and C++ front ends.  */
-      if (c_language == clk_c)
-       {
-         flag_no_asm = 1;
-         flag_writable_strings = 0;
-       }
-      flag_isoc94 = (code == OPT_std_iso9899_199409);
-      flag_no_gnu_keywords = 1;
-      flag_no_nonansi_builtin = 1;
-      flag_noniso_default_format_attributes = 0;
-      flag_isoc99 = 0;
-      flag_iso = 1;
+      set_std_c89 (code == OPT_std_iso9899_199409, true);
+      break;
+
+    case OPT_std_gnu89:
+      set_std_c89 (false /* c94 */, false /* ISO */);
       break;
 
     case OPT_std_c99:
     case OPT_std_c9x:
     case OPT_std_iso9899_1999:
     case OPT_std_iso9899_199x:
+      cpp_set_lang (parse_in, CLK_STDC99);
       flag_writable_strings = 0;
       flag_no_asm = 1;
       flag_no_nonansi_builtin = 1;
@@ -1145,17 +1160,9 @@ c_common_decode_option (argc, argv)
       flag_iso = 1;
       break;
 
-    case OPT_std_gnu89:
-      flag_writable_strings = 0;
-      flag_no_asm = 0;
-      flag_no_nonansi_builtin = 0;
-      flag_noniso_default_format_attributes = 1;
-      flag_isoc99 = 0;
-      flag_isoc94 = 0;
-      break;
-
     case OPT_std_gnu99:
     case OPT_std_gnu9x:
+      cpp_set_lang (parse_in, CLK_GNUC99);
       flag_writable_strings = 0;
       flag_no_asm = 0;
       flag_no_nonansi_builtin = 0;
@@ -1238,6 +1245,35 @@ c_common_post_options ()
   return flag_preprocess_only;
 }
 
+/* Set the C 89 standard (with 1994 amendments if C94, without GNU
+   extensions if ISO).  */
+static void
+set_std_c89 (c94, iso)
+     int c94, iso;
+{
+  cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
+  flag_iso = iso;
+  flag_no_asm = iso;
+  flag_no_gnu_keywords = iso;
+  flag_no_nonansi_builtin = iso;
+  flag_noniso_default_format_attributes = !iso;
+  flag_isoc94 = c94;
+  flag_isoc99 = 0;
+  flag_writable_strings = 0;
+}
+
+/* Set the C++ 98 standard (without GNU extensions if ISO).  */
+static void
+set_std_cxx98 (iso)
+     int iso;
+{
+  cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
+  flag_no_gnu_keywords = iso;
+  flag_no_nonansi_builtin = iso;
+  flag_noniso_default_format_attributes = !iso;
+  flag_iso = iso;
+}
+
 /* Handle setting implicit to ON.  */
 static void
 set_Wimplicit (on)
index 569d19a73d3719e12103825c7a76b114aa3aeabc..0563560c447bcd45d6b97011076b1224a8893fcc 100644 (file)
@@ -1,3 +1,7 @@
+2002-08-10  Neil Booth  <neil@daikokuya.co.uk>
+
+       * lang-specs.h: Remove -ansi.
+
 2002-08-10  Nathan Sidwell  <nathan@codesourcery.com>
 
        * tree.c (maybe_dummy_object): Replace // with /* */
index 7b8711666a671b69aba0953e709b0fafc59525ed..2e9640c83e1e5926d7d93aaa269aa5fbb9de0df2 100644 (file)
@@ -33,16 +33,14 @@ Boston, MA 02111-1307, USA.  */
   {".c++", "@c++", 0},
   {".C",   "@c++", 0},
   {"@c++",
-     /* We should convert -ansi to -std=c++98 even if -fpreprocessed,
-       to get dollars in identifiers correct.  */
     "%{E|M|MM:cc1plus -E %{!no-gcc:-D__GNUG__=%v1}\
-       %{ansi:-std=c++98} %(cpp_options) %2 %(cpp_debug_options)}\
+       %(cpp_options) %2 %(cpp_debug_options)}\
      %{!E:%{!M:%{!MM:\
        %{save-temps:cc1plus -E %{!no-gcc:-D__GNUG__=%v1}\
-               %{ansi:-std=c++98} %(cpp_options) %2 %b.ii \n}\
+               %(cpp_options) %2 %b.ii \n}\
       cc1plus %{save-temps:-fpreprocessed %b.ii}\
              %{!save-temps:%(cpp_unique_options) %{!no-gcc:-D__GNUG__=%v1}}\
-       %{ansi:-std=c++98} %(cc1_options) %2 %{+e1*}\
+       %(cc1_options) %2 %{+e1*}\
        %{!fsyntax-only:%(invoke_as)}}}}",
      CPLUSPLUS_CPP_SPEC},
   {".ii", "@c++-cpp-output", 0},
index 212da6b358af3783b23b227b60f3fe8bc6bc2326..927311e0a022116102c1154a1c3f2995ac6d23f1 100644 (file)
@@ -102,7 +102,6 @@ static void merge_include_chains    PARAMS ((cpp_reader *));
 static bool push_include               PARAMS ((cpp_reader *,
                                                 struct pending_option *));
 static void free_chain                 PARAMS ((struct pending_option *));
-static void set_lang                   PARAMS ((cpp_reader *, enum c_lang));
 static void init_dependency_output     PARAMS ((cpp_reader *));
 static void init_standard_includes     PARAMS ((cpp_reader *));
 static void read_original_filename     PARAMS ((cpp_reader *));
@@ -403,8 +402,8 @@ static const struct lang_flags lang_defaults[] =
 };
 
 /* Sets internal flags correctly for a given language.  */
-static void
-set_lang (pfile, lang)
+void
+cpp_set_lang (pfile, lang)
      cpp_reader *pfile;
      enum c_lang lang;
 {
@@ -471,7 +470,7 @@ cpp_create_reader (lang)
 
   pfile = (cpp_reader *) xcalloc (1, sizeof (cpp_reader));
 
-  set_lang (pfile, lang);
+  cpp_set_lang (pfile, lang);
   CPP_OPTION (pfile, warn_import) = 1;
   CPP_OPTION (pfile, warn_multichar) = 1;
   CPP_OPTION (pfile, discard_comments) = 1;
@@ -1123,13 +1122,11 @@ new_pending_directive (pend, text, handler)
 /* Irix6 "cc -n32" and OSF4 cc have problems with char foo[] = ("string");
    I.e. a const string initializer with parens around it.  That is
    what N_("string") resolves to, so we make no_* be macros instead.  */
-#define no_arg N_("argument missing after %s")
 #define no_ass N_("assertion missing after %s")
 #define no_dir N_("directory name missing after %s")
 #define no_fil N_("file name missing after %s")
 #define no_mac N_("macro name missing after %s")
 #define no_pth N_("path name missing after %s")
-#define no_num N_("number missing after %s")
 #define no_tgt N_("target missing after %s")
 
 /* This is the list of all command line options, with the leading
@@ -1155,24 +1152,8 @@ new_pending_directive (pend, text, handler)
   DEF_OPT("isystem",                  no_dir, OPT_isystem)                    \
   DEF_OPT("iwithprefix",              no_dir, OPT_iwithprefix)                \
   DEF_OPT("iwithprefixbefore",        no_dir, OPT_iwithprefixbefore)          \
-  DEF_OPT("lang-asm",                 0,      OPT_lang_asm)                   \
-  DEF_OPT("lang-c",                   0,      OPT_lang_c)                     \
-  DEF_OPT("lang-c++",                 0,      OPT_lang_cplusplus)             \
-  DEF_OPT("lang-c89",                 0,      OPT_lang_c89)                   \
-  DEF_OPT("lang-objc",                0,      OPT_lang_objc)                  \
   DEF_OPT("o",                        no_fil, OPT_o)                          \
-  DEF_OPT("remap",                    0,      OPT_remap)                      \
-  DEF_OPT("std=c++98",                0,      OPT_std_cplusplus98)            \
-  DEF_OPT("std=c89",                  0,      OPT_std_c89)                    \
-  DEF_OPT("std=c99",                  0,      OPT_std_c99)                    \
-  DEF_OPT("std=c9x",                  0,      OPT_std_c9x)                    \
-  DEF_OPT("std=gnu89",                0,      OPT_std_gnu89)                  \
-  DEF_OPT("std=gnu99",                0,      OPT_std_gnu99)                  \
-  DEF_OPT("std=gnu9x",                0,      OPT_std_gnu9x)                  \
-  DEF_OPT("std=iso9899:1990",         0,      OPT_std_iso9899_1990)           \
-  DEF_OPT("std=iso9899:199409",       0,      OPT_std_iso9899_199409)         \
-  DEF_OPT("std=iso9899:1999",         0,      OPT_std_iso9899_1999)           \
-  DEF_OPT("std=iso9899:199x",         0,      OPT_std_iso9899_199x)
+  DEF_OPT("remap",                    0,      OPT_remap)
 
 #define DEF_OPT(text, msg, code) code,
 enum opt_code
@@ -1329,42 +1310,6 @@ cpp_handle_option (pfile, argc, argv)
          CPP_OPTION (pfile, include_prefix) = arg;
          CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
          break;
-       case OPT_lang_c:
-         set_lang (pfile, CLK_GNUC89);
-         break;
-       case OPT_lang_cplusplus:
-         set_lang (pfile, CLK_GNUCXX);
-         break;
-       case OPT_lang_objc:
-         CPP_OPTION (pfile, objc) = 1;
-         break;
-       case OPT_lang_asm:
-         set_lang (pfile, CLK_ASM);
-         break;
-       case OPT_std_cplusplus98:
-         set_lang (pfile, CLK_CXX98);
-         break;
-       case OPT_std_gnu89:
-         set_lang (pfile, CLK_GNUC89);
-         break;
-       case OPT_std_gnu9x:
-       case OPT_std_gnu99:
-         set_lang (pfile, CLK_GNUC99);
-         break;
-       case OPT_std_iso9899_199409:
-         set_lang (pfile, CLK_STDC94);
-         break;
-       case OPT_std_iso9899_1990:
-       case OPT_std_c89:
-       case OPT_lang_c89:
-         set_lang (pfile, CLK_STDC89);
-         break;
-       case OPT_std_iso9899_199x:
-       case OPT_std_iso9899_1999:
-       case OPT_std_c9x:
-       case OPT_std_c99:
-         set_lang (pfile, CLK_STDC99);
-         break;
        case OPT_o:
          if (CPP_OPTION (pfile, out_fname) == NULL)
            CPP_OPTION (pfile, out_fname) = arg;
index 97520a7ed960d1840cbf8e81e6cf201e723add9b..75a9d921bab3023d79b61a66b3e2fac18f906159 100644 (file)
@@ -504,6 +504,10 @@ struct cpp_hashnode
 /* Call this first to get a handle to pass to other functions.  */
 extern cpp_reader *cpp_create_reader PARAMS ((enum c_lang));
 
+/* Call this to change the selected language standard (e.g. because of
+   command line options).  */
+extern void cpp_set_lang PARAMS ((cpp_reader *, enum c_lang));
+
 /* Call these to get pointers to the options and callback structures
    for a given reader.  These pointers are good until you call
    cpp_finish on that reader.  You can either edit the callbacks
index aacfb4b2631382f798b4b975009defe4e338cd17..b23c9fccdc7d76e08a4cd20e38ad30e7bff65fa7 100644 (file)
@@ -326,9 +326,8 @@ option.
 @itemx -ansi
 @opindex ansi
 @opindex std=
-Specify the standard to which the code should conform.  Currently cpp
-only knows about the standards for C; other language standards will be
-added in the future.
+Specify the standard to which the code should conform.  Currently CPP
+knows about C and C++ standards; others may be added in the future.
 
 @var{standard}
 may be one of:
@@ -356,6 +355,13 @@ The 1990 C standard plus GNU extensions.  This is the default.
 @item gnu99
 @itemx gnu9x
 The 1999 C standard plus GNU extensions.
+
+@item c++98
+The 1998 ISO C++ standard plus amendments.
+
+@item gnu++98
+The same as @option{-std=c++98} plus GNU extensions.  This is the
+default for C++ code.
 @end table
 
 @item -I-
index 71beb9485c6deff38f55d97f2c5db207617cc579..6383cd20cb814237c2dc5e80d5011d1794e9f1f4 100644 (file)
@@ -1009,8 +1009,8 @@ affected.
 @item -std=
 @opindex std
 Determine the language standard.  This option is currently only
-supported when compiling C@.  A value for this option must be provided;
-possible values are
+supported when compiling C or C++.  A value for this option must be
+provided; possible values are
 
 @table @samp
 @item c89
@@ -1036,6 +1036,12 @@ Default, ISO C90 plus GNU extensions (including some C99 features).
 ISO C99 plus GNU extensions.  When ISO C99 is fully implemented in GCC,
 this will become the default.  The name @samp{gnu9x} is deprecated.
 
+@item c++98
+The 1998 ISO C++ standard plus amendments.
+
+@item gnu++98
+The same as @option{-std=c++98} plus GNU extensions.  This is the
+default for C++ code.
 @end table
 
 Even when this option is not specified, you can still use some of the
index 25b3fb7126309e7516600a3c3a39540dde4b7dfb..3bff09a5bf636b2a72a875ba7988dece32cc6464 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -829,24 +829,23 @@ static const struct compiler default_compilers[] =
   {"@c",
    /* cc1 has an integrated ISO C preprocessor.  We should invoke the
       external preprocessor if -save-temps is given.  */
-     "%{E|M|MM:%(trad_capable_cpp) %{ansi:-std=c89} %(cpp_options)\
-         %(cpp_debug_options)}\
+     "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
       %{!E:%{!M:%{!MM:\
           %{traditional|ftraditional:\
 %eGNU C no longer supports -traditional without -E}\
          %{save-temps|traditional-cpp:%(trad_capable_cpp) \
-               %{ansi:-std=c89} %(cpp_options) %b.i \n\
+               %(cpp_options) %b.i \n\
                    cc1 -fpreprocessed %b.i %(cc1_options)}\
          %{!save-temps:%{!traditional-cpp:\
-               cc1 %{ansi:-std=c89} %(cpp_unique_options) %(cc1_options)}}\
+               cc1 %(cpp_unique_options) %(cc1_options)}}\
         %{!fsyntax-only:%(invoke_as)}}}}", 0},
   {"-",
    "%{!E:%e-E required when input is from standard input}\
-    %(trad_capable_cpp) %{ansi:-std=c89} %(cpp_options)", 0},
+    %(trad_capable_cpp) %(cpp_options)", 0},
   {".h", "@c-header", 0},
   {"@c-header",
    "%{!E:%ecompilation of header file requested} \
-    %(trad_capable_cpp) %{ansi:-std=c89} %(cpp_options) %(cpp_debug_options)",
+    %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)",
    0},
   {".i", "@cpp-output", 0},
   {"@cpp-output",
index e4c1e0fbaa6fec5e27b965e8eb528c8f4796300f..1e9c70155ad2a861f33d0caac3dd480dc2c330a3 100644 (file)
@@ -26,15 +26,14 @@ Boston, MA 02111-1307, USA.  */
    /* cc1obj has an integrated ISO C preprocessor.  We should invoke the
       external preprocessor if -save-temps or -traditional is given.  */
      "%{E|M|MM:%(trad_capable_cpp)\
-          -lang-objc %{ansi:-std=c89} %(cpp_options) %(cpp_debug_options)}\
+          -lang-objc %(cpp_options) %(cpp_debug_options)}\
       %{!E:%{!M:%{!MM:\
        %{traditional|ftraditional|traditional-cpp:\
 %eGNU Objective C no longer supports traditional compilation}\
-       %{save-temps:cc1obj -E %{ansi:-std=c89}\
-         %(cpp_options) %b.mi \n\
+       %{save-temps:cc1obj -E %(cpp_options) %b.mi \n\
            cc1obj -fpreprocessed %b.mi %(cc1_options) %{gen-decls}}\
        %{!save-temps:\
-           cc1obj %{ansi:-std=c89} %(cpp_unique_options) %(cc1_options) %{gen-decls}}\
+           cc1obj %(cpp_unique_options) %(cc1_options) %{gen-decls}}\
         %{!fsyntax-only:%(invoke_as)}}}}", 0},
   {".mi", "@objc-cpp-output", 0},
   {"@objc-cpp-output",