Skip to content

Error with C++11 uniform initialization of an array of type with explicit default constructor #27426

@llvmbot

Description

@llvmbot
Bugzilla Link 27052
Version 3.7
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor

Extended Description

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++11clang:frontendLanguage frontend issues, e.g. anything involving "Sema"invalidResolved as invalid, i.e. not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions