This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: gcc interprets C++0x initialization construct as function declarationâ
- From: Jeffrey Walton <noloader at gmail dot com>
- To: Nathan Ridge <zeratul976 at hotmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 4 Jan 2011 19:30:40 -0500
- Subject: Re: gcc interprets C++0x initialization construct as function declarationâ
- References: <BLU162-w121954B8D71C62561A140096080@phx.gbl>
- Reply-to: noloader at gmail dot com
2011/1/4 Nathan Ridge <zeratul976@hotmail.com>:
>
>
> Hello,
>
> For the following code:
>
> struct S
> {
> ? ?int a;
> ? ?float b;
> };
>
> struct T
> {
> ? ?T(S s) {}
> };
>
> int main()
> {
> ? ?T t(S{1, 0.1}); // ERROR HERE
> }
>
> gcc 4.6 trunk gives the following errors (with the --std=c++0x option):
>
> decl.cpp: In function 'int main()':
> decl.cpp:14:10: error: expected ')' before '{' token
> decl.cpp:14:10: error: a function-definition is not allowed here before '{' token
> decl.cpp:14:18: error: expected primary-expression before ')' token
> decl.cpp:14:18: error: expected ';' before ')' token
>
> It seems gcc is interpreting the statement as a function declaration.
>
> Is this the desired behaviour?
Try T t(S(1, 0.1));
I'm not sure C++0X would help (see Intializer Lists at
http://www2.research.att.com/~bs/C++0xFAQ.html)
Jeff