[PATCH v2] tst-unique4.cc: Add explicit instantiation declaration S<N>::i

Florian Weimer fweimer@redhat.com
Fri Dec 27 06:55:49 GMT 2024


* H. J. Lu:

> Add Add explicit instantiation declaration for S<N>::i and mark S<N>::i
> is used to silence Clang error:
>
> tst-unique4.cc:8:11: error: instantiation of variable 'S<1>::i' required here, but no definition is available [-Werror,-Wundefined-var-template]
>     8 |     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:8:11: note: add an explicit instantiation declaration to suppress this warning if 'S<1>::i' is explicitly instantiated in another translation unit
>     8 |     S<1>::i, S<2>::i, S<3>::i, S<4>::i, S<5>::i, S<6>::i, S<7>::i, S<8>::i,
>       |           ^
>
> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> ---
>  elf/tst-unique4.cc    | 49 +++++++++++++++++++++++++++++++++++++++++++
>  elf/tst-unique4lib.cc |  2 +-
>  2 files changed, 50 insertions(+), 1 deletion(-)
>
> diff --git a/elf/tst-unique4.cc b/elf/tst-unique4.cc
> index 575c70d3a1..f3bfe06a02 100644
> --- a/elf/tst-unique4.cc
> +++ b/elf/tst-unique4.cc
> @@ -3,6 +3,55 @@
>  
>  #include <cstdio>
>  
> +template<>
> +int S<1>::i;

I would expect

extern template<> int S<1>::i;

here, and the instantiations in elf/tst-unique4lib.cc.  It looks to me
as if the test objective here is not to have STB_GNU_UNIQUE symbols in
the main program.

Thanks,
Florian



More information about the Libc-alpha mailing list