public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55778] New: Variadic template extension possibly wrong
@ 2012-12-21 17:46 koala01 at free dot fr
  2012-12-21 18:38 ` [Bug c++/55778] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: koala01 at free dot fr @ 2012-12-21 17:46 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55778

             Bug #: 55778
           Summary: Variadic template extension possibly wrong
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: koala01@free.fr


with the code
#include <string>
#include <iostream>
template<typename ...Args>
void foo(Args ... args)
{
    std::cout<<"stopping with "<<sizeof...(args)<< " unused
arguments"<<std::endl;
}
template<typename ...Args>
void foo(int i, Args ... args)
{
    std::cout<<"using i = "<<i
             <<", left "<<sizeof...(args)<<" argument more"<<std::endl;
    foo(args...);
}
template<typename ... Args>
void foo(std::string const & s, Args...args)
{
    std::cout<<"using the "<<s<<" string, left "
             <<sizeof...(args)<<" argument more"<<std::endl;
    foo(args...);
}
int main()
{

    foo<int, int,int, int, std::string , int, int >(1, 2, 3, 4,5 ,
                                                   "hello", 6, 7 );
    return 0;
}

we get a result like
using i = 1, left 7 argument more
using i = 2, left 6 argument more
using i = 3, left 5 argument more
using i = 4, left 4 argument more
using i = 5, left 3 argument more
stopping with 3 unused arguments

but we could expect a result like 

using i = 1, left 7 argument more
using i = 2, left 6 argument more
using i = 3, left 5 argument more
using i = 4, left 4 argument more
using i = 5, left 3 argument more
using the hello string, left 2 argument more
using i = 6, left 1 argument more
using i = 7, left 0 argument more
stopping with 0 unused arguments

just like with the code 

#include <iostream>
#include <string>
template<typename ...Args>
void foo(int i, Args ... args);
template<typename ...Args>
void foo(std::string const & s, Args...args);
template<typename ...Args>
void foo(Args ... args)
{
    std::cout<<"stopping with "<<sizeof...(args)<< " unused
arguments"<<std::endl;
}
template<typename ... Args>
void foo(std::string const & s, Args...args)
{
    std::cout<<"using the "<<s<<" string, left "
             <<sizeof...(args)<<" argument more"<<std::endl;
    foo(args...);
}
template<typename ...Args>
void foo(int i, Args ... args)
{
    std::cout<<"using i = "<<i
             <<", left "<<sizeof...(args)<<" argument more"<<std::endl;
    foo(args...);
}
int main()
{

    foo<int, int,int, int, std::string , int, int >(1, 2, 3, 4,5 ,
                                                   "hello", 6, 7 );
    return 0;
}

Am i wrong ?


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-12-21 21:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-21 17:46 [Bug c++/55778] New: Variadic template extension possibly wrong koala01 at free dot fr
2012-12-21 18:38 ` [Bug c++/55778] " redi at gcc dot gnu.org
2012-12-21 19:17 ` koala01 at free dot fr
2012-12-21 19:43 ` redi at gcc dot gnu.org
2012-12-21 19:57 ` koala01 at free dot fr
2012-12-21 21:05 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).