glibc/elf/tst-unique3.cc
H.J. Lu dbc9a40007 tst-unique[34].cc: Use explicit instantiation declaration/definition
Use explicit instantiation declaration and definition 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>
Reviewed-by: Sam James <sam@gentoo.org>
2025-01-03 04:54:44 +08:00

26 lines
534 B
C++

#include "tst-unique3.h"
#include <cstdio>
#include "../dlfcn/dlfcn.h"
extern template struct S<char>;
int t = S<char>::i;
int
main (void)
{
std::printf ("%d %d\n", S<char>::i, t);
int result = S<char>::i++ != 1 || t != 1;
result |= in_lib ();
void *d = dlopen ("$ORIGIN/tst-unique3lib2.so", RTLD_LAZY);
int (*fp) ();
if (d == NULL || (fp = (int(*)()) dlsym (d, "in_lib2")) == NULL)
{
std::printf ("failed to get symbol in_lib2\n");
return 1;
}
result |= fp ();
dlclose (d);
return result;
}