From 9bee1c908825ba0bdf534106b4f922713a7d7660 Mon Sep 17 00:00:00 2001
From: jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Mon, 21 Aug 2000 14:30:38 +0000
Subject: [PATCH] 	* 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.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@35843 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog    | 15 +++++++++++
 gcc/c-common.c   | 69 ++++++++++++++++++++++++++++--------------------
 gcc/c-common.h   |  9 +++++++
 gcc/c-decl.c     |  9 +++++++
 gcc/c-tree.h     |  4 ---
 gcc/cp/ChangeLog |  7 +++++
 gcc/cp/decl.c    |  9 +++++++
 gcc/cp/decl2.c   |  2 +-
 8 files changed, 90 insertions(+), 34 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b95fbcdbd25..5f289b4cdd3 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/c-common.c b/gcc/c-common.c
index e9c84f915ca..c0b9816c301 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -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] == '[')
diff --git a/gcc/c-common.h b/gcc/c-common.h
index 50823df10f7..0fc84a58f6d 100644
--- a/gcc/c-common.h
+++ b/gcc/c-common.h
@@ -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;
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 48e842e580a..c9afb28ccd2 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -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;
diff --git a/gcc/c-tree.h b/gcc/c-tree.h
index 3af50a4295d..f3ad275f35e 100644
--- a/gcc/c-tree.h
+++ b/gcc/c-tree.h
@@ -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;
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 55f3111f4f0..98fb6697fed 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index c8599fa98eb..d9e2e982d4c 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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;
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index c45a272f764..31e42ae1dbd 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -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
-- 
GitLab