Date: Tue, 14 Jan 2025 09:55:00 -0500
Maybe you guys missed it, but Brian Bi already gave the authoritative
answer in this thread: "This is a known issue and needs a paper to fix."
(Brian, is there any prior discussion — a CWG issue, any old papers, etc.?)
The natural syntax seems to be https://gcc.godbolt.org/z/6n86jnY4W
template <typename T> int x;
template <typename T> int f();
template<> extern int x<int>;
template<> extern int f<int>();
int f() {
return x<int> + x<long>;
}
template <>
int x<int> = 4;
template <>
int f<int>() { return 4; }
Clang trunk already accepts this syntax, with a warning that it's
non-standard.
GCC, EDG, and MSVC all reject: `template<> extern [...]` isn't allowed
because the grammar for a template specialization doesn't include
storage-class for some historical reason ([temp.expl.spec]/2
<https://eel.is/c++draft/temp.expl.spec#2>).
Seems like a good idea to me, FWIW; but going back and forth on this
mailing list isn't going to change the status quo. "This is a known issue
and needs a paper to fix."
–Arthur
On Tue, Jan 14, 2025 at 9:13 AM Thiago Macieira via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> On Tuesday 14 January 2025 03:29:32 Pacific Standard Time Avi Kivity wrote:
> > Errors:
> >
> > <source>:14:13: error: explicit specialization of 'x' after
> > instantiation
> > 14 | int A<int>::x = 4;
> >
> > | ^
> >
> > <source>:6:24: note: explicit instantiation first required here
> > 6 | extern template struct A<int>;
> >
> > | ^
> >
> > 1 error generated.
> > Compiler returned: 1
>
> Works with three other compiler front-ends:
> https://gcc.godbolt.org/z/ddTqrqn7f
>
> I don't know if this is a Clang bug or just under-specified in the
> standard.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Principal Engineer - Intel DCAI Platform & System Engineering
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
answer in this thread: "This is a known issue and needs a paper to fix."
(Brian, is there any prior discussion — a CWG issue, any old papers, etc.?)
The natural syntax seems to be https://gcc.godbolt.org/z/6n86jnY4W
template <typename T> int x;
template <typename T> int f();
template<> extern int x<int>;
template<> extern int f<int>();
int f() {
return x<int> + x<long>;
}
template <>
int x<int> = 4;
template <>
int f<int>() { return 4; }
Clang trunk already accepts this syntax, with a warning that it's
non-standard.
GCC, EDG, and MSVC all reject: `template<> extern [...]` isn't allowed
because the grammar for a template specialization doesn't include
storage-class for some historical reason ([temp.expl.spec]/2
<https://eel.is/c++draft/temp.expl.spec#2>).
Seems like a good idea to me, FWIW; but going back and forth on this
mailing list isn't going to change the status quo. "This is a known issue
and needs a paper to fix."
–Arthur
On Tue, Jan 14, 2025 at 9:13 AM Thiago Macieira via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> On Tuesday 14 January 2025 03:29:32 Pacific Standard Time Avi Kivity wrote:
> > Errors:
> >
> > <source>:14:13: error: explicit specialization of 'x' after
> > instantiation
> > 14 | int A<int>::x = 4;
> >
> > | ^
> >
> > <source>:6:24: note: explicit instantiation first required here
> > 6 | extern template struct A<int>;
> >
> > | ^
> >
> > 1 error generated.
> > Compiler returned: 1
>
> Works with three other compiler front-ends:
> https://gcc.godbolt.org/z/ddTqrqn7f
>
> I don't know if this is a Clang bug or just under-specified in the
> standard.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Principal Engineer - Intel DCAI Platform & System Engineering
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2025-01-14 14:55:16