This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: template specializiation


This information from the ISO 14882 spec might help understand:

14.7.3.6

If a template, a member template or the member of a class template is
explicitly specialized then that specialization
shall be declared before the first use of that specialization that
would cause an implicit instantiation
to take place, in every translation unit in which such a use occurs;
no diagnostic is required. If the program
does not provide a definition for an explicit specialization and
either the specialization is used in a
way that would cause an implicit instantiation to take place or the
member is a virtual member function, the
program is ill-formed, no diagnostic required. An implicit
instantiation is never generated for an explicit
specialization that is declared but not defined. [Example:
template<class T> class Array { /* ... */ };
template<class T> void sort(Array<T>& v) { /* ... */ }
void f(Array<String>& v)
{
sort(v); //use primary template
// sort(Array<T>&), T is String
}
template<> void sort<String>(Array<String>& v); // error: specialization
// after use of primary template
template<> void sort<>(Array<char*>& v); // OK: sort<char*> not yet used
—end example]

corey

On 7/7/05, Eljay Love-Jensen <eljay@adobe.com> wrote:
> Hi Thomas,
> 
> Hmmm, unusual situation (for me).
> 
> Using...
> http://www.comeaucomputing.com/tryitout/
> 
> I tend to trust (EDG's front end) Comeau C++'s error message (strict mode, -tused) on this one.
> 
> How to unravel this riddle, I'm not sure.  Sorry.
> 
> --Eljay
> 
> - - - - -
> struct A
> {
>   const A* a;
> };
> 
> template <const char* c>
> struct B
> {
>   static const A b;
> };
> 
> extern const char c[1]="";
> extern const char d[1]="";
> 
> template<>
> const A B<c>::b =
> {
>   &B<d>::b
> };
> template<>
> const A B<d>::b = // Line 21
> {
>   &B<c>::b
> };
> - - - - -
> 
> Comeau C/C++ 4.3.3 (Aug  6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
> Copyright 1988-2003 Comeau Computing.  All rights reserved.
> MODE:strict errors C++
> 
> "ComeauTest.c", line 21: error: explicit specialization of member
>           "B<c>::b [with c=d]" must precede its first use
>   const A B<d>::b =
>                 ^
> 
> "ComeauTest.c", line 24: warning: parsing restarts here after previous syntax error
>   };
>    ^
> 
> 1 error detected in the compilation of "ComeauTest.c".
> 
> 
>

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]