mardi 5 avril 2016

deleted non template function signature while a possible template candidate exists

The code below has two differents results if compiled with visual studio 2015 compared to clang and gcc.

The idea behind the deleted signature was to prevent the compiler to report a falsie error message about foo not taking two arguments by picking the 3 arguments one.

Clang and GCC does it well, but visual studio never consider the template version when foo is called with a legit char[N]. I know non template functions have a higher priority when solving best match overload, so i would say it is the right behavior even if it would not solve my original problem.

void  foo( char* dst, size_t len, char const* src)
void  foo( char * dst, char const*src ) = delete;
template <size_t size> void foo( char (&dest)[size], char const* src){}
int main() {
    char* unbound;
    char bound[32];
    foo(unbound,"ii"); // have to error at compile time in a better way than foo take 3 arguments
    foo(bound,"ii"); // have to work
}

Is anyone with a better understanding of the standard can highlight me with who is right here and why ?

Aucun commentaire:

Enregistrer un commentaire