[Bug c++/60917] New: sub-optimal diagnostic when instantiating template
tromey at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Apr 21 18:43:00 GMT 2014
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60917
Bug ID: 60917
Summary: sub-optimal diagnostic when instantiating template
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: tromey at gcc dot gnu.org
Consider this source code:
typedef int callback ();
int f(char *);
const char *get_something ();
template<typename T, int (*F) (const T *)>
int wrapper ()
{
return F (get_something ());
}
template<typename T1, typename T2, int (*F) (const T1 *, const T2 *)>
int wrapper ()
{
return F (get_something ());
}
void add_callback (callback *);
void f ()
{
add_callback (wrapper<char, f>);
}
(The bug here is that wrapper is wrapping a function that
takes a "const char *", but f takes a "char *".)
Compiling:
barimba. g++ --syntax-only t.cc
t.cc: In function ‘void f()’:
t.cc:23:33: error: no matches converting function ‘wrapper’ to type ‘int (*)()’
add_callback (wrapper<char, f>);
^
t.cc:14:5: note: candidates are: template<class T1, class T2, int (* F)(const
T1*, const T2*)> int wrapper()
int wrapper ()
^
t.cc:8:5: note: template<class T, int (* F)(const T*)> int
wrapper()
int wrapper ()
^
I found this message pretty confusing. For instance, it claims
to be an error during conversion, but it would have been much more clear
to me if it had been a failure to instantiate instead. I don't know
whether that would be correct or not -- but some kind of clue leading
me to consider the argument types of "f" would have helped a lot.
In my real program, "wrapper" is much more complicated, using template
class in its body, etc, leading me to think perhaps g++ had chosen some
unusual instantiation somehow, or that some other bug had prevented
proper instantiation. I found myself wishing there were some verbose
mode, or "#pragma tell-me-all-the-template-decisions-starting-now" or
a template instantiation debugger...
More information about the Gcc-bugs
mailing list