Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #71205 > unrolled thread

explicit specialization problem

Started byBonita Montero <Bonita.Montero@gmail.com>
First post2020-01-07 11:26 +0100
Last post2020-01-09 21:21 +0000
Articles 20 on this page of 23 — 8 participants

Back to article view | Back to comp.lang.c++


Contents

  explicit specialization problem Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-07 11:26 +0100
    Re: explicit specialization problem Ian Collins <ian-news@hotmail.com> - 2020-01-08 10:26 +1300
    Re: explicit specialization problem "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2020-01-07 23:23 +0100
      Re: explicit specialization problem Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-08 07:29 +0100
        Re: explicit specialization problem "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-07 22:34 -0800
          Re: explicit specialization problem Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-08 07:46 +0100
            Re: explicit specialization problem Öö Tiib <ootiib@hot.ee> - 2020-01-07 22:58 -0800
              Re: explicit specialization problem Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-08 10:36 +0100
                Re: explicit specialization problem Öö Tiib <ootiib@hot.ee> - 2020-01-08 03:56 -0800
                  Re: explicit specialization problem Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-08 13:00 +0100
                    Re: explicit specialization problem Öö Tiib <ootiib@hot.ee> - 2020-01-08 06:02 -0800
                      Re: explicit specialization problem Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-08 15:15 +0100
                        Re: explicit specialization problem Öö Tiib <ootiib@hot.ee> - 2020-01-08 06:48 -0800
                          Re: explicit specialization problem Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-08 15:53 +0100
                            Re: explicit specialization problem Öö Tiib <ootiib@hot.ee> - 2020-01-08 07:16 -0800
                            Re: explicit specialization problem Manfred <noname@add.invalid> - 2020-01-08 16:28 +0100
                    Re: explicit specialization problem Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-01-08 15:00 +0000
                      Re: explicit specialization problem "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-08 14:44 -0800
                        Re: explicit specialization problem Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-01-09 02:20 +0000
                          Re: explicit specialization problem "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2020-01-08 19:42 -0800
                            Re: explicit specialization problem Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-01-09 18:17 +0000
                              Re: explicit specialization problem Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-01-09 19:40 +0000
                                Re: explicit specialization problem Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-01-09 21:21 +0000

Page 1 of 2  [1] 2  Next page →


#71205 — explicit specialization problem

FromBonita Montero <Bonita.Montero@gmail.com>
Date2020-01-07 11:26 +0100
Subjectexplicit specialization problem
Message-ID<qv1mcf$vi4$1@news.albasani.net>
Why does this work with an older g++ (6.3.0) and not with MSVC:

#include <iostream>

using namespace std;

template<typename T>
struct My
{
};

template<typename T>
struct Lib
{
     void f();
};

template<typename T>
void Lib<T>::f()
{
     cout << "void Lib<T>::f()" << endl;
}

template<>
template<typename T>
struct Lib<My<T>>
{
     void f();
};

template<typename T>
void Lib<My<T>>::f()
{
     cout << "void Lib<My<T>>::f()" << endl;
}

int main()
{
     Lib<My<int>> lmi;
     lmi.f();
}

MSVC:
x.cpp(22): error C2910: 'Lib<My<T>>': cannot be explicitly specialized
x.cpp(31): error C2039: 'f': is not a member of 'Lib<My<T>>'
x.cpp(30): note: see declaration of 'Lib<My<T>>'
x.cpp(31): error C2447: '{': missing function header (old-style formal 
list?)

[toc] | [next] | [standalone]


#71209

FromIan Collins <ian-news@hotmail.com>
Date2020-01-08 10:26 +1300
Message-ID<h7kbblFsqhkU3@mid.individual.net>
In reply to#71205
On 07/01/2020 23:26, Bonita Montero wrote:
> Why does this work with an older g++ (6.3.0) and not with MSVC:
> 
> #include <iostream>
> 
> using namespace std;
> 
> template<typename T>
> struct My
> {
> };
> 
> template<typename T>
> struct Lib
> {
>       void f();
> };
> 
> template<typename T>
> void Lib<T>::f()
> {
>       cout << "void Lib<T>::f()" << endl;
> }
> 
> template<>
> template<typename T>
> struct Lib<My<T>>
> {
>       void f();
> };
> 
> template<typename T>
> void Lib<My<T>>::f()
> {
>       cout << "void Lib<My<T>>::f()" << endl;
> }
> 
> int main()
> {
>       Lib<My<int>> lmi;
>       lmi.f();
> }
> 
> MSVC:
> x.cpp(22): error C2910: 'Lib<My<T>>': cannot be explicitly specialized
> x.cpp(31): error C2039: 'f': is not a member of 'Lib<My<T>>'
> x.cpp(30): note: see declaration of 'Lib<My<T>>'
> x.cpp(31): error C2447: '{': missing function header (old-style formal
> list?)


Use a more friendly compiler...

$ clang++ -std=c++17 /tmp/x.cc
/tmp/x.cc:22:1: warning: extraneous template parameter list in template 
specialization
template<>
^~~~~~~~~~

-- 
Ian.

[toc] | [prev] | [next] | [standalone]


#71210

From"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>
Date2020-01-07 23:23 +0100
Message-ID<qv30ce$5tr$1@dont-email.me>
In reply to#71205
On 07.01.2020 11:26, Bonita Montero wrote:
> Why does this work with an older g++ (6.3.0) and not with MSVC:
> 
> #include <iostream>
> 
> using namespace std;
> 
> template<typename T>
> struct My
> {
> };
> 
> template<typename T>
> struct Lib
> {
>      void f();
> };
> 
> template<typename T>
> void Lib<T>::f()
> {
>      cout << "void Lib<T>::f()" << endl;
> }
> 
> template<>
> template<typename T>
> struct Lib<My<T>>
> {
>      void f();
> };

The `template<>` does not make sense here.

Just remove that line.


> template<typename T>
> void Lib<My<T>>::f()
> {
>      cout << "void Lib<My<T>>::f()" << endl;
> }
> 
> int main()
> {
>      Lib<My<int>> lmi;
>      lmi.f();
> }
> 
> MSVC:
> x.cpp(22): error C2910: 'Lib<My<T>>': cannot be explicitly specialized
> x.cpp(31): error C2039: 'f': is not a member of 'Lib<My<T>>'
> x.cpp(30): note: see declaration of 'Lib<My<T>>'
> x.cpp(31): error C2447: '{': missing function header (old-style formal 
> list?)

I get the same diagnostics with MSVC 2019.

With MinGW g++ 9.2:

_.cpp:25:8: error: too many template-parameter-lists
    25 | struct Lib<My<T>>
       |        ^~~~~~~~~~
_.cpp:31:20: error: invalid use of incomplete type 'struct Lib<My<T> >'
    31 | void Lib<My<T>>::f()
       |                    ^
_.cpp:12:8: note: declaration of 'struct Lib<My<T> >'
    12 | struct Lib
       |        ^~~

When the offending `template<>` is removed both compilers accept the code.


- Alf


[toc] | [prev] | [next] | [standalone]


#71211

FromBonita Montero <Bonita.Montero@gmail.com>
Date2020-01-08 07:29 +0100
Message-ID<qv3srr$3dl$1@news.albasani.net>
In reply to#71210
>> template<>
>> template<typename T>
>> struct Lib<My<T>>
>> {
>>      void f();
>> };

> The `template<>` does not make sense here.
> Just remove that line.

Thanks.

[toc] | [prev] | [next] | [standalone]


#71212

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2020-01-07 22:34 -0800
Message-ID<qv3t67$1dc0$1@gioia.aioe.org>
In reply to#71211
On 1/7/2020 10:29 PM, Bonita Montero wrote:
>>> template<>
>>> template<typename T>
>>> struct Lib<My<T>>
>>> {
>>>      void f();
>>> };
> 
>> The `template<>` does not make sense here.
>> Just remove that line.
> 
> Thanks.

Your code works for me wrt removing the extra 'template<>'. Actually, in 
gcc in default, it works as is. I get an output of:

void Lib<My<T>>::f()

[toc] | [prev] | [next] | [standalone]


#71213

FromBonita Montero <Bonita.Montero@gmail.com>
Date2020-01-08 07:46 +0100
Message-ID<qv3tsm$4ps$1@news.albasani.net>
In reply to#71212
> Your code works for me wrt removing the extra 'template<>'.
> Actually, in gcc in default, it works as is. I get an output of:
> void Lib<My<T>>::f()

I think the template<> makes sense because in this case I have also
a template<>:

template<typename T>
struct S
{
};

template<>
struct S<int>
{
};

When it would be up to Alf I would have to write only:

struct S<int>
{
};

... which doesn't work.

[toc] | [prev] | [next] | [standalone]


#71214

FromÖö Tiib <ootiib@hot.ee>
Date2020-01-07 22:58 -0800
Message-ID<432e19e5-1981-48d1-85e8-d09929314ddc@googlegroups.com>
In reply to#71213
On Wednesday, 8 January 2020 08:46:55 UTC+2, Bonita Montero  wrote:
> > Your code works for me wrt removing the extra 'template<>'.
> > Actually, in gcc in default, it works as is. I get an output of:
> > void Lib<My<T>>::f()
> 
> I think the template<> makes sense because in this case I have also
> a template<>:
> 
> template<typename T>
> struct S
> {
> };
> 
> template<>
> struct S<int>
> {
> };
> 
> When it would be up to Alf I would have to write only:
> 
> struct S<int>
> {
> };
> 
> ... which doesn't work.

You had:

    template<>
    template<typename T>



[toc] | [prev] | [next] | [standalone]


#71215

FromBonita Montero <Bonita.Montero@gmail.com>
Date2020-01-08 10:36 +0100
Message-ID<qv47r5$b8n$1@news.albasani.net>
In reply to#71214
> You had:
>      template<>
>      template<typename T>

Yes, but makes also sense and it is accepted by g++.

[toc] | [prev] | [next] | [standalone]


#71217

FromÖö Tiib <ootiib@hot.ee>
Date2020-01-08 03:56 -0800
Message-ID<d1b045d5-8554-431f-99ff-f02f715fdb85@googlegroups.com>
In reply to#71215
On Wednesday, 8 January 2020 11:36:49 UTC+2, Bonita Montero  wrote:
> > You had:
> >      template<>
> >      template<typename T>
> 
> Yes, but makes also sense and it is accepted by g++.

It does not make sense in that context but lot of code that does not
make sense and even violates some rules is (often incorrectly)
accepted without any diagnostic by one or other compiler. 

[toc] | [prev] | [next] | [standalone]


#71218

FromBonita Montero <Bonita.Montero@gmail.com>
Date2020-01-08 13:00 +0100
Message-ID<qv4g8q$m28$1@news.albasani.net>
In reply to#71217
>>> You had:
>>>       template<>
>>>       template<typename T>
>> Yes, but makes also sense and it is accepted by g++.

> It does not make sense in that context ...

And why does g++ accept this ?

[toc] | [prev] | [next] | [standalone]


#71219

FromÖö Tiib <ootiib@hot.ee>
Date2020-01-08 06:02 -0800
Message-ID<1bf3538e-caec-401f-a3c2-69f53d60ee73@googlegroups.com>
In reply to#71218
On Wednesday, 8 January 2020 14:00:36 UTC+2, Bonita Montero  wrote:
> >>> You had:
> >>>       template<>
> >>>       template<typename T>
> >> Yes, but makes also sense and it is accepted by g++.
> 
> > It does not make sense in that context ...

Restoiring:
"but lot of code that does not make sense and even violates some
rules is (often incorrectly) accepted without any diagnostic by
one or other compiler."

> 
> And why does g++ accept this ?

Because the part that you snipped that I restored above. Can't
you read more than 6 words?
 

[toc] | [prev] | [next] | [standalone]


#71220

FromBonita Montero <Bonita.Montero@gmail.com>
Date2020-01-08 15:15 +0100
Message-ID<qv4o5e$18f$1@news.albasani.net>
In reply to#71219
> Restoiring:
> "but lot of code that does not make sense and even violates some
> rules is (often incorrectly) accepted without any diagnostic by
> one or other compiler."

If you have a template-specialization of a class that implements
all template-parameters it is headed with "template<>".

[toc] | [prev] | [next] | [standalone]


#71221

FromÖö Tiib <ootiib@hot.ee>
Date2020-01-08 06:48 -0800
Message-ID<d2ea939d-3dfb-4bb4-9928-1333a27b23c8@googlegroups.com>
In reply to#71220
On Wednesday, 8 January 2020 16:15:20 UTC+2, Bonita Montero  wrote:
> > Restoiring:
> > "but lot of code that does not make sense and even violates some
> > rules is (often incorrectly) accepted without any diagnostic by
> > one or other compiler."
> 
> If you have a template-specialization of a class that implements
> all template-parameters it is headed with "template<>".

But not with "template<> template<typename T>"

[toc] | [prev] | [next] | [standalone]


#71222

FromBonita Montero <Bonita.Montero@gmail.com>
Date2020-01-08 15:53 +0100
Message-ID<qv4qcj$r59$1@news.albasani.net>
In reply to#71221
Am 08.01.2020 um 15:48 schrieb Öö Tiib:
>> If you have a template-specialization of a class that implements
>> all template-parameters it is headed with "template<>".

> But not with "template<> template<typename T>"

No, that's not related to the specialization-part.

[toc] | [prev] | [next] | [standalone]


#71224

FromÖö Tiib <ootiib@hot.ee>
Date2020-01-08 07:16 -0800
Message-ID<b6b2b00a-5914-4648-879d-786fab154ef4@googlegroups.com>
In reply to#71222
On Wednesday, 8 January 2020 16:53:17 UTC+2, Bonita Montero  wrote:
> Am 08.01.2020 um 15:48 schrieb Öö Tiib:
> >> If you have a template-specialization of a class that implements
> >> all template-parameters it is headed with "template<>".
> 
> > But not with "template<> template<typename T>"
> 
> No, that's not related to the specialization-part.

Fixed g++ also complains about too large count of template parameter lists:
http://coliru.stacked-crooked.com/a/417e954f5e129b64
So whatever you tried to tell with that code does not make sense to it
as well.

[toc] | [prev] | [next] | [standalone]


#71225

FromManfred <noname@add.invalid>
Date2020-01-08 16:28 +0100
Message-ID<qv4sen$3b5$1@gioia.aioe.org>
In reply to#71222
On 1/8/2020 3:53 PM, Bonita Montero wrote:
> Am 08.01.2020 um 15:48 schrieb Öö Tiib:
>>> If you have a template-specialization of a class that implements
>>> all template-parameters it is headed with "template<>".
> 
>> But not with "template<> template<typename T>"
> 
> No, that's not related to the specialization-part.

After restoring proper (rudely removed) attributions,

Alf P. Steinbach wrote:
> Bonita Montero wrote: 
>> template<>
>> template<typename T>
>> struct Lib<My<T>>
>> {
>>      void f();
>> };
> 
> The `template<>` does not make sense here.

It is clearly related to specialization. Ref:

template<typename T>
struct S
{
};

template<typename T>
struct S<T*>
{
};

[toc] | [prev] | [next] | [standalone]


#71223

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2020-01-08 15:00 +0000
Message-ID<87tv56j8ml.fsf@bsb.me.uk>
In reply to#71218
Bonita Montero <Bonita.Montero@gmail.com> writes:

>>>> You had:
>>>>       template<>
>>>>       template<typename T>
>>> Yes, but makes also sense and it is accepted by g++.
>
>> It does not make sense in that context ...
>
> And why does g++ accept this ?

It's not accepted by recent gcc versions (8.x and above).

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#71231

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2020-01-08 14:44 -0800
Message-ID<qv5m0v$1vjn$1@gioia.aioe.org>
In reply to#71223
On 1/8/2020 7:00 AM, Ben Bacarisse wrote:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
> 
>>>>> You had:
>>>>>        template<>
>>>>>        template<typename T>
>>>> Yes, but makes also sense and it is accepted by g++.
>>
>>> It does not make sense in that context ...
>>
>> And why does g++ accept this ?
> 
> It's not accepted by recent gcc versions (8.x and above).
> 

Fwiw, still working with:

g++.exe (Rev1, Built by MSYS2 project) 7.3.0


In Clang 7.0.0-3 I get:

main.cpp:22:1: warning: extraneous template parameter list in template
       specialization

[toc] | [prev] | [next] | [standalone]


#71232

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2020-01-09 02:20 +0000
Message-ID<87o8vdjrqf.fsf@bsb.me.uk>
In reply to#71231
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:

> On 1/8/2020 7:00 AM, Ben Bacarisse wrote:
>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>
>>>>>> You had:
>>>>>>        template<>
>>>>>>        template<typename T>
>>>>> Yes, but makes also sense and it is accepted by g++.
>>>
>>>> It does not make sense in that context ...
>>>
>>> And why does g++ accept this ?
>>
>> It's not accepted by recent gcc versions (8.x and above).
>>
>
> Fwiw, still working with:
>
> g++.exe (Rev1, Built by MSYS2 project) 7.3.0

Not sure what you mean by "working".  I just tried gcc.Godbolt.org and
the oldest version that rejects the code is 8.1.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#71233

From"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Date2020-01-08 19:42 -0800
Message-ID<qv67f6$ah3$1@gioia.aioe.org>
In reply to#71232
On 1/8/2020 6:20 PM, Ben Bacarisse wrote:
> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
> 
>> On 1/8/2020 7:00 AM, Ben Bacarisse wrote:
>>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>>
>>>>>>> You had:
>>>>>>>         template<>
>>>>>>>         template<typename T>
>>>>>> Yes, but makes also sense and it is accepted by g++.
>>>>
>>>>> It does not make sense in that context ...
>>>>
>>>> And why does g++ accept this ?
>>>
>>> It's not accepted by recent gcc versions (8.x and above).
>>>
>>
>> Fwiw, still working with:
>>
>> g++.exe (Rev1, Built by MSYS2 project) 7.3.0
> 
> Not sure what you mean by "working". 

Compiling, and generating an executable.

> I just tried gcc.Godbolt.org and
> the oldest version that rejects the code is 8.1.
> 

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.c++


csiph-web