libtool-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C++ template tests (was: PGI and C++ templates)


From: Ralf Wildenhues
Subject: C++ template tests (was: PGI and C++ templates)
Date: Thu, 17 Mar 2005 18:54:10 +0100
User-agent: Mutt/1.4.1i

[ removing the libtool list from recipients ]

Hi Markus, all,

Here's a couple of new tests (for the shiny new HEAD testsuite)
for C++ with templates.

Markus, the short code you posted back some time for testing, can I put
it in a testsuite test, like in the patch below?  That would be great!

* Markus Christen wrote on Wed, Mar 16, 2005 at 09:07:52AM CET:
> Ralf Wildenhues wrote:
> >* Ralf Wildenhues wrote on Mon, Mar 14, 2005 at 07:49:00PM CET:
> >
> >>This is a status update on "libtool/pgi/C++ with templates".
> >
> >Now here's an improved patch against branch-2-0.  Should work for both
> >static and shared uninstalled libraries plus programs linked against
> >them, and seems to also work when relinking is required upon
> >installation.  It works with the example Markus provided a while ago.
*snip*
> >Testing would be *great*, as would be reviewing.
> >
> i will test it on "real-life" MD code. but we have Open-Doors days this 
> week - so no time at all.  will do it next week.

Sure, no problem.


For the tests below to pass with pgCC my PGI template patch needs a
little forward-porting.  Moreover, integration of that patch with my PGI
whole-archive patch needs a little adjustment.  Will post in another
mail.

I've got it all under control here, since all of this is nicely tested
by the new tests below.  :)

OK to apply to HEAD?  The test might need some adaptation for
portability and surely adaptation for other compilers, let's find that
out by putting it in.  :)

Regards,
Ralf

        * tests/template.at: New Autotest tests for C++ with templates.
        First test provided by Markus Christen <address@hidden>.
        * tests/Makefile.am, tests/testsuite.at: Use and distribute.

Index: tests/Makefile.am
===================================================================
RCS file: /cvsroot/libtool/libtool/tests/Makefile.am,v
retrieving revision 1.54
diff -u -r1.54 Makefile.am
--- tests/Makefile.am   11 Mar 2005 13:31:44 -0000      1.54
+++ tests/Makefile.am   17 Mar 2005 17:48:22 -0000
@@ -26,6 +26,7 @@
                  am-subdir.at \
                  functests.at \
                  stresstest.at \
+                 template.at \
                  inherited_flags.at
 
 EXTRA_DIST     = $(TESTSUITE) $(TESTSUITE_AT) package.m4
Index: tests/testsuite.at
===================================================================
RCS file: /cvsroot/libtool/libtool/tests/testsuite.at,v
retrieving revision 1.6
diff -u -r1.6 testsuite.at
--- tests/testsuite.at  4 Feb 2005 14:51:53 -0000       1.6
+++ tests/testsuite.at  17 Mar 2005 17:48:22 -0000
@@ -68,3 +68,5 @@
 m4_include([inherited_flags.at])
 # stress test
 m4_include([stresstest.at])
+# C++ templates tests
+m4_include([template.at])

--- /dev/null   2005-03-01 16:18:00.538006072 +0100
+++ tests/template.at   2005-03-17 17:07:32.206450976 +0100
@@ -0,0 +1,269 @@
+# Hand crafted tests for GNU Libtool.                         -*- Autotest -*-
+# Copyright 2005 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+
+# Test C++ and templates with libtool
+
+AT_BANNER([C++ template tests.])
+
+AT_SETUP([simple template test])
+
+: ${LIBTOOL=${abs_top_builddir}/libtool}
+eval `$LIBTOOL --tag=CXX --config | grep ^CC=`
+CXX=$CC
+
+AT_DATA(aclib.h,
+[[int cf(int);
+]])
+
+AT_DATA(aclib.cc,
+[[#include "aclib.h"
+template<typename T>
+
+T cq(T b)
+{
+  return b * 3;
+}
+
+int cf(int i)
+{
+  return cq(i);
+}
+]])
+
+AT_DATA(alib.h,
+[[int f(int);
+]])
+
+AT_DATA(alib.cc,
+[[#include "alib.h"
+
+template<typename T>
+T q(T b)
+{
+  return b * 2;
+}
+
+int f(int i)
+{
+  return q(i);
+}
+]])
+
+AT_DATA(prog.cc,
+[[#include <iostream>
+#include "alib.h"
+#include "aclib.h"
+
+using namespace std;
+
+int main()
+{
+  cout << "a sample prog" << endl;
+  cout << "f(3) = " << f(3) << endl;
+  cout << "cf(3) = " << cf(3) << endl;
+  return 0;
+}
+]])
+
+
+AT_CHECK($LIBTOOL --tag=CXX --mode=compile $CXX -I. $CPPFLAGS $CXXFLAGS -c -o 
alib.lo alib.cc, [0], [ignore], [ignore])
+AT_CHECK($LIBTOOL --tag=CXX --mode=compile $CXX -I. $CPPFLAGS $CXXFLAGS -c -o 
aclib.lo aclib.cc, [0], [ignore], [ignore])
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CPPFLAGS $CXXFLAGS -o 
libaclib.la aclib.lo, [0], [ignore], [ignore])
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CPPFLAGS $CXXFLAGS -o libalib.la 
-rpath /usr/local/lib alib.lo libaclib.la, [0], [ignore], [ignore])
+AT_CHECK($CXX -I. $CPPFLAGS $CXXFLAGS -c -o prog.o prog.cc, [0], [ignore], 
[ignore])
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CPPFLAGS $CXXFLAGS -o prog 
prog.o libalib.la, [0], [ignore], [ignore])
+
+AT_CHECK([./prog$EXEEXT], [0], [a sample prog
+f(3) = 6
+cf(3) = 9
+], [ignore])
+
+
+dnl with autoreconf, use:
+
+dnl AT_DATA(configure.ac,
+dnl [[AC_INIT([template_1], ]]AT_PACKAGE_VERSION[[, ]]AT_PACKAGE_BUGREPORT[[)
+dnl AC_CONFIG_MACRO_DIR([m4])
+dnl AC_CONFIG_AUX_DIR([config])
+dnl AM_INIT_AUTOMAKE([foreign])
+dnl AC_LANG([C++])
+dnl AC_PROG_CXX
+dnl AC_PROG_LIBTOOL
+dnl AC_CONFIG_FILES([Makefile])
+dnl AC_OUTPUT
+dnl ]])
+
+dnl AT_DATA(Makefile.am,
+dnl [[ACLOCAL_AMFLAGS = -I m4
+dnl noinst_LTLIBRARIES = libaclib.la
+dnl libaclib_la_SOURCES = aclib.cc aclib.h
+dnl lib_LTLIBRARIES = libalib.la
+dnl include_HEADERS = alib.h
+dnl libalib_la_SOURCES = alib.cc
+dnl libalib_la_LIBADD = libaclib.la
+dnl bin_PROGRAMS = prog
+dnl prog_SOURCES = prog.cc
+dnl LDADD = libalib.la
+dnl ]])
+
+AT_CLEANUP
+
+
+
+AT_SETUP([template test with subdirs])
+
+: ${LIBTOOL=${abs_top_builddir}/libtool}
+eval `$LIBTOOL --tag=CXX --config | grep ^CC=`
+CXX=$CC
+CPPFLAGS="-I../src/lib -I../src/lib2"
+
+mkdir src obj
+( cd src; mkdir lib lib2 sub )
+( cd obj; mkdir lib lib2 sub )
+
+AT_DATA(src/lib/a.hh,
+[[template <class T>
+unsigned int a(const T&);
+
+template <class T>
+unsigned int a(const T& t)
+{
+  return sizeof t;
+}
+
+extern int a2(char t);
+
+inline int a3(const double* t)
+{
+  return a(t);
+}
+]])
+
+AT_DATA(src/lib/a.cc,
+[[#include "a.hh"
+
+int a2(char t)
+{
+  return a(t);
+}
+]])
+
+AT_DATA(src/lib2/b.hh,
+[[#include "a.hh"
+
+template <class T>
+unsigned int b(T& t)
+{
+  return a(t);
+}
+extern int b2(char* t);
+struct bs { int bi; };
+extern int b3(bs t);
+]])
+
+AT_DATA(src/lib2/b.cc,
+[[#include "b.hh"
+
+int b2(char* t)
+{
+  return a2(t[0]);
+}
+
+int b3(bs t)
+{
+  return b(t);
+}
+]])
+
+AT_DATA(src/sub/main.cc,
+[[#include "b.hh"
+
+int main()
+{
+  double foo;
+  const char s = ' ';
+  char d;
+  char *t = &d;
+  return b(foo) + a3(&foo) + b2(t) - a(s)
+         - (sizeof(double) + sizeof(double*));
+}
+]])
+
+cd obj
+
+AT_CHECK($LIBTOOL --tag=CXX --mode=compile $CXX $CPPFLAGS $CXXFLAGS -c -o 
lib/a.lo ../src/lib/a.cc, [0], [ignore], [ignore])
+AT_CHECK($LIBTOOL --tag=CXX --mode=compile $CXX $CPPFLAGS $CXXFLAGS -c -o 
lib2/b.lo ../src/lib2/b.cc, [0], [ignore], [ignore])
+AT_CHECK($CXX $CPPFLAGS $CXXFLAGS -c -o sub/main.o ../src/sub/main.cc, [0], 
[ignore], [ignore])
+# both convenience
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib/liba.la 
lib/a.lo, [0], [ignore], [ignore])
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib2/libb.la 
lib2/b.lo, [0], [ignore], [ignore])
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o sub/main sub/main.o 
lib2/libb.la lib/liba.la, [0], [ignore], [ignore])
+AT_CHECK([./sub/main$EXEEXT], [ignore])
+# lib convenience
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib2/libb.la 
lib2/b.lo -rpath /foo, [0], [ignore], [ignore])
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o sub/main sub/main.o 
lib2/libb.la lib/liba.la, [0], [ignore], [ignore])
+AT_CHECK([./sub/main$EXEEXT])
+# both installed
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib/liba.la lib/a.lo 
-rpath /foo, [0], [ignore], [ignore])
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib2/libb.la 
lib2/b.lo -rpath /bar, [0], [ignore], [ignore])
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o sub/main sub/main.o 
lib2/libb.la lib/liba.la, [0], [ignore], [ignore])
+AT_CHECK([./sub/main$EXEEXT])
+# both convenience, libb depending on liba
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib/liba.la 
lib/a.lo, [0], [ignore], [ignore])
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib2/libb.la 
lib2/b.lo lib/liba.la, [0], [ignore], [ignore])
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o sub/main sub/main.o 
lib2/libb.la, [0], [ignore], [ignore])
+AT_CHECK([./sub/main$EXEEXT])
+# lib convenience
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib2/libb.la 
lib2/b.lo lib/liba.la -rpath /foo, [0], [ignore], [ignore])
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o sub/main sub/main.o 
lib2/libb.la, [0], [ignore], [ignore])
+AT_CHECK([./sub/main$EXEEXT])
+# both installed
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib/liba.la lib/a.lo 
-rpath /foo, [0], [ignore], [ignore])
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o lib2/libb.la 
lib2/b.lo lib/liba.la -rpath /bar, [0], [ignore], [ignore])
+AT_CHECK($LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS -o sub/main sub/main.o 
lib2/libb.la, [0], [ignore], [ignore])
+AT_CHECK([./sub/main$EXEEXT])
+
+cd ..
+
+dnl with autoreconf use:
+dnl
+dnl AT_DATA(src/configure.ac,
+dnl [[AC_INIT([template_2], ]]AT_PACKAGE_VERSION[[, ]]AT_PACKAGE_BUGREPORT[[)
+dnl AC_CONFIG_MACRO_DIR([m4])
+dnl AC_CONFIG_AUX_DIR([config])
+dnl AM_INIT_AUTOMAKE([foreign subdir-objects])
+dnl AC_LANG([C++])
+dnl AC_PROG_CXX
+dnl AC_PROG_LIBTOOL
+dnl AC_CONFIG_FILES([Makefile])
+dnl AC_OUTPUT
+dnl ]])
+dnl 
+dnl AT_DATA(src/Makefile.am,
+dnl [[ACLOCAL_AMFLAGS = -I m4
+dnl INCLUDES = -I$(srcdir)/lib -I$(srcdir)/lib2
+dnl bin_PROGRAMS = sub/main
+dnl noinst_LTLIBRARIES = lib/liba.la lib2/libb.la
+dnl lib_liba_la_SOURCES = lib/a.cc lib/a.hh
+dnl lib2_libb_la_SOURCES = lib2/b.cc lib2/b.hh
+dnl #lib2_libb_la_LIBADD = lib/liba.la
+dnl sub_main_SOURCES = sub/main.cc
+dnl sub_main_LDADD = lib2/libb.la lib/liba.la
+dnl ]])
+
+AT_CLEANUP




reply via email to

[Prev in Thread] Current Thread [Next in Thread]