[llvm-bugs] [Bug 33039] New: Class with a default constructible const member is not default constructible

via llvm-bugs llvm-bugs at lists.llvm.org
Mon May 15 07:46:55 PDT 2017


            Bug ID: 33039
           Summary: Class with a default constructible const member is not
                    default constructible
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: wellsd2 at rpi.edu
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

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:


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 at 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 at archway zero-parent-test]$ clang++ -std=c++11 -Wall -Wextra -Wpedantic
parent.cc:32:3: error: static_assert failed "TestChild"
  static_assert(std::is_default_constructible<TestChild>::value, "TestChild");
  ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.


#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<TestChild>::value, "TestChild");

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170515/0c9ce729/attachment-0001.html>

More information about the llvm-bugs mailing list