[cfe-dev] Zero-initialization and explicit constructors

Kuba Břečka kuba.brecka at gmail.com
Mon Jun 23 10:51:27 PDT 2014


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140623/c71f99d4/attachment.html>


More information about the cfe-dev mailing list