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)