public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/45873] New: Parameter packs not expanding consistently in function return types
@ 2010-10-03 15:55 sausage at tehsausage dot com
2010-10-04 8:11 ` [Bug c++/45873] " redi at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: sausage at tehsausage dot com @ 2010-10-03 15:55 UTC (permalink / raw)
To: gcc-bugs
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>
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/45873] Parameter packs not expanding consistently in function return types
2010-10-03 15:55 [Bug c++/45873] New: Parameter packs not expanding consistently in function return types sausage at tehsausage dot com
@ 2010-10-04 8:11 ` redi at gcc dot gnu.org
2011-05-16 12:28 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2010-10-04 8:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45873
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |4.4.3, 4.5.1, 4.6.0
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2010-10-04 08:11:07 UTC ---
(You didn't say which version this PR is for, although it doesn't work with any
I tried)
Here's a self-contained testcase, with a fix so the workaround actually works
(it was missing the template argument on baz<pair>)
template<class, class>
struct pair
{
template<class T1, class U1>
pair(T1&& t, U1&& u) { }
};
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...); }
// 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()
{
// error: no matching function for call to 'foo(int, double)'
foo<pair>(1, 2.0);
bar<pair>(1, 2.0); // OK, returns pair<int, double>
baz<pair>(1, 2.0); // OK, returns pair<int, double>
}
I think deduction fails for foo<pair>(1, 2.0), though I'm not sure if it
should.
For baz<pair> deduction succeeds, the template parameters appear in a
nested-name-specifier which is a non-deduced context.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/45873] Parameter packs not expanding consistently in function return types
2010-10-03 15:55 [Bug c++/45873] New: Parameter packs not expanding consistently in function return types sausage at tehsausage dot com
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
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2011-05-16 12:28 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45873
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-05-16 12:01:31 UTC ---
Jason, should deduction succeed here?
template<class, class>
struct pair
{
template<class T1, class U1>
pair(T1&& t, U1&& u) { }
};
template <template <class...> class T, class ...Args>
auto foo(Args... args) -> T<Args...>
{ return T<Args...>(args...); }
int main()
{
// error: no matching function for call to 'foo(int, double)'
foo<pair>(1, 2.0);
}
It looks as though substituting T=pair fails because T's single parameter pack
fails to match pair's two parameters.
If pair is a variadic template with exactly one parameter pack , like p0 below,
then it matches T:
template<class...> struct p0 { };
template<class, class...> struct p1 { };
template<class, class, class...> struct p2 { };
template <template <class...> class T, class ...Args>
auto foo(Args... args) -> T<Args...>
{ return T<Args...>(); }
int main()
{
foo<p0>(1, 2.0); // ok
foo<p1>(1, 2.0); // error
foo<p2>(1, 2.0); // error
}
Is this behaviour correct?
Clang accepts all three calls
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/45873] Parameter packs not expanding consistently in function return types
2010-10-03 15:55 [Bug c++/45873] New: Parameter packs not expanding consistently in function return types sausage at tehsausage dot com
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
4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2011-05-16 16:34 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45873
--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2011-05-16 15:42:36 UTC ---
This seems like a dup of 35722.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/45873] Parameter packs not expanding consistently in function return types
2010-10-03 15:55 [Bug c++/45873] New: Parameter packs not expanding consistently in function return types sausage at tehsausage dot com
` (2 preceding siblings ...)
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
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2011-05-16 17:40 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45873
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-05-16 17:04:12 UTC ---
(In reply to comment #3)
> This seems like a dup of 35722.
Ah yes, it definitely is for the call to foo<p1> in my second example in
comment 2: modifying pt.c to always complain at the FIXME in
coerce_template_parms produces the "sorry" for the call to foo<p1>
45873.c2.cc: In function 'int main()':
45873.c2.cc:14:18: sorry, unimplemented: cannot expand 'Args ...' into a
fixed-length argument list
45873.c2.cc:14:18: error: no matching function for call to 'foo(int, double)'
45873.c2.cc:14:18: note: candidate is:
45873.c2.cc:8:6: note: template<template<class ...> class T, class ... Args>
T<Args ...> foo(Args ...)
45873.c2.cc:15:18: error: no matching function for call to 'foo(int, double)'
45873.c2.cc:15:18: note: candidate is:
45873.c2.cc:8:6: note: template<template<class ...> class T, class ... Args>
T<Args ...> foo(Args ...)
But that "sorry" isn't reached for foo<p2> or for any foo<pair> in the other
testcases.
I don't know if that means something else is going on there, or if it's just an
undiagnosed case of the same situation.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/45873] [C++0x] Parameter packs not expanding consistently in function return types
2010-10-03 15:55 [Bug c++/45873] New: Parameter packs not expanding consistently in function return types sausage at tehsausage dot com
` (3 preceding siblings ...)
2011-05-16 17:40 ` redi at gcc dot gnu.org
@ 2012-04-16 2:11 ` jason at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: jason at gcc dot gnu.org @ 2012-04-16 2:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45873
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
Target Milestone|--- |4.7.0
--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> 2012-04-16 02:10:37 UTC ---
Works in 4.7.
*** This bug has been marked as a duplicate of bug 35722 ***
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-04-16 2:11 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-03 15:55 [Bug c++/45873] New: Parameter packs not expanding consistently in function return types sausage at tehsausage dot com
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
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).