Sujet : Array size validity and SFINAE
De : noone (at) *nospam* noone.net (Andrey Tarasevich)
Groupes : comp.lang.c++Date : 25. Feb 2026, 17:08:25
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <10nn6pp$su58$1@dont-email.me>
User-Agent : Mozilla Thunderbird
#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 "..."
The struct definition can be changed to `struct S {};` with the same behavior from GCC. I.e. in template contexts GCC does not check the validity of the size specified in array parameter declaration: it doesn't care whether it is positive, it doesn't even care whether the nested name exists. One can guess that this is most likely a consequence of the array parameter type adjustment, which makes the size essentially "disappear". However, it still does not necessarily mean that such array parameter declaration should be accepted as valid.
So, who's right here standard-wise?
-- Best regards,Andrey
Haut de la page
Les messages affichés proviennent d'usenet.
NewsPortal