public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105626] New: -Wformat should accept u8"" strings
@ 2022-05-17 12:13 drepper.fsp+rhbz at gmail dot com
  2022-05-17 13:10 ` [Bug c++/105626] " mpolacek at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: drepper.fsp+rhbz at gmail dot com @ 2022-05-17 12:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105626

            Bug ID: 105626
           Summary: -Wformat should accept u8"" strings
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: drepper.fsp+rhbz at gmail dot com
  Target Milestone: ---

The discussion about this topic on gcc@
(https://gcc.gnu.org/pipermail/gcc/2022-May/238673.html) ended with the
conclusion that gcc should not disregard the cast in code like this:

#include <stdio.h>

int main()
{
  printf((const char*) u8"test %d\n", 1);
  return 0;
}

With -Wformat this code produces with gcc 12:

t.cc: In function ‘int main()’:
t.cc:5:24: warning: format string is not an array of type ‘char’ [-Wformat=]
    5 |   printf((const char*) u8"test %d\n", 1);
      |                        ^~~~~~~~~~~~~

Since

a) there are no I/O functions for u8 strings in C++20
b) using u8 strings is necessary in reliable code
c) it is safe to perform the analysis -Wformat does on u8 strings

I suggest that u8 strings are allowed when testing for -Wformat.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/105626] -Wformat should accept u8"" strings
  2022-05-17 12:13 [Bug c++/105626] New: -Wformat should accept u8"" strings drepper.fsp+rhbz at gmail dot com
@ 2022-05-17 13:10 ` mpolacek at gcc dot gnu.org
  2022-07-04 20:38 ` drepper.fsp+rhbz at gmail dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-05-17 13:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105626

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Possible fix:

--- 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/105626] -Wformat should accept u8"" strings
  2022-05-17 12:13 [Bug c++/105626] New: -Wformat should accept u8"" strings drepper.fsp+rhbz at gmail dot com
  2022-05-17 13:10 ` [Bug c++/105626] " mpolacek at gcc dot gnu.org
@ 2022-07-04 20:38 ` drepper.fsp+rhbz at gmail dot com
  2022-07-05 16:23 ` mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: drepper.fsp+rhbz at gmail dot com @ 2022-07-04 20:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105626

--- Comment #2 from Ulrich Drepper <drepper.fsp+rhbz at gmail dot com> ---
Could something like this be added, it seems to have few chances if any to
disrupt any meaningful diagnostic while handling this specific case.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/105626] -Wformat should accept u8"" strings
  2022-05-17 12:13 [Bug c++/105626] New: -Wformat should accept u8"" strings drepper.fsp+rhbz at gmail dot com
  2022-05-17 13:10 ` [Bug c++/105626] " mpolacek at gcc dot gnu.org
  2022-07-04 20:38 ` drepper.fsp+rhbz at gmail dot com
@ 2022-07-05 16:23 ` mpolacek at gcc dot gnu.org
  2022-07-05 21:35 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-07-05 16:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105626

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-07-05
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Sure, I'll post the patch and we'll see what happens.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/105626] -Wformat should accept u8"" strings
  2022-05-17 12:13 [Bug c++/105626] New: -Wformat should accept u8"" strings drepper.fsp+rhbz at gmail dot com
                   ` (2 preceding siblings ...)
  2022-07-05 16:23 ` mpolacek at gcc dot gnu.org
@ 2022-07-05 21:35 ` cvs-commit at gcc dot gnu.org
  2022-07-05 21:39 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-07-05 21:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105626

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/105626] -Wformat should accept u8"" strings
  2022-05-17 12:13 [Bug c++/105626] New: -Wformat should accept u8"" strings drepper.fsp+rhbz at gmail dot com
                   ` (3 preceding siblings ...)
  2022-07-05 21:35 ` cvs-commit at gcc dot gnu.org
@ 2022-07-05 21:39 ` mpolacek at gcc dot gnu.org
  2022-07-06  4:42 ` drepper.fsp+rhbz at gmail dot com
  2022-07-06 12:53 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-07-05 21:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105626

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed for GCC 13.  I could probably backport to GCC 12, if desirable.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/105626] -Wformat should accept u8"" strings
  2022-05-17 12:13 [Bug c++/105626] New: -Wformat should accept u8"" strings drepper.fsp+rhbz at gmail dot com
                   ` (4 preceding siblings ...)
  2022-07-05 21:39 ` mpolacek at gcc dot gnu.org
@ 2022-07-06  4:42 ` drepper.fsp+rhbz at gmail dot com
  2022-07-06 12:53 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: drepper.fsp+rhbz at gmail dot com @ 2022-07-06  4:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105626

--- Comment #6 from Ulrich Drepper <drepper.fsp+rhbz at gmail dot com> ---
(In reply to Marek Polacek from comment #5)
> Fixed for GCC 13.  I could probably backport to GCC 12, if desirable.

Thanks.  And I certainly would appreciate a backport since this is an annoying
warning in some of my projects.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/105626] -Wformat should accept u8"" strings
  2022-05-17 12:13 [Bug c++/105626] New: -Wformat should accept u8"" strings drepper.fsp+rhbz at gmail dot com
                   ` (5 preceding siblings ...)
  2022-07-06  4:42 ` drepper.fsp+rhbz at gmail dot com
@ 2022-07-06 12:53 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-07-06 12:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105626

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:65941a910911a8d452b6a6baaccafcc7a1d85c1f

commit r12-8552-g65941a910911a8d452b6a6baaccafcc7a1d85c1f
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.

    (cherry picked from commit 543828e79bfa63ef26b11a2c9ea81fd7905f33aa)

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-07-06 12:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-17 12:13 [Bug c++/105626] New: -Wformat should accept u8"" strings drepper.fsp+rhbz at gmail dot com
2022-05-17 13:10 ` [Bug c++/105626] " mpolacek at gcc dot gnu.org
2022-07-04 20:38 ` drepper.fsp+rhbz at gmail dot com
2022-07-05 16:23 ` mpolacek at gcc dot gnu.org
2022-07-05 21:35 ` cvs-commit at gcc dot gnu.org
2022-07-05 21:39 ` mpolacek at gcc dot gnu.org
2022-07-06  4:42 ` drepper.fsp+rhbz at gmail dot com
2022-07-06 12:53 ` cvs-commit at gcc dot gnu.org

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).