Sujet : Re: Array size validity and SFINAE
De : news.5.maazl (at) *nospam* spamgourmet.org (Marcel Mueller)
Groupes : comp.lang.c++Date : 01. Mar 2026, 16:55:04
Autres entêtes
Organisation : MB-NET.NET for Open-News-Network e.V.
Message-ID : <10o1ngo$8go3$3@gwaiyur.mb-net.net>
References : 1
User-Agent : Mozilla Thunderbird
Am 25.02.26 um 17:08 schrieb Andrey Tarasevich:
#include <iostream>
struct S { static constexpr int N = -1; };
template <typename T> void foo(int [T::N])
{
std::cout << "array" << std::endl;
}
template <typename T> void foo(...)
{
std::cout << "..." << std::endl;
}
int main()
{
foo<int>(0);
}
GCC outputs "array", Clang and MSVC output "..."
You are taking an array by value. This might not be the intention and might take a slice. Since the array index is unsigned -1 is UB or in fact expand to UINT_MAX.
If you write
template <typename T> void foo(int (&)[T::N])
gcc will also output ...
I am unsure whether the overload resolution should take place before the other checks.
Marcel
Haut de la page
Les messages affichés proviennent d'usenet.
NewsPortal