<div dir="ltr">Hi,<div><br></div><div>I was experimenting some code and I incurred in an unexpected error.</div><div>I reduce the code to the minimal case:</div><div><br></div><div><div>template <class T></div><div>struct MyStruct {</div><div><span class="" style="white-space:pre"> </span>operator float* ()<span style="white-space:pre"> </span>{<span style="white-space:pre"> </span>return 0;<span style="white-space:pre"> </span>}</div><div><span class="" style="white-space:pre"> </span>operator T* () { return 0;<span style="white-space:pre"> </span>}</div><div>};</div><div>void func(bool) {}<br></div><div>void func(int*) {}</div><div>int main() {</div><div><span class="" style="white-space:pre"> </span>MyStruct<int> x;</div><div><span class="" style="white-space:pre"> </span>func(x);</div><div>}</div></div><div><br></div><div>Compiling the previous code result in an error with both GCC and Clang (latest version from code and 3.5 in Archlinux)</div><div><br></div><div><div>test.cpp:51:2: error: call to 'func' is ambiguous</div><div>    func(x);</div><div>    ^~~~</div><div>test.cpp:45:6: note: candidate function</div><div>void func(bool) {}</div><div>   ^</div><div>test.cpp:46:6: note: candidate function</div><div>void func(int*) {}</div><div>   ^</div><div>1 error generated.</div></div><div><br></div><div>The same error can be triggered with a template <class T> operator T* () and using function template argument deduction.</div><div><br></div><div>MSC, instead, select func(int*) in all versions from VS2010 to VS2013 CTP 3.</div><div><br></div><div>Now, I was wondering which one is the expected behaviour according to the standard.</div><div>From 13.3.3 (Best Viable Function):</div><div><br></div><div><div>— the context is an initialization by user-defined conversion (see 8.5, 13.3.1.5, and 13.3.1.6) and the</div><div>  standard conversion sequence from the return type of F1 to the destination type (i.e., the type of the</div><div>  entity being initialized) is a better conversion sequence than the standard conversion sequence from</div><div>  the return type of F2 to the destination type</div></div><div><br></div><div>In this case both the function call require user defined conversion.</div><div><br></div><div>The one using non-template parameter yield to a standard conversion sequence of type boolean conversion (4.12).</div><div><br></div><div>The UDC with a template parameter should resolve in a user defined conversion followed by a standard conversion of identity type (exact match).</div><div><br></div><div>Intuitively I would expect this second conversion to be considered a better match than the latter one and be selected.</div><div><br></div><div>Far from being a language expert, I wonder if I'm misreading the standard (or missing something) or if indeed this a bug in clang.</div><div><br></div><div>Thanks in advance for the answer,</div><div>Samuele</div><div><br></div></div>