[PATCH] tst-unique3.cc: Explicitly instantiate S<char>::i
Sam James
sam@gentoo.org
Tue Dec 17 15:10:10 GMT 2024
"H.J. Lu" <hjl.tools@gmail.com> writes:
> Explicitly instantiate S<char>::i to silence Clang error:
>
> 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>
> ---
OK but try my trick from the other patch too, better if that works.
> elf/tst-unique3.cc | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/elf/tst-unique3.cc b/elf/tst-unique3.cc
> index efdd6d78c2..bce3e578d7 100644
> --- a/elf/tst-unique3.cc
> +++ b/elf/tst-unique3.cc
> @@ -3,6 +3,9 @@
> #include <cstdio>
> #include "../dlfcn/dlfcn.h"
>
> +template<>
> +int S<char>::i;
> +
> int t = S<char>::i;
>
> int
More information about the Libc-alpha
mailing list