public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/22596] New: Impossible to explicitly instantiate particular overloaded function
@ 2005-07-21 18:48 phenning at lanl dot gov
  2005-07-21 18:57 ` [Bug c++/22596] " phenning at lanl dot gov
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: phenning at lanl dot gov @ 2005-07-21 18:48 UTC (permalink / raw)
  To: gcc-bugs

Compiling the following code with "g++ -c -fno-implict-templates" always generates code for the 
second definition of foo().  It appears that g++ is automatically deducing the template parameters from 
the function parameters, even though the template parameters are explicitly given in the explict 
instantiation.   This problem prevents explicitly instantiating the function

std::_Destroy<int*, std::allocator<int>>(int *, int *, std::allocator<int>);

from bits/stl_construct.h in the 4.x Common Library implementation.

This behavior has been seen in: 
i686-pc-linux-gnu gcc-3.4.2
powerpc-apple-darwin8 gcc-4.0.0 (20041026 Apple Computer build 4061) 
i686-pc-linux-gnu gcc-4.1.0 20050629 (experimental)

// -------------------------------

template<class T> struct A_class
{
  int do_it(int i) { return i+1; }
};

template<class A> int foo(A a)
{
  return a.do_it(1);
}

template<class A, class T> int foo(A_class<T> a)
{
  return a.do_it(2);
}

template int foo< A_class<int> >(A_class<int> a);

// -------------------------------

-- 
           Summary: Impossible to explicitly instantiate particular
                    overloaded function
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: phenning at lanl dot gov
                CC: gcc-bugs at gcc dot gnu dot org
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] 11+ 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 ` phenning at lanl dot gov
  2005-07-21 18:58 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ 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; 11+ 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] 11+ messages in thread

* [Bug c++/22596] Impossible to explicitly instantiate particular overloaded function
       [not found] <bug-22596-4@http.gcc.gnu.org/bugzilla/>
  2011-06-22 16:07 ` jason at gcc dot gnu.org
@ 2011-06-22 17:35 ` jason at gcc dot gnu.org
  1 sibling, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2011-06-22 17:35 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #9 from Jason Merrill <jason at gcc dot gnu.org> 2011-06-22 17:35:09 UTC ---
This is not a bug; under the partial ordering rules, the second foo is more
specialized than the first, so if both are possible matches the second will be
chosen.

If you want the explicit instantiation to match the same function that's called
with no explicit template arguments, then don't provide explicit template
arguments in the explicit instantiation.  If you just write

template int foo(A_class<int> a);

or

template int foo<>(A_class<int> a);

it will do what you want.


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

* [Bug c++/22596] Impossible to explicitly instantiate particular overloaded function
       [not found] <bug-22596-4@http.gcc.gnu.org/bugzilla/>
@ 2011-06-22 16:07 ` jason at gcc dot gnu.org
  2011-06-22 17:35 ` jason at gcc dot gnu.org
  1 sibling, 0 replies; 11+ messages in thread
From: jason at gcc dot gnu.org @ 2011-06-22 16:07 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #8 from Jason Merrill <jason at gcc dot gnu.org> 2011-06-22 16:07:24 UTC ---
The example at the bottom of DR 214 seems related, but not quite the same:

  http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#214


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

end of thread, other threads:[~2011-06-22 17:35 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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
     [not found] <bug-22596-4@http.gcc.gnu.org/bugzilla/>
2011-06-22 16:07 ` jason at gcc dot gnu.org
2011-06-22 17:35 ` jason at gcc dot gnu.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).