Open
Description
When compiling the following, Clang does not consider the default arguments provided by the declaration marked (A)
: https://godbolt.org/z/8Gxb3fvPz
The Clang behaviour is inconsistent with CWG's interpretation (during the 2025-04-11 teleconference) of https://wg21.link/dcl.fct.default#9.sentence-9:
When an overload set contains a declaration of a function that inhabits a scope S, any default argument associated with any reachable declaration that inhabits S is available to the call.
That is, although no argument-dependent lookup takes place for the case in question, the default arguments in play are extended to ones provided by redeclarations of the functions that were candidates in the template definition context.
Source (<stdin>
)
constexpr int f(int *, int) { return 42; }
constexpr int f(void *) { return 13; }
template <typename T>
constexpr int g() {
return f(T{});
}
constexpr int f(int *, int = 0); // (A)
static_assert(g<int *>() == 42, "");
Compiler invocation
clang++ -fsyntax-only -Wall -Wextra -pedantic -std=c++11 -xc++ -
Actual output
<stdin>:11:15: error: static assertion failed due to requirement 'g<int *>() == 42':
11 | static_assert(g<int *>() == 42, "");
| ^~~~~~~~~~~~~~~~
<stdin>:11:26: note: expression evaluates to '13 == 42'
11 | static_assert(g<int *>() == 42, "");
| ~~~~~~~~~~~^~~~~
1 error generated.
Expected output
(Clean compile)
Compiler version info (clang++ -v
)
clang version 21.0.0git (https://github.com/llvm/llvm-project.git 9466cbdf29306b2595303dac5b62b54cf71841b4)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/wandbox/clang-head/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/13
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Candidate multilib: .;@m64
Selected multilib: .;@m64