public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97253] New: [c++20] last character not shown when printing out std::array <char> via -Wunused-local-typedefs
@ 2020-09-30 10:57 dimitri.gorokhovik at free dot fr
  2020-09-30 11:21 ` [Bug c++/97253] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: dimitri.gorokhovik at free dot fr @ 2020-09-30 10:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97253
           Summary: [c++20] last character not shown when printing out
                    std::array <char> via -Wunused-local-typedefs
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dimitri.gorokhovik at free dot fr
  Target Milestone: ---

The following code:

#include <array>
#include <cstdio>

template <auto M> struct s { constexpr static auto m = M; };

int main ()
{
  constexpr auto s1 = s <std::array <char, 4> { 'a', 'b', 'c', 'd' }> {};
  constexpr auto s2 = s <std::array <wchar_t, 4> { 'a', 'b', 'c', 'd' }> {};  

  using _1 = decltype (s1);
  using _2 = decltype (s2);    

  for (auto i : s1.m)
    printf ("%c", i);
  printf ("\n");

  return 0;
};


when built as:
g++ -std=c++20 -Wunused-local-typedefs -o bug-7  bug-7.cpp && ./bug-7

produces the following warnings:

bug-7.cpp: In function ‘int main()’:
bug-7.cpp:11:9: warning: typedef ‘using _1 = const struct s<std::array<char,
4>{"abc"}>’ locally defined but not used [-Wunused-local-typedefs]
   11 |   using _1 = decltype (s1);
      |         ^~
bug-7.cpp:12:9: warning: typedef ‘using _2 = const struct s<std::array<wchar_t,
4>{std::__array_traits<wchar_t, 4>::_Type{97, 98, 99, 100}}>’ locally defined
but not used [-Wunused-local-typedefs]
   12 |   using _2 = decltype (s2);
      |         ^~

When it is run, the output is:
abcd

I.e., when the warning displays the contents of the literal of the type
std::array <char>, it presents it as a character string ("abc") in which the
last character is missing ('d' in this example). This doesn't happen when the
array type doesn't allow to show it as char string -- all array elements are
shown.

Running the binary confirms that the array literal actually contains the
non-shown character.

g++ (GCC) 11.0.0 20200924 (experimental)

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

* [Bug c++/97253] [c++20] last character not shown when printing out std::array <char> via -Wunused-local-typedefs
  2020-09-30 10:57 [Bug c++/97253] New: [c++20] last character not shown when printing out std::array <char> via -Wunused-local-typedefs dimitri.gorokhovik at free dot fr
@ 2020-09-30 11:21 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2020-09-30 11:21 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
           Keywords|                            |diagnostic
   Last reconfirmed|                            |2020-09-30
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I think the bug is that it's trying to print char[4] as a quoted string, rather
than as an array of four elements. I would expect it to show {'a','b','c','d'}
instead.

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

end of thread, other threads:[~2020-09-30 11:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-30 10:57 [Bug c++/97253] New: [c++20] last character not shown when printing out std::array <char> via -Wunused-local-typedefs dimitri.gorokhovik at free dot fr
2020-09-30 11:21 ` [Bug c++/97253] " redi 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).