[PATCH] tst-uniquexi[34].cc: Use explicit instantiation declaration
Florian Weimer
fweimer@redhat.com
Thu Jan 2 09:50:13 GMT 2025
* H. J. Lu:
> Use explicit instantiation declaration to silence Clang error:
Tgere's a typo in the commit subject.
> tst-unique3.cc:6:18: error: instantiation of variable 'S<char>::i' required here, but no definition is available [-Werror,-Wundefined-var-template]
> 6 | int t = S<char>::i;
> | ^
> ./tst-unique3.h:5:14: note: forward declaration of template entity is here
> 5 | static int i;
> | ^
> tst-unique3.cc:6:18: note: add an explicit instantiation declaration to suppress this warning if 'S<char>::i' is explicitly instantiated in another translation unit
> 6 | int t = S<char>::i;
> | ^
>
> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> ---
> elf/tst-unique3.cc | 3 +--
> elf/tst-unique4.cc | 31 +++++++++++++++++++++++++------
> 2 files changed, 26 insertions(+), 8 deletions(-)
>
> diff --git a/elf/tst-unique3.cc b/elf/tst-unique3.cc
> index bce3e578d7..53ba19a53e 100644
> --- a/elf/tst-unique3.cc
> +++ b/elf/tst-unique3.cc
> @@ -3,8 +3,7 @@
> #include <cstdio>
> #include "../dlfcn/dlfcn.h"
>
> -template<>
> -int S<char>::i;
> +extern template int S<char>::i;
Shouldn't this use the same syntax as below?
> diff --git a/elf/tst-unique4.cc b/elf/tst-unique4.cc
> index 46a42f15c2..7212367fa3 100644
> --- a/elf/tst-unique4.cc
> +++ b/elf/tst-unique4.cc
> @@ -2,12 +2,32 @@
> #include "tst-unique4.h"
>
> #include <cstdio>
> -#include <libc-diag.h>
>
> -/* clang warns that the instantiation of the variable is required, but no
> - definition is available. They are implemented on tst-unique4lib.so. */
> -DIAG_PUSH_NEEDS_COMMENT_CLANG;
> -DIAG_IGNORE_NEEDS_COMMENT_CLANG (13, "-Wundefined-var-template");
> +extern template struct S<1>;
Please add corresponding explicit instantiations to
elf/tst-unique4lib.cc. This will avoid the need for the __attribute__
((used)) stuff.
Thanks,
Florian
More information about the Libc-alpha
mailing list