Re: Array size validity and SFINAE

Liste des GroupesRevenir à cl c++ 
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

Date Sujet#  Auteur
25 Feb 26 * Array size validity and SFINAE9Andrey Tarasevich
1 Mar 26 +* Re: Array size validity and SFINAE5Marcel Mueller
1 Mar 26 i+* Re: Array size validity and SFINAE3Andrey Tarasevich
2 Mar 26 ii`* Re: Array size validity and SFINAE2Chris M. Thomasson
2 Mar 26 ii `- Re: Array size validity and SFINAE1Andrey Tarasevich
2 Mar 26 i`- Re: Array size validity and SFINAE1Bonita Montero
2 Mar 26 `* Re: Array size validity and SFINAE3Tim Rentsch
2 Mar 26  `* Re: Array size validity and SFINAE2Andrey Tarasevich
3 Mar 26   `- Re: Array size validity and SFINAE1Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal