Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Aggregate initialization

30 views
Skip to first unread message

Alf P. Steinbach

unread,
Oct 26, 2015, 1:45:51 PM10/26/15
to
On 10/26/2015 6:09 PM, Stefan Ram wrote:
> I am using a compiler that seems to be GCC 4.9.2 with »-std=c++14«.
>
> It reports an error on an example that was copied from 8.5.1p7:
>
> int main()
> { struct S { int a; const char* b; int c; int d = b[a]; };
> S ss = { 1, "asdf" }; }
>
> 3:22: error: could not convert '{1, "asdf"}' from '<brace-enclosed initializer list>' to 'main()::S'
> S ss = { 1, "asdf" }; }
> ^
>
> . Is it possible that this compiler does not consider
> classes with member initializers to be aggregates?
>

With MinGW g++ 5.1.0 I get the error you quote when using -std=c++11,
but, discounting warnings, it compiles with -std=c++14.

Visual C++ 2015 (version 19.00.23026 as reported by the compiler) does
not compile the code.

Upshot: this seems like a C++14 Microsoft-like feature (Microsoft-like:
something that some not very bright first-year student found useful in
one particular not very meaningful context, one would be forgiven for
calling it an idiot's device, and found a way to impose on everybody at
the cost of much else). Indeed the example you quote is there in the
C++14 standard, but not in the C++11 standard.


Cheers & hth.,

- Alf

Victor Bazarov

unread,
Oct 26, 2015, 2:45:14 PM10/26/15
to
On 10/26/2015 1:09 PM, Stefan Ram wrote:
> I am using a compiler that seems to be GCC 4.9.2 with »-std=c++14«.
>
> It reports an error on an example that was copied from 8.5.1p7:
>
> int main()
> { struct S { int a; const char* b; int c; int d = b[a]; };
> S ss = { 1, "asdf" }; }
>
> 3:22: error: could not convert '{1, "asdf"}' from '<brace-enclosed initializer list>' to 'main()::S'
> S ss = { 1, "asdf" }; }
> ^
>
> . Is it possible that this compiler does not consider
> classes with member initializers to be aggregates?
>
> I have this presumption because the following program
> is accepted without an error message:
>
> int main()
> { struct S { int a; const char* b; int c; int d; };
> S ss = { 1, "asdf" }; }
>
> .

Which element in the brace-enclosed initializer corresponds to the 'c'
member?

V
--
I do not respond to top-posted replies, please don't ask

Alf P. Steinbach

unread,
Oct 26, 2015, 3:13:26 PM10/26/15
to
In C++03 items following the last value in a brace initializer list are
zero-initialized. I guess that's so also for C++14. However, g++ warns
about the 'c' member being uninitialized, which is a weird warning if my
gut feeling about it is correct.

Cheers,

- Alf

mark

unread,
Oct 26, 2015, 4:49:17 PM10/26/15
to
On 2015-10-26 18:09, Stefan Ram wrote:
> I am using a compiler that seems to be GCC 4.9.2 with »-std=c++14«.
>
> It reports an error on an example that was copied from 8.5.1p7:
>
> int main()
> { struct S { int a; const char* b; int c; int d = b[a]; };
> S ss = { 1, "asdf" }; }
>
> 3:22: error: could not convert '{1, "asdf"}' from '<brace-enclosed initializer list>' to 'main()::S'
> S ss = { 1, "asdf" }; }
> ^
>
> . Is it possible that this compiler does not consider
> classes with member initializers to be aggregates?

This was changed with C++14 / n3653:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3653.html

n3653 requires GCC 5:
https://gcc.gnu.org/projects/cxx1y.html

Victor Bazarov

unread,
Oct 26, 2015, 5:02:32 PM10/26/15
to
On 10/26/2015 2:54 PM, Stefan Ram wrote:
> Victor Bazarov <v.ba...@comcast.invalid> writes:
>> On 10/26/2015 1:09 PM, Stefan Ram wrote:
>>> I have this presumption because the following program
>>> is accepted without an error message:
>>> int main()
>>> { struct S { int a; const char* b; int c; int d; };
>>> S ss = { 1, "asdf" }; }
>> Which element in the brace-enclosed initializer corresponds to the 'c'
>> member?
>
> No element in the brace-enclosed initializer list
> corresponds to the data member c.
>

Sorry, I was running on half-the-cylinders. Yours is an aggregate, at
least according to the latest draft I got, and I think you already
received a conclusive response from mark that you need the next version
of the compiler.

Vir Campestris

unread,
Oct 26, 2015, 5:35:04 PM10/26/15
to
On 26/10/2015 19:13, Alf P. Steinbach wrote:
> In C++03 items following the last value in a brace initializer list are
> zero-initialized. I guess that's so also for C++14. However, g++ warns
> about the 'c' member being uninitialized, which is a weird warning if my
> gut feeling about it is correct.

It annoys me intensely. I've got structures being initialised from
lists, and it warns me about any where the last fields are left to their
default constructors. The compiler people don't seem to see it as a problem.

Andy

woodb...@gmail.com

unread,
Oct 26, 2015, 6:39:17 PM10/26/15
to
Clang warns about it too:

warning: missing field 'revents' initializer
[-Wmissing-field-initializers]


I find it a little annoying, but add the extra stuff
inside the braces and then forget about it.

Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net
0 new messages