public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/10619: [diagnostic] Error message for no matching function calls does not list explicitally-specified template arguments
@ 2003-05-09 19:03 giovannibajo
  0 siblings, 0 replies; 2+ messages in thread
From: giovannibajo @ 2003-05-09 19:03 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, gccbugs, gdr, giovannibajo, nobody

Synopsis: [diagnostic] Error message for no matching function calls does not list explicitally-specified template arguments

Responsible-Changed-From-To: unassigned->gdr
Responsible-Changed-By: bajo
Responsible-Changed-When: Fri May  9 19:03:10 2003
Responsible-Changed-Why:
    Diagnostic mantainer

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10619


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

* Re: c++/10619: [diagnostic] Error message for no matching function calls does not list explicitally-specified template arguments
@ 2003-05-04 14:44 giovannibajo
  0 siblings, 0 replies; 2+ messages in thread
From: giovannibajo @ 2003-05-04 14:44 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, gccbugs, giovannibajo, nobody

Old Synopsis: Instantiation through function template return type causes too cryptic error.
New Synopsis: [diagnostic] Error message for no matching function calls does not list explicitally-specified template arguments

State-Changed-From-To: open->analyzed
State-Changed-By: bajo
State-Changed-When: Sun May  4 14:44:57 2003
State-Changed-Why:
    Your understanding of what the compiler does are wrong.
    When template functions are found during the
    lookup phase, the compiler _tries_ to specialize them,
    following several rules: it tries to deduce the template
    parameters from the arguments passed and/or uses the 
    explicitally specified template parameters. If the 
    deduction fails and/or is not possible to specialize the
    function in a way that would match the call, the function
    is _not_ instantiated _and_ it is not added to the 
    overload set (which will be used later to decide which 
    function must be called).
    
    De-legalizing the above, in your case, what happens is
    that the compiler detects that it is impossible to 
    specialize f() in a way which would match a call like
    "f<0>()," because specializing with I=0 leads to a type 
    error in the return type. Thus, the template function f() 
    is not added to the overload set. Since there are no more 
    functions called f(), the overload set ends up being
    empty, and the compiler correctly complains that there
    are no matching functions for call to f(). 
    
    This is actually a feature of the language: you can use
    type deduction together with overload as a way to detect
    valid constructs. A quick example is the common is_class
    template trick, which uses deduction and overload to 
    detect a class: the trick is that a class is an entity T 
    for which declaring a pointer such as "void (T::*)(void)" 
    is a valid construct:
    
    --------------------------------------------------------
    template <typename T>
    struct is_class
    {
    	typedef char yes;
    	typedef double no;
    
    	template <typename Q>
    	static yes func(void (Q::*)(void));
    
    	template <typename Q>
    	static no func(...);
    
    	enum { value = sizeof(func<T>(0)) == sizeof(yes) };
    
    	// due to another bug, in GCC currently you need:
    	//  sizeof(is_class::template func<T>(0))
    	// to make the above line compile
    };
    
    struct Foo {}
    
    is_class<int>::value; // 0
    is_class<Foo>::value; // 1
    --------------------------------------------------------
    
    
    * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    
    Anyway, I keep this PR open for another reason. Given the
    following code snippet:
    
    -----------------------------
    template <typename T>
    void foo(int );
    
    int main()
    {
    	foo<0>(4);
    }
    
    -----------------------------
    pr10619.cpp: In function `int main()':
    pr10619.cpp:8: error: no matching function for call to `foo(int)'
    
    
    The error message is slightly wrong. It's not true that there
    are no matching calls "foo(int)". The problem here is that there
    are no matching calls for "foo<0>(int)". The error message does
    not list the explicitally specified template argument, which is
    the real problem for the call to fail. I think that the error
    message should rather be:
    
    "no matching function for call to foo<0>(int)"
    
    Then, I keep this as a change request for diagnostic.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10619


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

end of thread, other threads:[~2003-05-09 19:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-09 19:03 c++/10619: [diagnostic] Error message for no matching function calls does not list explicitally-specified template arguments giovannibajo
  -- strict thread matches above, loose matches on Subject: below --
2003-05-04 14:44 giovannibajo

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).