The following program
template<int>
struct R{};
struct S
{
template<typename T>
auto f(T t) -> R<sizeof(t)>;
};
template<typename T>
auto S::f(T t) -> R<sizeof(t)> {}
compiles with Clang, but GCC 10.2 gives an error for the definition of f
error: no declaration matches 'R<sizeof (t)> S::f(T)'
This looks like a GCC bug, especially since GCC trunk currently gives an ICE
internal compiler error: canonical types differ for identical types 'R<sizeof (t)>' and 'R<sizeof (t)>'
Also, GCC compiles the program when the return type in both the declaration and the definition is changed to R<sizeof (T)>
.
Is the program valid?
Here's the demo.
t
should be within the name scope to be used in thatsizeof
expression. What's most interesting to me is that this fails even if you do something silly likeR<sizeof(decltype(t))>
(which I tried since gcc does handledecltype(t)
correctly). I'm pretty sure this is a GCC bug. – Sortsizeof
is involved. I'm definitely leaning towards it being a gcc bug. – Alteration