public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "sausage at tehsausage dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/45873] New: Parameter packs not expanding consistently in function return types
Date: Sun, 03 Oct 2010 15:55:00 -0000	[thread overview]
Message-ID: <bug-45873-4@http.gcc.gnu.org/bugzilla/> (raw)

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

           Summary: Parameter packs not expanding consistently in function
                    return types
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: sausage@tehsausage.com


Non-variadic templates passed to a function as "template <class ...> class"
have inconsistent behavior when provided with a parameter pack as an argument
and used as a return type than when used in the body of the function in the
same way. I am unsure on the expected behavior or whether passing templates in
such a way is even allowed.


template <template <class ...> class T, class ...Args>
auto foo(Args... args) -> T<Args...>
{ return T<Args...>(args...); }

template <template <class ...> class T, class ...Args>
auto bar(Args... args) -> T<int, double>
{ return T<Args...>(args...); }

int main()
{
   foo<pair>(1, 2.0); // error: no matching function for call to 'foo(int,
double)'
   bar<pair>(1, 2.0); // OK, returns pair<int, double>
}


The following work-around seems to work:

template <template <class ...> class T, class ...Args> struct expand
{ typedef T<Args...> type; };

template <template <class ...> class T, class ...Args>
auto baz(Args... args) -> typename expand<T, Args...>::type
{ return T<Args...>(args...); }

int main()
{
   baz(1, 2.0); // OK, returns pair<int, double>
}


             reply	other threads:[~2010-10-03 15:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-03 15:55 sausage at tehsausage dot com [this message]
2010-10-04  8:11 ` [Bug c++/45873] " redi at gcc dot gnu.org
2011-05-16 12:28 ` redi at gcc dot gnu.org
2011-05-16 16:34 ` jason at gcc dot gnu.org
2011-05-16 17:40 ` redi at gcc dot gnu.org
2012-04-16  2:11 ` [Bug c++/45873] [C++0x] " jason at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-45873-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).