[cfe-dev] Zero-initialization and explicit constructors
Richard Smith
richard at metafoo.co.uk
Fri Jun 27 08:30:57 PDT 2014
On Mon, Jun 23, 2014 at 10:51 AM, Kuba Břečka <kuba.brecka at gmail.com> wrote:
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140627/5b0c9f50/attachment.html>
More information about the cfe-dev
mailing list