Date: Mon, 13 Jul 2026 22:40:44 +0200
On 7/12/26 08:50, SD SH via Std-Discussion wrote:
> Hi.
>
> 1. Intro
>
> ```
> template<typename...>
> void foo() { }
>
> auto _ = &foo; // is it OK?
> ```
>
> GCC, Clang and MSVC have different results of it:
> GCC: [success]
> Clang: error: variable '_' with type 'auto' has incompatible initializer of type '<overloaded function type>'
> MSVC: error C3535: cannot deduce type for 'auto' from 'overloaded-function'
>
> 2. My Opinion
>
> The type of `_` is `decltype(&foo)` [a],
Right, placeholder type deduction is applied, but the process is different
than just saying "it's decltype(x)". [dcl.type.auto.deduct] p4 doesn't apply.
> `&foo` can be deduced as `&foo<>` here [b], and have a unique function.
I don't think [temp.arg.explicit] is relevant here; there are no explicit
template arguments. Note that we do placeholder deduction for the target
type first and then we do deduction as described in [over.over].
> By the text of Standard, seems it is well-formed, or I made some mistakes on it.
Please re-read the rules, and try the rewrite in [dcl.type.auto.deduct] p3
explicitly.
> The compilers didn't have the same behaviors. Is the code correct?
> 3. Compilers Have Different Behaviors of Same Expressions
> The 3 compilers all accepted these code:
> ```
> template<typename...>
> int foo(void) { return 0; }
>
> auto _ = (&foo)();
> ```
> It shows that all the compilers can accept `&foo` as `&foo<>`.
> If it is true, both Clang and MSVC has different behaviors of the expression `&foo`.
>
> While the 3 compilers all rejected these code:
> ```
> template<typename...>
> int foo(void) { return 0; }
>
> using X = decltype(&foo);
> ```
> So, GCC also has different behaviors of the expression `&foo`.
>
> Overall, all of GCC, MSVC and Clang has different behaviors of the expression `&foo`.
> I doubt the all these compilers didn't follow the Standard, or the Standard itself have ambiguities in some places.
We have recently clarified the rules in [over.over]; maybe compilers haven't caught up.
Please consider posting bug reports to the compiler vendors.
Jens
> Hi.
>
> 1. Intro
>
> ```
> template<typename...>
> void foo() { }
>
> auto _ = &foo; // is it OK?
> ```
>
> GCC, Clang and MSVC have different results of it:
> GCC: [success]
> Clang: error: variable '_' with type 'auto' has incompatible initializer of type '<overloaded function type>'
> MSVC: error C3535: cannot deduce type for 'auto' from 'overloaded-function'
>
> 2. My Opinion
>
> The type of `_` is `decltype(&foo)` [a],
Right, placeholder type deduction is applied, but the process is different
than just saying "it's decltype(x)". [dcl.type.auto.deduct] p4 doesn't apply.
> `&foo` can be deduced as `&foo<>` here [b], and have a unique function.
I don't think [temp.arg.explicit] is relevant here; there are no explicit
template arguments. Note that we do placeholder deduction for the target
type first and then we do deduction as described in [over.over].
> By the text of Standard, seems it is well-formed, or I made some mistakes on it.
Please re-read the rules, and try the rewrite in [dcl.type.auto.deduct] p3
explicitly.
> The compilers didn't have the same behaviors. Is the code correct?
> 3. Compilers Have Different Behaviors of Same Expressions
> The 3 compilers all accepted these code:
> ```
> template<typename...>
> int foo(void) { return 0; }
>
> auto _ = (&foo)();
> ```
> It shows that all the compilers can accept `&foo` as `&foo<>`.
> If it is true, both Clang and MSVC has different behaviors of the expression `&foo`.
>
> While the 3 compilers all rejected these code:
> ```
> template<typename...>
> int foo(void) { return 0; }
>
> using X = decltype(&foo);
> ```
> So, GCC also has different behaviors of the expression `&foo`.
>
> Overall, all of GCC, MSVC and Clang has different behaviors of the expression `&foo`.
> I doubt the all these compilers didn't follow the Standard, or the Standard itself have ambiguities in some places.
We have recently clarified the rules in [over.over]; maybe compilers haven't caught up.
Please consider posting bug reports to the compiler vendors.
Jens
Received on 2026-07-13 20:40:51
