This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


493. Type deduction from a bool context

Section: 13.10.3.4  [temp.deduct.conv]     Status: CD2     Submitter: John Spicer     Date: 17 Dec 2004

[Voted into WP at March, 2010 meeting.]

An expression used in an if statement is implicitly converted to type bool (8.5 [stmt.select]). According to the rules of template argument deduction for conversion functions given in 13.10.3.4 [temp.deduct.conv], the following example is ill-formed:

    struct X {
      template<class T> operator const T&() const;
    };
    int main()
    {
      if( X() ) {}
    }

Following the logic in 13.10.3.4 [temp.deduct.conv], A is bool and P is const T (because cv-qualification is dropped from P before the reference is removed), and deduction fails.

It's not clear whether this is the intended outcome or not.

Notes from the April, 2005 meeting:

The CWG observed that there is nothing special about either bool or the context in the example above; instead, it will be a problem wherever a copy occurs, because cv-qualification is always dropped in a copy operation. This appears to be a case where the conversion deduction rules are not properly symmetrical with the rules for arguments. The example should be accepted.

Proposed resolution (February, 2010):

This issue is resolved by the resolution of issue 976.