c-common.c (check_format_info): Warn for a wide character string used as a non-wide...
authorJoseph Myers <jsm28@cam.ac.uk>
Sun, 24 Sep 2000 09:52:53 +0000 (10:52 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Sun, 24 Sep 2000 09:52:53 +0000 (10:52 +0100)
* c-common.c (check_format_info): Warn for a wide character string
used as a non-wide format argument.

testsuite:
* gcc.dg/c90-printf-1.c: Add test for wide string format.

From-SVN: r36586

gcc/ChangeLog
gcc/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c90-printf-1.c

index 9fb5b7acc1810dd93011dd69a72cadb85a532456..55bdbc6cfdea560b4ba01703dacab21811222206 100644 (file)
@@ -1,3 +1,8 @@
+2000-09-24  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * c-common.c (check_format_info): Warn for a wide character string
+       used as a non-wide format argument.
+
 2000-09-24  Joseph S. Myers  <jsm28@cam.ac.uk>
 
        * builtins.def (BUILT_IN_LLABS): Add.
index d72c45b8152514cd86082589b16c577eb4112802..79fef421f032cd01680576dfeecbc8691093e90d 100644 (file)
@@ -2040,6 +2040,11 @@ check_format_info (status, info, params)
        status_warning (status, "format not a string literal, argument types not checked");
       return;
     }
+  if (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (format_tree))) != char_type_node)
+    {
+      status_warning (status, "format is a wide character string");
+      return;
+    }
   format_chars = TREE_STRING_POINTER (format_tree);
   format_length = TREE_STRING_LENGTH (format_tree);
   if (format_length <= 1)
index 1de5ac8dce15edb432dd6a8c270a9168b4b7c75f..46ab73ba0aa45869226d9d955abc53a48740b229 100644 (file)
@@ -1,3 +1,7 @@
+2000-09-24  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * gcc.dg/c90-printf-1.c: Add test for wide string format.
+
 2000-09-22  Geoff Keating  <geoffk@cygnus.com>
 
        * gcc.c-torture/compile/20000922-1.c: New file.
index ad8adb0a2f7af8317afb3c2e00396a89b4767b59..4c5a6e360884ec78b8a9f0a49d316454ebbe1b8a 100644 (file)
@@ -243,5 +243,6 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p,
   printf ("%"); /* { dg-warning "trailing" "trailing % warning" } */
   printf ("%++d", i); /* { dg-warning "repeated" "repeated flag warning" } */
   printf ("%n", cn); /* { dg-warning "constant" "%n with const" } */
+  printf ((const char *)L"foo"); /* { dg-warning "wide" "wide string" } */
   /* Can we test for the warning for unterminated string formats?  */
 }