Bug 26404 - g++ seems to substitute template parameter too early
Summary: g++ seems to substitute template parameter too early
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on: 26261
Blocks:
  Show dependency treegraph
 
Reported: 2006-02-21 21:03 UTC by Stefan Seefeld
Modified: 2007-09-27 02:15 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 2.95 3.2 3.3.3 3.4.0 4.0.0 4.1.0 4.2.0
Last reconfirmed: 2006-02-21 21:14:54


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Seefeld 2006-02-21 21:03:34 UTC
The following code generates the error

/home/stefan/fs.cc:11: error: template-id ‘foo<>’ for ‘void foo(int)’ does not match any template declaration
/home/stefan/fs.cc:11: error: invalid function declaration 


as it doesn't seem to match 'Tag<int>::tag' against 'Tag<A>::tag' but the
substituted 'int' directly.

---

template <typename A> struct Tag { typedef int type;};

template <typename A>
void
foo(typename Tag<A>::type t);

template <>
void
foo(Tag<int>::type t) {} 

---
Comment 1 Andrew Pinski 2006-02-21 21:14:54 UTC
Confirmed not a regression, I saw a bug that was related to this was recently filed also.
Comment 2 Andrew Pinski 2006-02-21 21:16:35 UTC
PR 26261 was the bug which I was thinking of.
Comment 3 Paolo Carlini 2007-09-23 18:58:57 UTC
For the record, Comeau also rejects it.
Comment 4 Wolfgang Bangerth 2007-09-24 03:52:31 UTC
It's only a diagnostic problem: the template type 'int' in Tag<int>::type
is non-deductible, so the compiler can't find the primary template. The
code in therefore in fact invalid. You can make it valid by explicitly
specifying the template argument as in

template <>
void
foo<int>(Tag<int>::type t) {} 

Once one knows what the problem is, the error message even makes some sense.
I don't know how to improve it, since the compiler certainly can't tell
that the primary template uses a template parameter in a non-deducible context
here.

W.