Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's a bug, at least in C++03 (not sure about C++11).</p> <p>According to the overload resolution rules in C++03 §13.3.1.2, the built-in <code>||</code> operator is selected, since no user-defined <code>||</code> operator is defined for <code>S</code>.</p> <p>§5.15/1 says:</p> <blockquote> <p>The <code>||</code> operator groups left-to-right. The operands are both implicitly converted to <code>bool</code> (clause 4). [...]</p> </blockquote> <p>§12.3/2 says:</p> <blockquote> <p>User-defined conversions are applied only where they are unambiguous (10.2, 12.3.2). [...]</p> </blockquote> <p>§12.3/5:</p> <blockquote> <p>User-defined conversions are used implicitly only if they are unambiguous. [...] Function overload resolution (13.3.3) selects the best conversion function to perform the conversion.</p> </blockquote> <p>§13.3.2/3:</p> <blockquote> <p>Second, for <code>F</code> to be a viable function, there shall exist for each argument an implicit conversion sequence (13.3.3.1) that converts that argument to the corresponding parameter of <code>F</code>.</p> </blockquote> <p>Clearly <code>S</code> defines a user-defined conversion to <code>bool</code>. The built-in <code>||</code> operator is a viable function for the overload resolution, and since it's the only one, it's the best. So the expression is well-formed.</p> <p>Also of note is §4/3, which says:</p> <blockquote> <p>An expression <code>e</code> can be implicitly converted to a type <code>T</code> if and only if the declaration “<code>T t=e;</code>” is well- formed, for some invented temporary variable <code>t</code> (8.5). [...]</p> </blockquote> <p>So I'm curious whether Visual Studio also produces an error for the statement <code>bool b = S();</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload