[PATCH v2] tst-unique4.cc: Add explicit instantiation declaration S<N>::i
H.J. Lu
hjl.tools@gmail.com
Tue Dec 31 11:19:04 GMT 2024
On Tue, Dec 31, 2024 at 7:09 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Tue, Dec 31, 2024 at 6:28 PM Florian Weimer <fweimer@redhat.com> wrote:
> >
> > * H. J. Lu:
> >
> > > On Mon, Dec 30, 2024 at 6:39 PM Florian Weimer <fweimer@redhat.com> wrote:
> > >>
> > >> * H. J. Lu:
> > >>
> > >> > Clang 19 complains:
> > >> > tst-unique4.cc:7:16: error: expected unqualified-id
> > >> > 7 | extern template<> int S<1>;
> > >> > | ^
> > >> > 1 error generated.
> > >>
> > >> I should habe looked up the syntax. It's this:
> > >>
> > >> extern template class S<1>;
> > >
> > > tst-unique4.cc:7:17: error: class template 'S' was previously declared
> > > as a struct template; this is valid, but may result in linker errors
> > > under the Microsoft C++ ABI [-Werror,-Wmismatched-tags]
> > > 7 | extern template class S<1>;
> > > | ^
> > > ./tst-unique4.h:3:8: note: previous use is here
> > > 3 | struct S
> > > | ^
> > > tst-unique4.cc:7:17: note: did you mean struct here?
> > > 7 | extern template class S<1>;
> > > | ^~~~~
> > > | struct
> > > 1 error generated.
> >
> > Does replacing class with struct work?
>
> No.
>
> tst-unique4.cc:11:20: error: instantiation of variable 'S<2>::i'
> required here, but no definition is available
> [-Werror,-Wundefined-var-template]
> 11 | S<1>::i, S<2>::i, S<3>::i, S<4>::i, S<5>::i, S<6>::i,
> S<7>::i, S<8>::i,
> | ^
> ./tst-unique4.h:5:14: note: forward declaration of template entity is here
> 5 | static int i;
> | ^
> tst-unique4.cc:11:20: note: add an explicit instantiation declaration
> to suppress this warning if 'S<2>::i' is explicitly instantiated in
> another translation unit
> 11 | S<1>::i, S<2>::i, S<3>::i, S<4>::i, S<5>::i, S<6>::i,
> S<7>::i, S<8>::i,
> | ^
> 1 error generated.
>
It needs 25 explicit instantiation declarations. Passing
-Wno-undefined-var-template to clang silences the error.
--
H.J.
More information about the Libc-alpha
mailing list