c-tree.h (flag_hosted): Move declaration from here...
authorJoseph Myers <jsm28@cam.ac.uk>
Mon, 21 Aug 2000 14:30:38 +0000 (15:30 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Mon, 21 Aug 2000 14:30:38 +0000 (15:30 +0100)
* c-tree.h (flag_hosted): Move declaration from here...
* c-common.h (flag_hosted): ... to here.
(flag_noniso_default_format_attributes): New declaration.
* c-decl.c (flag_noniso_default_format_attributes): New variable.
(c_decode_option): Set it appropriately for options choosing
language standard variant.
* c-common.c (init_function_format_info): Only provide default
format attributes if flag_hosted.  Only provide the gettext
formats if flag_noniso_default_format_attributes.  Update
comments.
(check_format_info): Disable treatment of %a as a scanf flag in
C99 mode.

cp:
* decl.c (flag_hosted, flag_noniso_default_format_attributes): New
variables.
* decl2.c (lang_decode_option): Disable gettext attributes for
-ansi.

From-SVN: r35843

gcc/ChangeLog
gcc/c-common.c
gcc/c-common.h
gcc/c-decl.c
gcc/c-tree.h
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/decl2.c

index b95fbcdbd25360e0d67c01574a2caa5f19c7efa5..5f289b4cdd397a3a90198b83cca6e6828402c1c8 100644 (file)
@@ -1,3 +1,18 @@
+2000-08-21  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * c-tree.h (flag_hosted): Move declaration from here...
+       * c-common.h (flag_hosted): ... to here.
+       (flag_noniso_default_format_attributes): New declaration.
+       * c-decl.c (flag_noniso_default_format_attributes): New variable.
+       (c_decode_option): Set it appropriately for options choosing
+       language standard variant.
+       * c-common.c (init_function_format_info): Only provide default
+       format attributes if flag_hosted.  Only provide the gettext
+       formats if flag_noniso_default_format_attributes.  Update
+       comments.
+       (check_format_info): Disable treatment of %a as a scanf flag in
+       C99 mode.
+
 2000-08-21  Joseph S. Myers  <jsm28@cam.ac.uk>
 
        * c-common.c (scan_char_table): Add 'w' to flags for all formats
index e9c84f915ca212ba5cd98258d2dab46b064f442e..c0b9816c30192e11ddb03d1b17125e2b0e18c43a 100644 (file)
@@ -1325,11 +1325,13 @@ static international_format_info *international_format_list = NULL;
 static void check_format_info  PARAMS ((function_format_info *, tree));
 
 /* Initialize the table of functions to perform format checking on.
-   The ANSI functions are always checked (whether <stdio.h> is
+   The ISO C functions are always checked (whether <stdio.h> is
    included or not), since it is common to call printf without
    including <stdio.h>.  There shouldn't be a problem with this,
-   since ANSI reserves these function names whether you include the
-   header file or not.  In any case, the checking is harmless.
+   since ISO C reserves these function names whether you include the
+   header file or not.  In any case, the checking is harmless.  With
+   -ffreestanding, these default attributes are disabled, and must be
+   specified manually if desired.
 
    Also initialize the name of function that modify the format string for
    internationalization purposes.  */
@@ -1337,28 +1339,32 @@ static void check_format_info   PARAMS ((function_format_info *, tree));
 void
 init_function_format_info ()
 {
-  record_function_format (get_identifier ("printf"), NULL_TREE,
-                         printf_format_type, 1, 2);
-  record_function_format (get_identifier ("fprintf"), NULL_TREE,
-                         printf_format_type, 2, 3);
-  record_function_format (get_identifier ("sprintf"), NULL_TREE,
-                         printf_format_type, 2, 3);
-  record_function_format (get_identifier ("scanf"), NULL_TREE,
-                         scanf_format_type, 1, 2);
-  record_function_format (get_identifier ("fscanf"), NULL_TREE,
-                         scanf_format_type, 2, 3);
-  record_function_format (get_identifier ("sscanf"), NULL_TREE,
-                         scanf_format_type, 2, 3);
-  record_function_format (get_identifier ("vprintf"), NULL_TREE,
-                         printf_format_type, 1, 0);
-  record_function_format (get_identifier ("vfprintf"), NULL_TREE,
-                         printf_format_type, 2, 0);
-  record_function_format (get_identifier ("vsprintf"), NULL_TREE,
-                         printf_format_type, 2, 0);
-  record_function_format (get_identifier ("strftime"), NULL_TREE,
-                         strftime_format_type, 3, 0);
-
-  if (flag_isoc99)
+  if (flag_hosted)
+    {
+      /* Functions from ISO/IEC 9899:1990.  */
+      record_function_format (get_identifier ("printf"), NULL_TREE,
+                             printf_format_type, 1, 2);
+      record_function_format (get_identifier ("fprintf"), NULL_TREE,
+                             printf_format_type, 2, 3);
+      record_function_format (get_identifier ("sprintf"), NULL_TREE,
+                             printf_format_type, 2, 3);
+      record_function_format (get_identifier ("scanf"), NULL_TREE,
+                             scanf_format_type, 1, 2);
+      record_function_format (get_identifier ("fscanf"), NULL_TREE,
+                             scanf_format_type, 2, 3);
+      record_function_format (get_identifier ("sscanf"), NULL_TREE,
+                             scanf_format_type, 2, 3);
+      record_function_format (get_identifier ("vprintf"), NULL_TREE,
+                             printf_format_type, 1, 0);
+      record_function_format (get_identifier ("vfprintf"), NULL_TREE,
+                             printf_format_type, 2, 0);
+      record_function_format (get_identifier ("vsprintf"), NULL_TREE,
+                             printf_format_type, 2, 0);
+      record_function_format (get_identifier ("strftime"), NULL_TREE,
+                             strftime_format_type, 3, 0);
+    }
+
+  if (flag_hosted && flag_isoc99)
     {
       /* ISO C99 adds the snprintf and vscanf family functions.  */
       record_function_format (get_identifier ("snprintf"), NULL_TREE,
@@ -1373,9 +1379,13 @@ init_function_format_info ()
                              scanf_format_type, 2, 0);
     }
 
-  record_international_format (get_identifier ("gettext"), NULL_TREE, 1);
-  record_international_format (get_identifier ("dgettext"), NULL_TREE, 2);
-  record_international_format (get_identifier ("dcgettext"), NULL_TREE, 2);
+  if (flag_hosted && flag_noniso_default_format_attributes)
+    {
+      /* Uniforum/GNU gettext functions, not in ISO C.  */
+      record_international_format (get_identifier ("gettext"), NULL_TREE, 1);
+      record_international_format (get_identifier ("dgettext"), NULL_TREE, 2);
+      record_international_format (get_identifier ("dcgettext"), NULL_TREE, 2);
+    }
 }
 
 /* Record information for argument format checking.  FUNCTION_IDENT is
@@ -1872,7 +1882,8 @@ check_format_info (info, params)
              if (pedantic && !flag_isoc99)
                warning ("ISO C89 does not support the `hh' length modifier");
            }
-         if (*format_chars == 'a' && info->format_type == scanf_format_type)
+         if (*format_chars == 'a' && info->format_type == scanf_format_type
+             && !flag_isoc99)
            {
              if (format_chars[1] == 's' || format_chars[1] == 'S'
                  || format_chars[1] == '[')
index 50823df10f751d6f42e330916febabebb7b32f78..0fc84a58f6d833d9c6a6c98e61deeb3f1bfaf401 100644 (file)
@@ -195,6 +195,15 @@ extern int flag_isoc99;
 
 extern int flag_digraphs;
 
+/* Nonzero means environment is hosted (i.e., not freestanding) */
+
+extern int flag_hosted;
+
+/* Nonzero means add default format_arg attributes for functions not
+   in ISO C.  */
+
+extern int flag_noniso_default_format_attributes;
+
 /* Nonzero means warn about suggesting putting in ()'s.  */
 
 extern int warn_parentheses;
index 48e842e580a6338968896336dedb7585c0cc0cf0..c9afb28ccd2ff7d9cf20abcae231d600232a132b 100644 (file)
@@ -345,6 +345,11 @@ int flag_digraphs = 1;
 
 int flag_hosted = 1;
 
+/* Nonzero means add default format_arg attributes for functions not
+   in ISO C.  */
+
+int flag_noniso_default_format_attributes = 1;
+
 /* Nonzero means to allow single precision math even if we're generally
    being traditional.  */
 int flag_allow_single_precision = 0;
@@ -550,6 +555,7 @@ c_decode_option (argc, argv)
          flag_writable_strings = 0;
          flag_no_asm = 1;
          flag_no_nonansi_builtin = 1;
+         flag_noniso_default_format_attributes = 0;
          flag_isoc99 = 0;
        }
       else if (!strcmp (argstart, "iso9899:199409"))
@@ -567,6 +573,7 @@ c_decode_option (argc, argv)
          flag_writable_strings = 0;
          flag_no_asm = 1;
          flag_no_nonansi_builtin = 1;
+         flag_noniso_default_format_attributes = 0;
          flag_isoc99 = 1;
          flag_digraphs = 1;
          flag_isoc94 = 1;
@@ -577,6 +584,7 @@ c_decode_option (argc, argv)
          flag_writable_strings = 0;
          flag_no_asm = 0;
          flag_no_nonansi_builtin = 0;
+         flag_noniso_default_format_attributes = 1;
          flag_isoc99 = 0;
          flag_digraphs = 1;
          flag_isoc94 = 0;
@@ -587,6 +595,7 @@ c_decode_option (argc, argv)
          flag_writable_strings = 0;
          flag_no_asm = 0;
          flag_no_nonansi_builtin = 0;
+         flag_noniso_default_format_attributes = 1;
          flag_isoc99 = 1;
          flag_digraphs = 1;
          flag_isoc94 = 1;
index 3af50a4295d80a14a9679bdb01663946a243c1f1..f3ad275f35e26f73574f733be3168ba8be988481 100644 (file)
@@ -299,10 +299,6 @@ extern int flag_cond_mismatch;
 
 extern int flag_no_asm;
 
-/* Nonzero means environment is hosted (i.e., not freestanding) */
-
-extern int flag_hosted;
-
 /* Nonzero means warn about implicit declarations.  */
 
 extern int warn_implicit;
index 55f3111f4f0427914966b1974d9801d25018f669..98fb6697fed0f16502da3b82269fc8e0599a728a 100644 (file)
@@ -1,3 +1,10 @@
+2000-08-21  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * decl.c (flag_hosted, flag_noniso_default_format_attributes): New
+       variables.
+       * decl2.c (lang_decode_option): Disable gettext attributes for
+       -ansi.
+
 2000-08-21  Gabriel Dos Reis  <gdr@codesourcery.com>
 
        * lex.c (lang_init_options): Default diagnostic message maximum
index c8599fa98eb3afa53244f488e376c3b7e3f09f7f..d9e2e982d4cf0f1631ab819e84f1a2cba2961891 100644 (file)
@@ -345,6 +345,15 @@ int flag_isoc94;
 
 int flag_isoc99;
 
+/* Nonzero means we are a hosted implementation for code shared with C.  */
+
+int flag_hosted = 1;
+
+/* Nonzero means add default format_arg attributes for functions not
+   in ISO C.  */
+
+int flag_noniso_default_format_attributes = 1;
+
 /* Nonzero means give `double' the same size as `float'.  */
 
 extern int flag_short_double;
index c45a272f76438a29326ef6dbc73ffa4d0106956c..31e42ae1dbdad99f3bbf6a959d5b8d958321f183 100644 (file)
@@ -822,7 +822,7 @@ lang_decode_option (argc, argv)
     }
   else if (!strcmp (p, "-ansi"))
     flag_no_nonansi_builtin = 1, flag_ansi = 1,
-    flag_no_gnu_keywords = 1;
+    flag_noniso_default_format_attributes = 0, flag_no_gnu_keywords = 1;
 #ifdef SPEW_DEBUG
   /* Undocumented, only ever used when you're invoking cc1plus by hand, since
      it's probably safe to assume no sane person would ever want to use this