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

2024-10-26


1336. Definition of “converting constructor”

Section: 11.4.8.2  [class.conv.ctor]     Status: CD3     Submitter: Niels Dekker     Date: 2011-07-03

[Voted into the WP at the February, 2012 meeting; moved to DR at the October, 2012 meeting.]

Although the normative wording of 11.4.8.2 [class.conv.ctor] paragraph 1 defining a converting constructor says

A constructor declared without the function-specifier explicit specifies a conversion from the types of its parameters to the type of its class.

implying that a constructor with multiple parameters can be a converting constructor, it would be helpful if the example contained such a constructor.

Proposed resolution (August, 2011):

  1. Change the example in 11.4.8.2 [class.conv.ctor] paragraph 1 as follows:

  2.   struct X {
          X(int);
          X(const char*, int =0);
          X(int, int);
      };
    
      void f(X arg) {
        X a = 1;          // a = X(1)
        X b = "Jessie";   // b = X("Jessie",0)
        a = 2;            // a = X(2)
        f(3);             // f(X(3))
        f({1, 2});        // f(X(1,2))
      }
    
  3. Change the example in 11.4.8.2 [class.conv.ctor] paragraph 2 as follows:

  4.   struct Z {
        explicit Z();
        explicit Z(int);
        explicit Z(int, int);
      };
    
      Z a;                       // OK: default-initialization performed
      Z a1 = 1;                  // error: no implicit conversion
      Z a3 = Z(1);               // OK: direct initialization syntax used
      Z a2(1);                   // OK: direct initialization syntax used
      Z* p = new Z(1);           // OK: direct initialization syntax used
      Z a4 = (Z)1;               // OK: explicit cast used
      Z a5 = static_cast<Z>(1);  // OK: explicit cast used
      Z a6 = { 3, 4 };           // error: no implicit conversion