Only build and tested by run-readelf-unknown.sh if a g++ with c++x0 is available. Fairly simple C++ program, can be extended to test more features.
Signed-off-by: Mark Wielaard <[email protected]> --- ChangeLog | 4 ++ configure.ac | 5 ++ m4/ChangeLog | 4 ++ m4/ax_cxx_compile_stdcxx_0x.m4 | 107 ++++++++++++++++++++++++++++++++ tests/ChangeLog | 8 +++ tests/Makefile.am | 7 ++- tests/cpp-various.cxx | 136 +++++++++++++++++++++++++++++++++++++++++ tests/run-readelf-unknown.sh | 5 ++ 8 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 m4/ax_cxx_compile_stdcxx_0x.m4 create mode 100644 tests/cpp-various.cxx diff --git a/ChangeLog b/ChangeLog index 5842492..3be157c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2012-07-24 Mark Wielaard <[email protected]> + * configure.ac: Add AX_CXX_COMPILE_STDCXX_0X check. + +2012-07-24 Mark Wielaard <[email protected]> + * TODO: Add note on shdrs after elf_cntl (ELF_C_FDREAD). 2012-06-22 Mark Wielaard <[email protected]> diff --git a/configure.ac b/configure.ac index 31ab21c..088dde3 100644 --- a/configure.ac +++ b/configure.ac @@ -72,6 +72,11 @@ AC_PROG_RANLIB AC_PROG_YACC AM_PROG_LEX +# Check whether we can use g++ with -std=c++0x for the test. +AC_PROG_CXX +AX_CXX_COMPILE_STDCXX_0X +AM_CONDITIONAL(HAVE_STDCXX_0X, test "x$ax_cv_cxx_compile_cxx0x_cxx" == "xyes") + AC_CACHE_CHECK([for gcc with C99 support], ac_cv_c99, [dnl old_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -std=gnu99" diff --git a/m4/ChangeLog b/m4/ChangeLog index d4f2bc1..af717c4 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,7 @@ +2012-07-24 Mark Wielaard <[email protected]> + + * ax_cxx_compile_stdcxx_0x.m4: Add from autoconf-archive. + 2010-04-14 Roland McGrath <[email protected]> * gettext.m4: Upgrade to gettext-0.17. diff --git a/m4/ax_cxx_compile_stdcxx_0x.m4 b/m4/ax_cxx_compile_stdcxx_0x.m4 new file mode 100644 index 0000000..a4e556f --- /dev/null +++ b/m4/ax_cxx_compile_stdcxx_0x.m4 @@ -0,0 +1,107 @@ +# ============================================================================ +# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_0x.html +# ============================================================================ +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX_0X +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the C++0x +# standard. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik <[email protected]> +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 7 + +AU_ALIAS([AC_CXX_COMPILE_STDCXX_0X], [AX_CXX_COMPILE_STDCXX_0X]) +AC_DEFUN([AX_CXX_COMPILE_STDCXX_0X], [ + AC_CACHE_CHECK(if g++ supports C++0x features without additional flags, + ax_cv_cxx_compile_cxx0x_native, + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + AC_TRY_COMPILE([ + template <typename T> + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check<check<bool>> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check<int> check_type; + check_type c; + check_type&& cr = static_cast<check_type&&>(c);],, + ax_cv_cxx_compile_cxx0x_native=yes, ax_cv_cxx_compile_cxx0x_native=no) + AC_LANG_RESTORE + ]) + + AC_CACHE_CHECK(if g++ supports C++0x features with -std=c++0x, + ax_cv_cxx_compile_cxx0x_cxx, + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -std=c++0x" + AC_TRY_COMPILE([ + template <typename T> + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check<check<bool>> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check<int> check_type; + check_type c; + check_type&& cr = static_cast<check_type&&>(c);],, + ax_cv_cxx_compile_cxx0x_cxx=yes, ax_cv_cxx_compile_cxx0x_cxx=no) + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE + ]) + + AC_CACHE_CHECK(if g++ supports C++0x features with -std=gnu++0x, + ax_cv_cxx_compile_cxx0x_gxx, + [AC_LANG_SAVE + AC_LANG_CPLUSPLUS + ac_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -std=gnu++0x" + AC_TRY_COMPILE([ + template <typename T> + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + typedef check<check<bool>> right_angle_brackets; + + int a; + decltype(a) b; + + typedef check<int> check_type; + check_type c; + check_type&& cr = static_cast<check_type&&>(c);],, + ax_cv_cxx_compile_cxx0x_gxx=yes, ax_cv_cxx_compile_cxx0x_gxx=no) + CXXFLAGS="$ac_save_CXXFLAGS" + AC_LANG_RESTORE + ]) + + if test "$ax_cv_cxx_compile_cxx0x_native" = yes || + test "$ax_cv_cxx_compile_cxx0x_cxx" = yes || + test "$ax_cv_cxx_compile_cxx0x_gxx" = yes; then + AC_DEFINE(HAVE_STDCXX_0X,,[Define if g++ supports C++0x features. ]) + fi +]) diff --git a/tests/ChangeLog b/tests/ChangeLog index 6993273..59074a1 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,11 @@ +2012-07-24 Mark Wielaard <[email protected]> + + * cpp-various.cxx: New testfile. + * Makefile.am (cpp_various_SOURCES): New. + (HAVE_STDCXX_0X): Add cpp-various and -std=c++0x if exists. + (EXTRA_DIST): Add cpp-various.cxx + * run-readelf-unknown.sh: runtest ./cpp-various if exists. + 2012-07-19 Mark Wielaard <[email protected]> * run-readelf-unknown.sh: New test. diff --git a/tests/Makefile.am b/tests/Makefile.am index 2bd5ca6..038d374 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -94,6 +94,11 @@ check_PROGRAMS += $(asm_TESTS) TESTS += $(asm_TESTS) endif +if HAVE_STDCXX_0X +check_PROGRAMS += cpp-various +AM_CXXFLAGS = -std=c++0x +cpp_various_SOURCES = cpp-various.cxx +endif EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ run-show-die-info.sh run-get-files.sh run-get-lines.sh \ @@ -129,7 +134,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ coverage.sh test-subr.sh test-wrapper.sh \ run-readelf-test1.sh run-readelf-test2.sh run-readelf-test3.sh \ run-readelf-test4.sh run-readelf-twofiles.sh \ - run-readelf-unknown.sh \ + run-readelf-unknown.sh cpp-various.cxx \ run-bug1-test.sh testfile28.bz2 testfile28.rdwr.bz2 \ testfile29.bz2 testfile29.rdwr.bz2 \ testfile30.bz2 testfile31.bz2 testfile32.bz2 testfile33.bz2 \ diff --git a/tests/cpp-various.cxx b/tests/cpp-various.cxx new file mode 100644 index 0000000..39db5a1 --- /dev/null +++ b/tests/cpp-various.cxx @@ -0,0 +1,136 @@ +/* Test program for testing C++0X features are recognized. + Copyright (C) 2012 Red Hat, Inc. + This file is part of elfutils. + + This file 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 3 of the License, or + (at your option) any later version. + + elfutils 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, see <http://www.gnu.org/licenses/>. */ + +#include <iostream> + +using namespace std; + +#define PI 3.14159 +#define NEWLINE '\n' + +int arr[5] = { 1, 26, 7, 740, 1271 }; +char days[365][24][60][60]; +int *b; + +struct p { int w; float p;}; +p a; + +typedef char CHAR; +typedef int INT; +typedef float FLOAT; + +union u +{ + CHAR c; + INT i; + FLOAT f; + union + { + int i2; + char c2; + }; + union sub + { + float f; + double d; + }; + union chars + { + char c; + unsigned char uc; + signed char sc; + wchar_t wc; + char16_t c16; + char32_t c32; + }; +}; + +enum en { foo, bar, baz }; +enum en2 { en_a = 1, en_b, en_c, en_d, en_e, en_f = 16}; + +class Rect +{ + int x, y; +public: + void set (int, int); + int get () { return (x * y); }; +}; + +void Rect::set (int a, int b) +{ + x = a; + y = b; +} + +double print_circle (double r) +{ + double ret; + ret = 2 * PI *r; + cout << "circle r:" << r << " circle: " << ret << NEWLINE; + return ret; +} + +void printp (p foo) +{ + cout << foo.w << ", " << foo.p << endl; +} + +int substract (int a, int b=1) +{ + int ret; + ret = a - b; + return (ret); +} + +template <class T, int N> +class seq { + T mem [N]; +public: + void set (int x, T value); + T get (int x); +}; + +template <class T, int N> +void seq<T,N>::set (int x, T val) +{ + mem[x] = val; +} + +template <class T, int N> +T seq<T,N>::get (int x) +{ + return mem[x]; +} + +seq <int, 13> ints; +seq <Rect, 42> rects; + +int main () +{ + b = new int [5]; + cout << "Hello World!"; + double c = print_circle (5.0); + int l = substract (c); + a.w = l; + a.p = 42.50; + printp (a); + delete[] b; + Rect rect; + rect.set (3, 4); + cout << "rect: " << rect.get () << endl; + return 0; +} diff --git a/tests/run-readelf-unknown.sh b/tests/run-readelf-unknown.sh index d3541f2..056674a 100755 --- a/tests/run-readelf-unknown.sh +++ b/tests/run-readelf-unknown.sh @@ -54,6 +54,11 @@ runtest ../backends/libebl_sh.so runtest ../backends/libebl_sparc.so runtest ../backends/libebl_x86_64.so +# Might not exist if we don't have a c++ compiler around +if test -f ./cpp-various; then + runtest ./cpp-various +fi + test_cleanup exit $status -- 1.7.11.2 _______________________________________________ elfutils-devel mailing list [email protected] https://fedorahosted.org/mailman/listinfo/elfutils-devel
