[PATCH] tst-uniquexi[34].cc: Use explicit instantiation declaration

H.J. Lu hjl.tools@gmail.com
Thu Jan 2 11:06:40 GMT 2025


On Thu, Jan 2, 2025 at 5:50 PM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > Use explicit instantiation declaration to silence Clang error:
>
> Tgere's a typo in the commit subject.

Fixed in v2.

> > 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?

Fixed in v2.

> > 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.

Fixed in v2:

https://patchwork.sourceware.org/project/glibc/patch/20250102110347.3866402-1-hjl.tools@gmail.com/

> Thanks,
> Florian
>


-- 
H.J.


More information about the Libc-alpha mailing list