]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
tst-unique[34].cc: Use explicit instantiation declaration/definition
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 2 Jan 2025 11:03:47 +0000 (19:03 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 2 Jan 2025 20:54:44 +0000 (04:54 +0800)
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>
elf/tst-unique3.cc
elf/tst-unique4.cc
elf/tst-unique4lib.cc

index bce3e578d791a9abf63901d84e585153f026b4f2..07a21ef4ad79f930d0ddd11aa1db485923d95cdf 100644 (file)
@@ -3,8 +3,7 @@
 #include <cstdio>
 #include "../dlfcn/dlfcn.h"
 
-template<>
-int S<char>::i;
+extern template struct S<char>;
 
 int t = S<char>::i;
 
index 46a42f15c28f92e59dc0dd81018d01ecb7e3e757..7212367fa3560d8e43c7a5479d7e1ba4e61a2bc9 100644 (file)
@@ -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>;
+extern template struct S<2>;
+extern template struct S<3>;
+extern template struct S<4>;
+extern template struct S<5>;
+extern template struct S<6>;
+extern template struct S<7>;
+extern template struct S<8>;
+extern template struct S<9>;
+extern template struct S<10>;
+extern template struct S<11>;
+extern template struct S<12>;
+extern template struct S<13>;
+extern template struct S<14>;
+extern template struct S<15>;
+extern template struct S<16>;
+extern template struct S<17>;
+extern template struct S<18>;
+extern template struct S<19>;
+extern template struct S<20>;
+extern template struct S<21>;
+extern template struct S<22>;
+extern template struct S<23>;
+extern template struct S<24>;
+
 static int a[24] =
   {
     S<1>::i, S<2>::i, S<3>::i, S<4>::i, S<5>::i, S<6>::i, S<7>::i, S<8>::i,
@@ -15,7 +35,6 @@ static int a[24] =
     S<16>::i, S<17>::i, S<18>::i, S<19>::i, S<20>::i, S<21>::i, S<22>::i,
     S<23>::i, S<24>::i
   };
-DIAG_POP_NEEDS_COMMENT_CLANG;
 
 int
 main (void)
index 2829e75ceecccc4d45c33b6da7c1df3d18cbde70..7afbe72a0e166212f0ed72bedc194c3891910a55 100644 (file)
@@ -1,17 +1,28 @@
 // BZ 12511
 #include "tst-unique4.h"
 
-template<int N>
-int S<N>::i __attribute__ ((used)) = N;
-template<int N>
-const int S<N>::j __attribute__ ((used)) = -1;
-
-static int a[24] __attribute__ ((used)) =
-  {
-    S<1>::i, S<2>::i, S<3>::i, S<4>::i, S<5>::i, S<6>::i, S<7>::i, S<8>::i,
-    S<9>::i, S<10>::i, S<11>::i, S<12>::i, S<13>::i, S<14>::i, S<15>::i,
-    S<16>::i, S<17>::i, S<18>::i, S<19>::i, S<20>::i, S<21>::i, S<22>::i,
-    S<23>::i, S<24>::i
-  };
-
-static int b __attribute__ ((used)) = S<1>::j;
+template<> int S<1>::i = 1;
+template<> int S<2>::i = 2;
+template<> int S<3>::i = 3;
+template<> int S<4>::i = 4;
+template<> int S<5>::i = 5;
+template<> int S<6>::i = 6;
+template<> int S<7>::i = 7;
+template<> int S<8>::i = 8;
+template<> int S<9>::i = 9;
+template<> int S<10>::i = 10;
+template<> int S<11>::i = 11;
+template<> int S<12>::i = 12;
+template<> int S<13>::i = 13;
+template<> int S<14>::i = 14;
+template<> int S<15>::i = 15;
+template<> int S<16>::i = 16;
+template<> int S<17>::i = 17;
+template<> int S<18>::i = 18;
+template<> int S<19>::i = 19;
+template<> int S<20>::i = 20;
+template<> int S<21>::i = 21;
+template<> int S<22>::i = 22;
+template<> int S<23>::i = 23;
+template<> int S<24>::i = 24;
+template<> const int S<1>::j = -1;