Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #581

Re: Variadic template parameter pack matching non-pack parameters

Message-ID <kcsfns$gnd$1@dont-email.me> (permalink)
Newsgroups comp.std.c++
From Daniel Krügler <daniel.kruegler@googlemail.com>
Subject Re: Variadic template parameter pack matching non-pack parameters
Organization A noiseless patient Spider
References <kcd5vj$n3k$1@dont-email.me>
Date 2013-01-13 14:33 -0600

Show all headers | View raw


Am 12.01.2013 20:23, schrieb Sylvester Hesp:
> I was playing around with the November '12 CTP preview of the VC++11
> compiler, which includes an implementation of variadic templates, and
> something interesting caught my eye.
>
> Consider the following program:
>
> ===================
> template<class T, class U>
> struct Foo { };
>
> template<class... Args>
> void Bar(Foo<Args...> f)
> {
> }
>
> template<class... Args>
> void Baz()
> {
>      Foo<Args...> f;
> }
>
> int main()
> {
>      Foo<int, float> f;
>      Bar(f);                    // #1
>      Bar<int, float>(f);        // #2
>      Baz<int, float>(f);        // #3

Given the definition of function Baz() above how on earth should #3
work? Did you intent to write

Baz<int, float>();         // #3

instead?

> }
> ===================
>
> This fails to compile using both VC++11 and GCC 4.6.3 (unfortunately I
> was not able to test a more recent version). VC++ in particular reports
> these errors:
>
> ===================
> test1.cpp(5): error C2976: 'Foo' : too few template arguments
>           test1.cpp(2) : see declaration of 'Foo'
> test1.cpp(18): error C2664: 'void Bar<>(Foo)' : cannot convert
> parameter 1 from 'Foo<int,float>' to 'Foo'
>           No user-defined-conversion operator available that can
> perform this conversion, or the operator cannot be called
> test1.cpp(20): error C2780: 'void Baz(void)' : expects 0 arguments - 1
> provided
>           test1.cpp(10) : see declaration of 'Baz'
> ===================

Its clear that #3 cannot work, but except from that the code should be
accepted. Looks like a compiler defect to me.

> My first reasoning was that I was simply hitting a compiler bug in
> VC++, but then I found out that GCC reported similar errors.

I have no gcc 4.6 here (it is rather out-aged), but current gcc 4.8
except the code except for #3.

> Am I right in asserting that, based on above paragraphs, the program is
> in fact well-formed C++11, and it just so happens that both VC++ as GCC
> have a bug in this regard?

I would suggest to submit a bug report to VC++. I don't think its worth
sending one for gcc, to my knowledge such fixes will not be applied in 4.6.

HTH & Greetings from Bremen,

Daniel Krügler



-- 
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Variadic template parameter pack matching non-pack parameters Sylvester Hesp <usenet@oisyn.nl> - 2013-01-12 11:23 -0800
  Re: Variadic template parameter pack matching non-pack parameters Daniel Krügler <daniel.kruegler@googlemail.com> - 2013-01-13 14:33 -0600
  Re: Variadic template parameter pack matching non-pack parameters "terminator(jam)" <farid.mehrabi@googlemail.com> - 2013-04-02 15:56 -0700
    Re: Variadic template parameter pack matching non-pack parameters Daniel Krügler <daniel.kruegler@googlemail.com> - 2013-04-04 19:05 -0600

csiph-web