[llvm-bugs] [Bug 27052] New: Error with C++11 uniform initialization of an array of type with explicit default constructor

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Mar 24 05:35:27 PDT 2016


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

            Bug ID: 27052
           Summary: Error with C++11 uniform initialization of an array of
                    type with explicit default constructor
           Product: clang
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mosra at centrum.cz
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

I am getting an error when compiling the following snippet:

    struct Explicit {
        explicit Explicit() {}
    };

    struct A {
        A(): _a{} {}

        Explicit _a[5];
    };

    int main() {}

Clang 3.7.1 complains that `error: chosen constructor is explicit in
copy-initialization`, both GCC 5.3 and MSVC 2015 compile fine. The behavior
differs when I make the following changes:

- If I remove the `explicit` keyword, it compiles fine (of course).
- If I make the `_a` member a non-array, it compiles fine.
- If I change `_a{}` to the C++03-style `_a()`, it compiles fine.
- If I change `_a{}` to `_a{Explicit{}, Explicit{}, Explicit{}, Explicit{},
Explicit{}}`, it compiles fine.
- If I change the constructor to `explicit Explicit() = default;`, it compiles
fine.

The problem is not just when using constructor initializer lists, but also when
initializing the array as a variable like this:

    Explicit b[5]{};

This behavior seems rather arbitrary to me and since the "old" C++03-style
works okay, I think it should have the same behavior in C++11.

This probably affects also older versions, didn't have a chance to test.

-- 
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/20160324/ae777f83/attachment.html>


More information about the llvm-bugs mailing list