<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Union with variant member with non-trivial default constructor but another variant member has a default member initializer with deleted default constructor"
   href="https://bugs.llvm.org/show_bug.cgi?id=39686">39686</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Union with variant member with non-trivial default constructor but another variant member has a default member initializer with deleted default constructor
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++14
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>yaghmour.shafik@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Given the following code which is a more minimal example taken from this
Stackoveflow question <a href="https://stackoverflow.com/q/53310690/1708801">https://stackoverflow.com/q/53310690/1708801</a>

struct X {
  X() {}        //non-trivial default constructor
};

union U {
    X x;
    int i{};   //default member initializer
};

void foo() {
    U u;
}

clang gives the following diagnostic <a href="https://godbolt.org/z/6oTJ01">https://godbolt.org/z/6oTJ01</a> :

call to implicitly-deleted default constructor of 'U'
    U u;
      ^

note: default constructor of 'U' is implicitly deleted because variant field
'x' has a non-trivial default constructor
    X x;
      ^


but [class.default.ctor]p2 <a href="http://eel.is/c++draft/class.default.ctor#2.1">http://eel.is/c++draft/class.default.ctor#2.1</a> says:

  A defaulted default constructor for class X is defined as deleted if:
  - X is a union that has a variant member with a non-trivial default
constructor and no variant member of X has a default member initializer,

U does have a member with a default member initializer so the default
constructor should not be deleted and this should be well-formed.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>