[PATCH v2] tst-unique4.cc: Add explicit instantiation declaration S<N>::i
H.J. Lu
hjl.tools@gmail.com
Tue Dec 17 18:14:07 GMT 2024
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;
+template<>
+int S<2>::i;
+template<>
+int S<3>::i;
+template<>
+int S<4>::i;
+template<>
+int S<5>::i;
+template<>
+int S<6>::i;
+template<>
+int S<7>::i;
+template<>
+int S<8>::i;
+template<>
+int S<9>::i;
+template<>
+int S<10>::i;
+template<>
+int S<11>::i;
+template<>
+int S<12>::i;
+template<>
+int S<13>::i;
+template<>
+int S<14>::i;
+template<>
+int S<15>::i;
+template<>
+int S<16>::i;
+template<>
+int S<17>::i;
+template<>
+int S<18>::i;
+template<>
+int S<19>::i;
+template<>
+int S<20>::i;
+template<>
+int S<21>::i;
+template<>
+int S<22>::i;
+template<>
+int S<23>::i;
+template<>
+int S<24>::i;
+
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,
diff --git a/elf/tst-unique4lib.cc b/elf/tst-unique4lib.cc
index 17a7cdf567..2829e75cee 100644
--- a/elf/tst-unique4lib.cc
+++ b/elf/tst-unique4lib.cc
@@ -2,7 +2,7 @@
#include "tst-unique4.h"
template<int N>
-int S<N>::i = N;
+int S<N>::i __attribute__ ((used)) = N;
template<int N>
const int S<N>::j __attribute__ ((used)) = -1;
--
2.47.1
More information about the Libc-alpha
mailing list