public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/35904]  New: Poor error message
@ 2008-04-10 21:33 chris at bubblescope dot net
  2008-04-14 14:35 ` [Bug c++/35904] " bangerth at dealii dot org
  0 siblings, 1 reply; 2+ messages in thread
From: chris at bubblescope dot net @ 2008-04-10 21:33 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 838 bytes --]

The code:
void grab(int& i);

int main(void)
{ grab(1); }

Produces the useful and informative error:

invalid initialization of non-const reference of type ‘int&’ from a temporary
of type ‘int’

Whereas the code:


template<typename T>
void grab(T t, int& i);

int main(void)
{ grab(1,1); }

Produces the much less useful

"no matching function for call to ‘grab(int, int)’"

Would it be possible to still get the error message about temporaries in the
templated case?


-- 
           Summary: Poor error message
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: chris at bubblescope dot net


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


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

* [Bug c++/35904] Poor error message
  2008-04-10 21:33 [Bug c++/35904] New: Poor error message chris at bubblescope dot net
@ 2008-04-14 14:35 ` bangerth at dealii dot org
  0 siblings, 0 replies; 2+ messages in thread
From: bangerth at dealii dot org @ 2008-04-14 14:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from bangerth at dealii dot org  2008-04-14 14:34 -------
You are asking for too much. The problem is that in your first example
the compiler knows that you want to call the grab() function and therefore
can give you an informative error message. But in the second example it
can't: there's a template, and the compiler tries to match your call's
argument types with the template types, but it can't find a set of
template types for which the call would match the signature of the function
template. In other words, it doesn't know which function you want to
call -- there doesn't appear to be one that would match what you want.

To implement what you suggest would require the compiler to speculate what
you wanted, for example by speculating that you wanted grab<int>. We've
found over the years that letting the compiler speculate sometimes produces
a better diagnostic, but most of the time leads to messages that really don't
have anything to do with what the user really wanted -- and then become
really confusing.

W.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |WONTFIX


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


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

end of thread, other threads:[~2008-04-14 14:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-10 21:33 [Bug c++/35904] New: Poor error message chris at bubblescope dot net
2008-04-14 14:35 ` [Bug c++/35904] " bangerth at dealii dot 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).