* [Bug c++/22596] Impossible to explicitly instantiate particular overloaded function
2005-07-21 18:48 [Bug c++/22596] New: Impossible to explicitly instantiate particular overloaded function phenning at lanl dot gov
@ 2005-07-21 18:57 ` phenning at lanl dot gov
2005-07-21 18:58 ` pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: phenning at lanl dot gov @ 2005-07-21 18:57 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From phenning at lanl dot gov 2005-07-21 18:48 -------
Created an attachment (id=9324)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9324&action=view)
sample code illustrating problem
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22596
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/22596] Impossible to explicitly instantiate particular overloaded function
2005-07-21 18:48 [Bug c++/22596] New: Impossible to explicitly instantiate particular overloaded function phenning at lanl dot gov
2005-07-21 18:57 ` [Bug c++/22596] " phenning at lanl dot gov
@ 2005-07-21 18:58 ` pinskia at gcc dot gnu dot org
2005-07-21 19:16 ` pinskia at gcc dot gnu dot org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-21 18:58 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-07-21 18:57 -------
Note both Comeau and ICC have this same behavior.
Even the following code calls the second declaration too:
template<class T> struct A_class
{
int do_it(int i){return T::f(i);}
};
template<class A> int foo(A a);
template<class A, class T> int foo(A_class<T> a)
{
return a.do_it(2);
}
void g(void)
{
A_class<int> a;
foo<A_class<int> >(a);
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22596
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/22596] Impossible to explicitly instantiate particular overloaded function
2005-07-21 18:48 [Bug c++/22596] New: Impossible to explicitly instantiate particular overloaded function phenning at lanl dot gov
2005-07-21 18:57 ` [Bug c++/22596] " phenning at lanl dot gov
2005-07-21 18:58 ` pinskia at gcc dot gnu dot org
@ 2005-07-21 19:16 ` pinskia at gcc dot gnu dot org
2005-07-21 19:34 ` phenning at lanl dot gov
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-21 19:16 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-07-21 18:58 -------
I don't think this is a bug in the front-end.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22596
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/22596] Impossible to explicitly instantiate particular overloaded function
2005-07-21 18:48 [Bug c++/22596] New: Impossible to explicitly instantiate particular overloaded function phenning at lanl dot gov
` (2 preceding siblings ...)
2005-07-21 19:16 ` pinskia at gcc dot gnu dot org
@ 2005-07-21 19:34 ` phenning at lanl dot gov
2005-07-21 23:19 ` bangerth at dealii dot org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: phenning at lanl dot gov @ 2005-07-21 19:34 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From phenning at lanl dot gov 2005-07-21 19:16 -------
(In reply to comment #2)
> void g(void)
> {
> A_class<int> a;
> foo<A_class<int> >(a);
> }
Right, and I think that it should in that case. It seems that g++ attempts to call the first definition
when there is usage like:
foo(something_that_returns_Aclass_int());
So, when I try to compile code that uses std::vector<int>, the compiler generates calls to both
std::_Destroy<int*, std::allocator<int> >(int *, int*, std::allocator<int>)
and
std::_Destroy<int*, std::allocator<int>, int>(int *, int*, std::allocator<int>)
Since I can't explicitly instantiate the first form, I can't compile std::vector code with -fno-implicit-
templates.
This could be changed by how _Destroy is implemented, but it seems strange that I can't explicitly
instantiate a class, given that I'm providing the template parameter signature explicitly.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22596
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/22596] Impossible to explicitly instantiate particular overloaded function
2005-07-21 18:48 [Bug c++/22596] New: Impossible to explicitly instantiate particular overloaded function phenning at lanl dot gov
` (3 preceding siblings ...)
2005-07-21 19:34 ` phenning at lanl dot gov
@ 2005-07-21 23:19 ` bangerth at dealii dot org
2005-07-21 23:30 ` phenning at lanl dot gov
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2005-07-21 23:19 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2005-07-21 23:17 -------
Your explicit instantiation
template int foo< A_class<int> >(A_class<int> a);
obviously matches both the declarations of foo. I'm unsure which
one the compiler should choose, but if you want to instantiate the
second one, why don't you write
template int foo< A_class<int>,int >(A_class<int> a);
i.e. explicitly state the second template argument as well?
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22596
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/22596] Impossible to explicitly instantiate particular overloaded function
2005-07-21 18:48 [Bug c++/22596] New: Impossible to explicitly instantiate particular overloaded function phenning at lanl dot gov
` (4 preceding siblings ...)
2005-07-21 23:19 ` bangerth at dealii dot org
@ 2005-07-21 23:30 ` phenning at lanl dot gov
2005-07-22 0:34 ` bangerth at dealii dot org
2005-07-26 20:43 ` pinskia at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: phenning at lanl dot gov @ 2005-07-21 23:30 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From phenning at lanl dot gov 2005-07-21 23:26 -------
(In reply to comment #5)
> Your explicit instantiation
> template int foo< A_class<int> >(A_class<int> a);
> obviously matches both the declarations of foo. I'm unsure which
> one the compiler should choose, but if you want to instantiate the
> second one, why don't you write
> template int foo< A_class<int>,int >(A_class<int> a);
> i.e. explicitly state the second template argument as well?
The compiler is more than happy to instantiate the second one... the problem is that it is converting my
one template parameter explicit specialization into the two template parameter form, presumably
because the function signature matches. I would expect that if I explicitly state the one parameter
form, the compiler should instantiate the one parameter form.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22596
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/22596] Impossible to explicitly instantiate particular overloaded function
2005-07-21 18:48 [Bug c++/22596] New: Impossible to explicitly instantiate particular overloaded function phenning at lanl dot gov
` (5 preceding siblings ...)
2005-07-21 23:30 ` phenning at lanl dot gov
@ 2005-07-22 0:34 ` bangerth at dealii dot org
2005-07-26 20:43 ` pinskia at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: bangerth at dealii dot org @ 2005-07-22 0:34 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2005-07-22 00:18 -------
Oh, I apparently didn't read closely enough. I see the problem now.
For others -- take this:
---------------------
template <typename T> void f(T) {}
template <typename U, typename T> void f(T) {}
template void f<int> (int);
---------------------
We want the first function to be instantiated, but both functions match
the signature and gcc (as well as icc) instantiate the second:
g/x> c++ -c x.cc
g/x> nm -C x.o
00000000 W void f<int, int>(int)
I remember that there was a PR on this somewhere in bugzilla, and possibly
a DR on this. I don't remember the conclusion, though...
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22596
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/22596] Impossible to explicitly instantiate particular overloaded function
2005-07-21 18:48 [Bug c++/22596] New: Impossible to explicitly instantiate particular overloaded function phenning at lanl dot gov
` (6 preceding siblings ...)
2005-07-22 0:34 ` bangerth at dealii dot org
@ 2005-07-26 20:43 ` pinskia at gcc dot gnu dot org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-26 20:43 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
GCC target triplet|i686-pc-linux-gnu, powerpc- |
|apple-darwin8 |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22596
^ permalink raw reply [flat|nested] 9+ messages in thread