public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-1511] c-family: Prevent -Wformat warnings with u8 strings [PR105626]
@ 2022-07-05 21:35 Marek Polacek
  0 siblings, 0 replies; only message in thread
From: Marek Polacek @ 2022-07-05 21:35 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:543828e79bfa63ef26b11a2c9ea81fd7905f33aa

commit r13-1511-g543828e79bfa63ef26b11a2c9ea81fd7905f33aa
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Jul 5 14:22:26 2022 -0400

    c-family: Prevent -Wformat warnings with u8 strings [PR105626]
    
    The <https://gcc.gnu.org/pipermail/gcc/2022-May/238679.html> thread
    seems to have concluded that -Wformat shouldn't warn about
    
      printf((const char*) u8"test %d\n", 1);
    
    saying "format string is not an array of type 'char'".  This code
    is not an aliasing violation, and there are no I/O functions for u8
    strings, so the const char * cast is OK and shouldn't be disregarded.
    
            PR c++/105626
    
    gcc/c-family/ChangeLog:
    
            * c-format.cc (check_format_arg): Don't emit -Wformat warnings with
            u8 strings.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/warn/Wformat-char8_t-1.C: New test.

Diff:
---
 gcc/c-family/c-format.cc                      |  3 ++-
 gcc/testsuite/g++.dg/warn/Wformat-char8_t-1.C | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc
index 4559ca3e28f..754780446ba 100644
--- a/gcc/c-family/c-format.cc
+++ b/gcc/c-family/c-format.cc
@@ -1742,7 +1742,8 @@ check_format_arg (void *ctx, tree format_tree,
     }
   tree underlying_type
     = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (format_tree)));
-  if (underlying_type != char_type_node)
+  if (underlying_type != char_type_node
+      && !(flag_char8_t && underlying_type == char8_type_node))
     {
       if (underlying_type == char16_type_node
 	  || underlying_type == char32_type_node
diff --git a/gcc/testsuite/g++.dg/warn/Wformat-char8_t-1.C b/gcc/testsuite/g++.dg/warn/Wformat-char8_t-1.C
new file mode 100644
index 00000000000..ba6f388a210
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wformat-char8_t-1.C
@@ -0,0 +1,10 @@
+// PR c++/105626
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wformat" }
+// { dg-additional-options "-fchar8_t" { target c++17_down } }
+
+int main()
+{
+  __builtin_printf((const char*) u8"test %d\n", 1); // { dg-bogus "format string" }
+  return 0;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-05 21:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-05 21:35 [gcc r13-1511] c-family: Prevent -Wformat warnings with u8 strings [PR105626] Marek Polacek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).