<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 - Class with a default constructible const member is not default constructible"
   href="https://bugs.llvm.org/show_bug.cgi?id=33039">33039</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Class with a default constructible const member is not default constructible
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

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

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

        <tr>
          <th>Reporter</th>
          <td>wellsd2@rpi.edu
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>clang++ does not always mark classes with const members as default
constructible. Variants of this bug appear in older versions of clang (my
coworkers reported 3.4 and 3.7). The original context for this is here:

<a href="https://github.com/dealii/dealii/pull/4386">https://github.com/dealii/dealii/pull/4386</a>

The problem only seems to arise when a parent class has a user-defined default
constructor and the child class uses the implicitly generated constructor
(adding a user defined do-nothing default constructor, e.g., "Child() {}", to
the example below fixes compilation, but "Child() = default;" does not).

GCC compiles this program successfully.

terminal output:

[drwells@archway zero-parent-test]$ clang++ --version
clang version 4.0.0 (tags/RELEASE_400/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
[drwells@archway zero-parent-test]$ clang++ -std=c++11 -Wall -Wextra -Wpedantic
parent.cc
parent.cc:32:3: error: static_assert failed "TestChild"
  static_assert(std::is_default_constructible<TestChild>::value, "TestChild");
  ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

code:

#include <type_traits>

struct Parent
{
  Parent() : a {0.0}, b {1.0}
  {}

  double a;
  double b;
};

struct Child : public Parent
{};

class TestParent
{
  const Parent p;
};

class TestChild
{
  const Child c;
};

int main()
{
  static_assert(std::is_default_constructible<Parent>::value, "Parent");
  static_assert(std::is_default_constructible<Child>::value, "Child");

  const Child c;
  static_assert(std::is_default_constructible<TestParent>::value,
"TestParent");
  static_assert(std::is_default_constructible<TestChild>::value, "TestChild");
}</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>