This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/17413] [3.4/4.0 regression] local classes as template argument
- From: "mmitchel at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 12 Oct 2004 16:13:36 -0000
- Subject: [Bug c++/17413] [3.4/4.0 regression] local classes as template argument
- References: <20040911043255.17413.gdr@gcc.gnu.org>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From mmitchel at gcc dot gnu dot org 2004-10-12 16:13 -------
As in the discussion of DR 415, it's not feasible to postpone all error messages
until overload resolution has succeeded. The example in DR 415 is that you
might need to instantiate a class type to do type deduction. If the class has
an invalid member upon instantiation, it makes sense to complain then, not later
when the function that required that instantiation is selected.
The language (which John Spicer is trying to clarify) leads to another
complication. [temp.over] says:
template argument deduction (_temp.deduct_)
and checking of any explicit template arguments (_temp.arg_) are per-
formed for each function template to find the template argument values
(if any) that can be used with that function template to instantiate a
function template specialization that can be invoked with the call
arguments. For each function template, if the argument deduction and
checking succeeds, the template-arguments (deduced and/or explicit)
are used to instantiate a single function template specialization
which is added to the candidate functions set to be used in overload
resolution. If, for a given function template, argument deduction
fails, no such function is added to the set of candidate functions for
that template.
This section does not clearly specify what happens if argument deduction
succeeds, but the checking of explict template arguments (as per [temp.arg]) fails.
Consider:
template <typename T>
void f(T *);
void g() {
struct S;
S* p;
f (p); // #1
f<S> (p); // #2
}
If we treated deduction and explicit arguments differently, then we would put
the template in the overload set at #1 (deduction succeeds) but not at #2
(checking of explicit arguments fails). That's odd.
John (and I) think that "instantiate" is the wrong term in the passage quoted
above, in the sense that this should not be a point-of-instantiation, I do
think, however, that the compiler must generate a declaration of the function
template, after instantiation, for use during overload resolution. That is the
natural time to issue errors about the function. Otherwise, you must queue a
possibly arbitrary error or set of errors to issue later, iff the template is
instantiated. It's not reasonable to ask that of the implementation.
For all these reasons, I intend to fix this by issuing an error message before
overload resolution.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17413