public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/18306] New: seems not possible to specialize a template member function
@ 2004-11-05 4:13 ramya dot chandar at wipro dot com
2004-11-05 4:19 ` [Bug c++/18306] " ramya dot chandar at wipro dot com
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: ramya dot chandar at wipro dot com @ 2004-11-05 4:13 UTC (permalink / raw)
To: gcc-bugs
Environment : i686-pc-linux-gnu
Compiler Version: GCC 3.3.2
Kernel Version : 2.4.7-10
It seems, not possible to specialize a template member functions const. I got a
file(.impl) which got the following template functions( generalized and
specialized template functions ) and i got the corresponding header file ( where
this .impl file is getting included ).
IOCM::Status IOCM_SequenceTempl<IOCM::Char>::_skip(IOCM::MessageBox& msgBox);
IOCM::Status IOCM_SequenceTempl<IOCM::Octet>::_skip(IOCM::MessageBox& msgBox);
IOCM::Status IOCM_SequenceTempl<IOCM::Short>::_skip(IOCM::MessageBox& msgBox);
IOCM::Status IOCM_SequenceTempl<IOCM::UShort>::_skip(IOCM::MessageBox& msgBox);
IOCM::Status IOCM_SequenceTempl<IOCM::Long>::_skip(IOCM::MessageBox& msgBox);
IOCM::Status IOCM_SequenceTempl<IOCM::ULong>::_skip(IOCM::MessageBox& msgBox);
IOCM::Status IOCM_SequenceTempl<IOCM::Float>::_skip(IOCM::MessageBox& msgBox);
IOCM::Status IOCM_SequenceTempl<T>::_skip(IOCM::MessageBox& msgBox);
But, the build is getting failed, with the following error( for all the template
functions ).
/cm4/objects/gant-c/ghostr/cm4/fsn/app/asam/eqptDomain/eqptMgntCore/common/AppliqueSensorListener.o(.text+0x0):
In function `IOCM_SequenceTempl<char>::_size() const':
/cm4/fsn/include/iocm/Sequence.impl:293: multiple definition of
`IOCM_SequenceTempl<char>::_size() const'
/cm4/objects/gant-c/ghostr/cm4/fsn/app/asam/eqptDomain/eqptMgntCore/common/AppliqueHandler.o(.text+0x0):/cm4/fsn/include/iocm/Sequence.impl:293:
first defined here
/cm4/objects/gant-c/ghostr/cm4/fsn/app/asam/eqptDomain/eqptMgntCore/common/AppliqueSensorListener.o(.text+0x18):
In function `IOCM_SequenceTempl<char>::_pack(IOCM_MessageBox&) const':
/cm4/fsn/include/iocm/Sequence.impl:305: multiple definition of
`IOCM_SequenceTempl<char>::_pack(IOCM_MessageBox&) const'
/cm4/objects/gant-c/ghostr/cm4/fsn/app/asam/eqptDomain/eqptMgntCore/common/AppliqueHandler.o(.text+0x18):/cm4/fsn/include/iocm/Sequence.impl:305:
first defined here
There is no problem with 2.95.3
But, when i remove the .impl file( which got the template function definitions )
from the corresponding header file, compilation went through, but its failing
during linking stage for the same reason giving the following error message for
all the template functions.
Linking fails with the following error( for all the template functions ).
/cm4/fsn/app/asam/atm2/nt/../export/idl/AtmApplication_ifc.cc:344: undefined
reference to `IOCM_SequenceTempl<Eqpt::LogicalIfIndex>::_size(void) const'
/cm4/fsn/app/asam/atm2/nt/../export/idl/AtmApplication_ifc.cc:349: undefined
reference to `IOCM_SequenceTempl<Eqpt::LogicalIfIndex>::_pack(IOCM_MessageBox &)
const'
--
Summary: seems not possible to specialize a template member
function
Product: gcc
Version: 3.2.2
Status: UNCONFIRMED
Severity: critical
Priority: P1
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ramya dot chandar at wipro dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18306
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18306] seems not possible to specialize a template member function
2004-11-05 4:13 [Bug c++/18306] New: seems not possible to specialize a template member function ramya dot chandar at wipro dot com
@ 2004-11-05 4:19 ` ramya dot chandar at wipro dot com
2004-11-05 4:21 ` ramya dot chandar at wipro dot com
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: ramya dot chandar at wipro dot com @ 2004-11-05 4:19 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From ramya dot chandar at wipro dot com 2004-11-05 04:19 -------
Created an attachment (id=7476)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7476&action=view)
preprocessed source for AppliqueHandler.cc
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18306
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18306] seems not possible to specialize a template member function
2004-11-05 4:13 [Bug c++/18306] New: seems not possible to specialize a template member function ramya dot chandar at wipro dot com
2004-11-05 4:19 ` [Bug c++/18306] " ramya dot chandar at wipro dot com
@ 2004-11-05 4:21 ` ramya dot chandar at wipro dot com
2004-11-05 4:28 ` pinskia at gcc dot gnu dot org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: ramya dot chandar at wipro dot com @ 2004-11-05 4:21 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From ramya dot chandar at wipro dot com 2004-11-05 04:21 -------
Created an attachment (id=7477)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7477&action=view)
preprocessed code for AppliqueSensorListener.cc
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18306
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18306] seems not possible to specialize a template member function
2004-11-05 4:13 [Bug c++/18306] New: seems not possible to specialize a template member function ramya dot chandar at wipro dot com
2004-11-05 4:19 ` [Bug c++/18306] " ramya dot chandar at wipro dot com
2004-11-05 4:21 ` ramya dot chandar at wipro dot com
@ 2004-11-05 4:28 ` pinskia at gcc dot gnu dot org
2004-11-05 5:03 ` pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-05 4:28 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-11-05 04:28 -------
As I said before the code you have here is invalid C++.
you have to add
template<> in front of each of the specialization of a template member function.
Also you have problems with template namelookup also (read the 3.4 release notes for the problems
which I am talking about).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18306
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18306] seems not possible to specialize a template member function
2004-11-05 4:13 [Bug c++/18306] New: seems not possible to specialize a template member function ramya dot chandar at wipro dot com
` (2 preceding siblings ...)
2004-11-05 4:28 ` pinskia at gcc dot gnu dot org
@ 2004-11-05 5:03 ` pinskia at gcc dot gnu dot org
2004-11-05 19:27 ` bangerth at dealii dot org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-05 5:03 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-11-05 05:03 -------
Invalid, as what you are doing is called explicit specializtion and when this happens you instantiate the
template and now you are violating the one defintional rule (which is 14.7/5 in the C++ standard).
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18306
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18306] seems not possible to specialize a template member function
2004-11-05 4:13 [Bug c++/18306] New: seems not possible to specialize a template member function ramya dot chandar at wipro dot com
` (3 preceding siblings ...)
2004-11-05 5:03 ` pinskia at gcc dot gnu dot org
@ 2004-11-05 19:27 ` bangerth at dealii dot org
2004-11-05 19:29 ` bangerth at dealii dot org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: bangerth at dealii dot org @ 2004-11-05 19:27 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-11-05 19:27 -------
These are all duplicates of PR 15552
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18306
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18306] seems not possible to specialize a template member function
2004-11-05 4:13 [Bug c++/18306] New: seems not possible to specialize a template member function ramya dot chandar at wipro dot com
` (4 preceding siblings ...)
2004-11-05 19:27 ` bangerth at dealii dot org
@ 2004-11-05 19:29 ` bangerth at dealii dot org
2004-11-23 12:31 ` ramya dot chandar at wipro dot com
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: bangerth at dealii dot org @ 2004-11-05 19:29 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2004-11-05 19:29 -------
Duplicate of PR 15552.
*** This bug has been marked as a duplicate of 15552 ***
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18306
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18306] seems not possible to specialize a template member function
2004-11-05 4:13 [Bug c++/18306] New: seems not possible to specialize a template member function ramya dot chandar at wipro dot com
` (5 preceding siblings ...)
2004-11-05 19:29 ` bangerth at dealii dot org
@ 2004-11-23 12:31 ` ramya dot chandar at wipro dot com
2004-11-24 6:55 ` ramya dot chandar at wipro dot com
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: ramya dot chandar at wipro dot com @ 2004-11-23 12:31 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From ramya dot chandar at wipro dot com 2004-11-23 12:31 -------
Subject: Re: seems not possible to specialize a template member
function
clarification please...
I tried including "template<>" in front of each of the specialized template member functions. It doesn't solve the problem.
Looking at my code, for my knowledge, it doesn't look like violating the rule (14.7/5). Can you please tell me what exacting is going wrong and how does it violates the rule.
According to 14.7/5 rule,
A non-exported template that is neither explicitly specialized nor explicitly instan-
tiated must be defined in every translation unit in which it is implicitly instantiated or explicitly instantiated; no diagnostic is required. An exported template need only be declared (and not necessarily defined) in a translation unit in which it is instantiated. A template function declared both exported and inline is just inline and not exported.
But, in the code i have attached,( since the generalised and specialized template member functions ) are explicitely instantiated in a module( Sequence.impl ), its not defined separately in any of the translation unit. Still why does it fail.
I don't know how is it violating the rule. Can you please tell me, what needs to be done exactly.
Thanks,
Ramya.
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-11-05 04:28 -------
As I said before the code you have here is invalid C++.
you have to add
template<> in front of each of the specialization of a template member function.
Also you have problems with template namelookup also (read the 3.4 release notes for the problems
which I am talking about).
--
pinskia at gcc dot gnu dot org wrote:
>------- Additional Comments From pinskia at gcc dot gnu dot org 2004-11-05 05:03 -------
>Invalid, as what you are doing is called explicit specializtion and when this happens you instantiate the
>template and now you are violating the one defintional rule (which is 14.7/5 in the C++ standard).
>
>
>
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18306
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18306] seems not possible to specialize a template member function
2004-11-05 4:13 [Bug c++/18306] New: seems not possible to specialize a template member function ramya dot chandar at wipro dot com
` (6 preceding siblings ...)
2004-11-23 12:31 ` ramya dot chandar at wipro dot com
@ 2004-11-24 6:55 ` ramya dot chandar at wipro dot com
2004-11-24 19:11 ` pinskia at gcc dot gnu dot org
2005-03-08 9:44 ` ramya dot chandar at wipro dot com
9 siblings, 0 replies; 11+ messages in thread
From: ramya dot chandar at wipro dot com @ 2004-11-24 6:55 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From ramya dot chandar at wipro dot com 2004-11-24 06:55 -------
clarification please...
I tried including "template<>" in front of each of the specialized template
member functions. It doesn't solve the problem.
But, in the code i have attached,( since the generalised and specialized
template member functions ) are explicitely instantiated in a module(
Sequence.impl ), its not defined separately in any of the translation unit.
Still why does it fail.
I don't know how is it violating the rule. Can you please tell me, what needs to
be done exactly.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|DUPLICATE |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18306
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18306] seems not possible to specialize a template member function
2004-11-05 4:13 [Bug c++/18306] New: seems not possible to specialize a template member function ramya dot chandar at wipro dot com
` (7 preceding siblings ...)
2004-11-24 6:55 ` ramya dot chandar at wipro dot com
@ 2004-11-24 19:11 ` pinskia at gcc dot gnu dot org
2005-03-08 9:44 ` ramya dot chandar at wipro dot com
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-24 19:11 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-11-24 19:11 -------
Invalid, as what you are doing is called explicit specializtion and when this happens you instantiate the
template and now you are violating the one defintional rule (which is 14.7/5 in the C++ standard).
Note that if you use 3.4.0, it works with adding template<>.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18306
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/18306] seems not possible to specialize a template member function
2004-11-05 4:13 [Bug c++/18306] New: seems not possible to specialize a template member function ramya dot chandar at wipro dot com
` (8 preceding siblings ...)
2004-11-24 19:11 ` pinskia at gcc dot gnu dot org
@ 2005-03-08 9:44 ` ramya dot chandar at wipro dot com
9 siblings, 0 replies; 11+ messages in thread
From: ramya dot chandar at wipro dot com @ 2005-03-08 9:44 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From ramya dot chandar at wipro dot com 2005-03-08 09:44 -------
(In reply to comment #9)
> Invalid, as what you are doing is called explicit specializtion and when this
happens you instantiate the
> template and now you are violating the one defintional rule (which is 14.7/5
in the C++ standard).
>
> Note that if you use 3.4.0, it works with adding template<>.
(In reply to comment #9)
> Invalid, as what you are doing is called explicit specializtion and when this
happens you instantiate the
> template and now you are violating the one defintional rule (which is 14.7/5
in the C++ standard).
>
> Note that if you use 3.4.0, it works with adding template<>.
Since solving this Compiler error is very critical to us, We made some more
investigation in our code to see if it violates the one defintional rule of C++.
Here is our consolidated investigation.
Explicit template specialization itself does NOT instantiate the template. It
only specializes it. Hence, we feel, it is not violating any C++ standard rules.
E.g.,
template<class T> class A {
public:
void f(T t) { /* ... */ } // definition in general case
};
template<> void A<int>::f(int i) { /* ... */ } // definition in specific, i.e.,
'T=int' case
The above code does NOT instantiate the template, it only does explicit
specialization of its 'f' member function for the case of 'T= int'.
Template instantiation is an another issue, and it can happen either implicitly
or explicitly.
Implicit template instantiation happens when the template is being used in the
way that its usage requires the instantiation.
E.g.,
A<int>* aP; // No instantiation happens!
A<int> a; // Implicit template instantiation happens!
Explicit template instantiation happens when the explicit template instantiation
syntax is applied.
E.g.,
template class A<int>;
template void A<int>::f(int);
template class A<char>;
Looking at our IOCM Sequence.hh and Sequence.impl files, within these files the
templates, that generate errors with the new GNU compiler( 3.3.2), are surely
NOT instantiated.
However it is true that the template specializations in the Sequence.impl files
should have template<> prefix (but most of the compilers are actually accept
them without this as well).
I checked these files with the Microsoft Visual Studio .Net 2003 which is
commonly known as having one of the compilers that most follow the C++ standard.
With this compiler everything compiles well (in fact, with or without the
template<> prefix).
Can you please explain us, if it is the problem with GCC 3.3.2 compiler.
surprisingly, with GCC 2.95.3 compiler, we are able to compile the same code
without any changes.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18306
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2005-03-08 9:44 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-05 4:13 [Bug c++/18306] New: seems not possible to specialize a template member function ramya dot chandar at wipro dot com
2004-11-05 4:19 ` [Bug c++/18306] " ramya dot chandar at wipro dot com
2004-11-05 4:21 ` ramya dot chandar at wipro dot com
2004-11-05 4:28 ` pinskia at gcc dot gnu dot org
2004-11-05 5:03 ` pinskia at gcc dot gnu dot org
2004-11-05 19:27 ` bangerth at dealii dot org
2004-11-05 19:29 ` bangerth at dealii dot org
2004-11-23 12:31 ` ramya dot chandar at wipro dot com
2004-11-24 6:55 ` ramya dot chandar at wipro dot com
2004-11-24 19:11 ` pinskia at gcc dot gnu dot org
2005-03-08 9:44 ` ramya dot chandar at wipro 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).