https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88829
Bug ID: 88829
Summary: Failure to deduce size of array of 2^31 chars
Product: gcc
Version: 9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Casey at Carter dot net
Target Milestone: ---
This sample TU:
using size_t = decltype(sizeof(int));
template<class T> T&& declval();
template<class T, size_t N>
void f(T(&&)[N]) {}
using U = decltype(f(declval<char[(1ULL << 31)]>())); // error: size of
array is negative
fails to compile on trunk with "g++ -std=c++2a repro.cpp", diagnosing:
<source>:8:51: error: no matching function for call to 'f(char
[2147483648])'
8 | using U = decltype(f(declval<char[(1ULL << 31)]>())); // error:
size of array is negative
| ^
<source>:6:6: note: candidate: 'template<class T, long unsigned int N> void
f(T (&&)[N])'
6 | void f(T(&&)[N]) {}
| ^
<source>:6:6: note: template argument deduction/substitution failed:
<source>: In substitution of 'template<class T, long unsigned int N> void
f(T (&&)[N]) [with T = char; long unsigned int N = 18446744071562067968]':
<source>:8:51: required from here
<source>:6:6: error: size of array is negative
<source>:6:8: error: size of array is negative
6 | void f(T(&&)[N]) {}
| ^~~~~~~~
<source>:8:49: error: invalid initialization of reference of type 'char
(&&)[1]' from expression of type 'char [2147483648]'
8 | using U = decltype(f(declval<char[(1ULL << 31)]>())); // error:
size of array is negative
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
<source>:6:8: note: in passing argument 1 of 'void f(T (&&)[N]) [with T =
char; long unsigned int N = 18446744071562067968]'
6 | void f(T(&&)[N]) {}
| ^~~~~~~~
If arrays of size >= 2^31 aren't supported - which is a perfectly legitimate
implementation limit - I expect the formation of the array type to be diagnosed
rather than the deduction to fail. Also, the "size of array is negative"
diagnostic is confusing (#87996 already makes that point).