https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104179
Bug ID: 104179
Summary: Truncated representation of character arrays as
non-type template parameters
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: stinkingmadgod at gmail dot com
Target Milestone: ---
#include<algorithm>
template<unsigned N>
struct str
{
char data[N];
consteval str(const char (&arr)[N])
{
std::copy(arr, arr + N, data);
}
};
template<str>
struct print;
constexpr char s[] = {'4', '2'};
print<s> p;
Produces the error message
<source>:17:10: error: aggregate 'print<str<2>{"4"}> p' has incomplete type and
cannot be defined
17 | print<s> p;
Where print<str<2>{"4"}> should be print<str<2>{"42"}>
The intention is likely to print null-terminated strings correctly, as in
print<"42"> p2;
<source>:16:13: error: aggregate 'print<str<3>{"42"}> p2' has incomplete type
and cannot be defined
16 | print<"42"> p2;