[llvm-bugs] [Bug 39686] New: Union with variant member with non-trivial default constructor but another variant member has a default member initializer with deleted default constructor

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Nov 15 21:57:20 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=39686

            Bug ID: 39686
           Summary: Union with variant member with non-trivial default
                    constructor but another variant member has a default
                    member initializer with deleted default constructor
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++14
          Assignee: unassignedclangbugs at nondot.org
          Reporter: yaghmour.shafik at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Given the following code which is a more minimal example taken from this
Stackoveflow question https://stackoverflow.com/q/53310690/1708801

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 https://godbolt.org/z/6oTJ01 :

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 http://eel.is/c++draft/class.default.ctor#2.1 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.

-- 
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/20181116/77b7a5ef/attachment.html>


More information about the llvm-bugs mailing list