Skip to content

clang++: Surprising SFINAE behavior for default function argumentsΒ #63391

@akrzemi1

Description

@akrzemi1

Clang 16 fails to compile the following program due to malformed default function argument:

template <typename U>
int fun(U u = U::value);

template <class T>
decltype(fun<T>()) test(int) { return 2; }

template<class> 
int test(long) { return 3; }

int main() { 
    return test<int>(0);
}

GCC and MSVC compile the program that returns value 3. ICX exposes the same behavior as Clang. I would expect the GCC behavior.

  1. Either the formation of the default function argument is not in the immediate context, and in this case there is no need to form the value: it should be enough to say that some default value would be produced (program would return 2),
  2. Or it should be in the immediate context, and in this case the program should correctly diagnose that fun<T>() is invalid expression, substitution should fail, and the program should return 3.

Or am I mising something here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions