public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/19569] New: no code for explicit instantiation of template class specialization
@ 2005-01-21 18:12 jamesp at trdlnk dot com
  2005-01-22 18:37 ` [Bug c++/19569] " bangerth at dealii dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: jamesp at trdlnk dot com @ 2005-01-21 18:12 UTC (permalink / raw)
  To: gcc-bugs

It appears that explicit instantiation of specialized template classes isn't
instantiating all of the class's members as it should:

--- Begin Sample Code ------------
template <typename T>
class A
{
public:
    void foo( T const & ) {}
};

template <>
class A<char>
{
public:
    void foo( char const & ) {}
};

template class A<int>;
template class A<char>;

--- End Sample Code ------------

When I compile the above code and run nm on the object file, I get:
%nm test.o
00000000 W _ZN1AIiE3fooERKi
%

The explicit instantiation of the char specialization of class A should have
created A<char>::foo(char const &).

-- 
           Summary: no code for explicit instantiation of template class
                    specialization
           Product: gcc
           Version: 3.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jamesp at trdlnk dot com
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i686-pc-linux-gnu


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


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

* [Bug c++/19569] no code for explicit instantiation of template class specialization
  2005-01-21 18:12 [Bug c++/19569] New: no code for explicit instantiation of template class specialization jamesp at trdlnk dot com
@ 2005-01-22 18:37 ` bangerth at dealii dot org
  2005-01-24 14:03 ` jamesp at trdlnk dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: bangerth at dealii dot org @ 2005-01-22 18:37 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2005-01-22 18:37 -------
Why? The function you want is inline. I would rather claim that the 
instantiation of the function in the general template is wrong, 
although arguably it doesn't matter since it is marked weak. 
 
You will have to explain what kind of problem you have because the 
function you ask for isn't instantiated? 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


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


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

* [Bug c++/19569] no code for explicit instantiation of template class specialization
  2005-01-21 18:12 [Bug c++/19569] New: no code for explicit instantiation of template class specialization jamesp at trdlnk dot com
  2005-01-22 18:37 ` [Bug c++/19569] " bangerth at dealii dot org
@ 2005-01-24 14:03 ` jamesp at trdlnk dot com
  2005-01-24 14:27 ` lerdsuwa at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jamesp at trdlnk dot com @ 2005-01-24 14:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jamesp at trdlnk dot com  2005-01-24 14:03 -------
According to paragraph 7 of section 14.7.2 in the C++ standard, this is supposed
to work as I described.

I admit that the sample code I supplied doesn't show why this functionality is
necessary, so I'll try to explain my motivation. I'm writing a library that
defines a template class that is supposed to be specialized by client code.
There is no default implementation for the template class member functions. I
consider the implementation of the template class a detail related to this
library and don't want to force the client to litter header files with these
details. The header files for the library contain enough of the details to
generate the necessary function calls properly without forcing the user to
define the specialized template class member functions in a special location. My
recommendation to the users is to define the specialization in a .cc file,
explicitly extantiate the class, and link in the code as necessary rather than
create special header files. In short, it's just a lot cleaner and easier for
the clients to maintain.

-- 


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


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

* [Bug c++/19569] no code for explicit instantiation of template class specialization
  2005-01-21 18:12 [Bug c++/19569] New: no code for explicit instantiation of template class specialization jamesp at trdlnk dot com
  2005-01-22 18:37 ` [Bug c++/19569] " bangerth at dealii dot org
  2005-01-24 14:03 ` jamesp at trdlnk dot com
@ 2005-01-24 14:27 ` lerdsuwa at gcc dot gnu dot org
  2005-01-24 14:30 ` pinskia at gcc dot gnu dot org
  2005-01-24 14:56 ` jamesp at trdlnk dot com
  4 siblings, 0 replies; 6+ messages in thread
From: lerdsuwa at gcc dot gnu dot org @ 2005-01-24 14:27 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From lerdsuwa at gcc dot gnu dot org  2005-01-24 14:27 -------
There is a defect report DR259 about this issue:
  http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#259

According to the DR, the original standard mentions that
the instantiation:
  template class A<char>;
is invalid because there is already a specialization
  template <> class A<char> { ... };
declared earlier.

In the revised version of the standard, which includes the
resolution of this DR, the instantiation is ignored.
Recent GCC releases follow this behavior.

-- 


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


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

* [Bug c++/19569] no code for explicit instantiation of template class specialization
  2005-01-21 18:12 [Bug c++/19569] New: no code for explicit instantiation of template class specialization jamesp at trdlnk dot com
                   ` (2 preceding siblings ...)
  2005-01-24 14:27 ` lerdsuwa at gcc dot gnu dot org
@ 2005-01-24 14:30 ` pinskia at gcc dot gnu dot org
  2005-01-24 14:56 ` jamesp at trdlnk dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-24 14:30 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-24 14:30 -------
So this is not a bug, so closing.

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


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


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

* [Bug c++/19569] no code for explicit instantiation of template class specialization
  2005-01-21 18:12 [Bug c++/19569] New: no code for explicit instantiation of template class specialization jamesp at trdlnk dot com
                   ` (3 preceding siblings ...)
  2005-01-24 14:30 ` pinskia at gcc dot gnu dot org
@ 2005-01-24 14:56 ` jamesp at trdlnk dot com
  4 siblings, 0 replies; 6+ messages in thread
From: jamesp at trdlnk dot com @ 2005-01-24 14:56 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jamesp at trdlnk dot com  2005-01-24 14:55 -------
It seems that paragraph 5 of 14.7.3 explains what I should have been doing.

Sorry for the mix-up.

James

-- 


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


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

end of thread, other threads:[~2005-01-24 14:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-21 18:12 [Bug c++/19569] New: no code for explicit instantiation of template class specialization jamesp at trdlnk dot com
2005-01-22 18:37 ` [Bug c++/19569] " bangerth at dealii dot org
2005-01-24 14:03 ` jamesp at trdlnk dot com
2005-01-24 14:27 ` lerdsuwa at gcc dot gnu dot org
2005-01-24 14:30 ` pinskia at gcc dot gnu dot org
2005-01-24 14:56 ` jamesp at trdlnk dot com

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).