c++11 - temporary objects with variadic template arguments; another g++/clang++ difference -


the following code

struct foo  {    foo ()     { }     template <typename t0, typename ... ts>       foo (const t0 & t0, const ts & ... ts)         { foo(ts...); }  };  int main()  {    foo f(1, 2);     return 0;  } 

compile without problems g++ (4.9.2) , give following errors

tmp_002-11,14,gcc,clang.cpp:9:16: error: expected ')'        { foo(ts...); }                ^ tmp_002-11,14,gcc,clang.cpp:9:13: note: match '('        { foo(ts...); }             ^ tmp_002-11,14,gcc,clang.cpp:9:14: error: redefinition of 'ts'            { foo(ts...); }              ^ tmp_002-11,14,gcc,clang.cpp:8:42: note: previous definition here       foo (const t0 & t0, const ts & ... ts)                                           ^ 2 errors generated. 

with clang++ (3.5).

as usual question is: who's right?

--- edit ---

clarification: know foo(ts...) can't call delegate constructor (i think can be) construction of temporary foo object (another foo object).

but, pointed vsoftco, what's happening when sizeof...(ts) == 1u?

in case, foo(ts...); (re)declaration of single variable ts (so, suppose, should right clang++) or variadic syntax avoid problem (so, suppose, should right g++)?

there c++11 standard experts can clarify this?

p.s.: sorry bad english.

this looks clang bug. here's minimal reproduction:

template <typename ... ts> void foo (ts ... ts) {     int(ts...); } 

(there's no need instantiate template).

judging error messages, clang interprets int(ts...); declaration, cannot be, because (ts...) cannot declarator.

one ask: when ts... parameter pack of size one, shouldn't parsed ts , cause whole construct interpreted declaration? answer no.

there syntactic ambiguity in c++ grammar between "declaration" , "expression-statement" productions. if ambiguous construct can parsed "declaration", "declaration". int(ts...) cannot parsed such, because grammar not have productions needed such parse. once construct classified expression statement, , not before that, can interpret ts... parameter pack , calculate sizeof...(ts). if construct not classified expression, sizeof...(ts) has no meaning @ all, because ts... has no meaning, such syntax cannot in declaration.

once established int(ts...); expression statement , not declaration, 1 may interpret , instantiate relevant templates , expand parameter packs. @ point it's late go , claim declaration along, based on fact sizeof...(ts) == 1. 1 not possibly deduce sizeof...(ts) == 1 if declaration (ts wouldn't parameter pack then).

moreover, clang seemingly insinuates not syntactically correct declaration. 1 cannot possibly derive facts sizeof...(ts) == 1 out of not syntactically correct.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -