public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/40127] Fails to identify template function with default args
[not found] <bug-40127-4@http.gcc.gnu.org/bugzilla/>
@ 2012-01-15 20:27 ` pinskia at gcc dot gnu.org
2012-01-15 23:26 ` redi at gcc dot gnu.org
1 sibling, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-01-15 20:27 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40127
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-01-15 20:01:35 UTC ---
This code is invalid (and other compilers agree with me). What type is going
to be chosen for T? void*, int*, any pointer type? There is no way the
compiler can deduce the type of T from the arguments.
This code is valid though:
template<typename T>
void foo(int i, void(*f)(T*) = 0, T* a = 0) {}
int main() {
foo<void>(5);
return 0;
}
AS the compiler does not need to deduce the template argument type.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/40127] Fails to identify template function with default args
[not found] <bug-40127-4@http.gcc.gnu.org/bugzilla/>
2012-01-15 20:27 ` [Bug c++/40127] Fails to identify template function with default args pinskia at gcc dot gnu.org
@ 2012-01-15 23:26 ` redi at gcc dot gnu.org
1 sibling, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2012-01-15 23:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40127
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-01-15 23:16:53 UTC ---
(In reply to comment #0)
> I'm not sure whether argument types can be bound from default arguments in the
> standard,
They can't.
> but if they can't then I should get a diagnostic at the declaration
> of the template.
As Andrew showed, the template isn't invalid and can be called with an explicit
template argument list, so issuing a diagnostic at declaration would be wrong.
> The actual message is cryptic and unhelpful.
Current versions give a great diagnostic:
c.cc: In function ‘int main()’:
c.cc:4:14: error: no matching function for call to ‘foo(int)’
c.cc:4:14: note: candidate is:
c.cc:2:9: note: template<class T> void foo(int, void (*)(T*), T*)
c.cc:2:9: note: template argument deduction/substitution failed:
c.cc:4:14: note: couldn't deduce template parameter ‘T’
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-01-15 23:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-40127-4@http.gcc.gnu.org/bugzilla/>
2012-01-15 20:27 ` [Bug c++/40127] Fails to identify template function with default args pinskia at gcc dot gnu.org
2012-01-15 23:26 ` 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).