Zero-initialization and explicit constructors

Hi,
I would like to ask about the difference in behavior of C++11 explicit constructors, between Clang/LLVM 3.4 and current trunk version (3.5). The following:

#include <stdio.h>
struct Inner {
explicit Inner() {}
};
struct Outer {
Inner member;
};
int main() {
Outer s = {};
printf("%p\n", &s); // just to silence “unused variable” warning
return 0;
}

compiles fine with Clang 3.4 using “clang++ -std=c++11 -Wall -Wpedantic”, however using trunk version, this gives me “chosen constructor is explicit in copy-initialization” error. Is this the right (intended) behavior? How can you zero-initialize such an object? I mean “Outer s = Outer{}” doesn’t compile either.

Thanks,
Kuba

Hi,
I would like to ask about the difference in behavior of C++11 explicit
constructors, between Clang/LLVM 3.4 and current trunk version (3.5). The
following:

  #include <stdio.h>
  struct Inner {
    explicit Inner() {}
  };
  struct Outer {
    Inner member;
  };
  int main() {
    Outer s = {};
    printf("%p\n", &s); // just to silence "unused variable" warning
    return 0;
  }

compiles fine with Clang 3.4 using "clang++ -std=c++11 -Wall -Wpedantic",
however using trunk version, this gives me "chosen constructor is explicit
in copy-initialization" error. Is this the right (intended) behavior?

Yes. This reflects a recent bugfix to the C++ specification. Note that:

  Inner s = {};

was rejected before and after this change, as was

  Inner s = { {} };

How can you zero-initialize such an object? I mean "Outer s = Outer{}"
doesn't compile either.

  Outer s = Outer();

should work. In this case,

  Outer s;

should work fine too.