Make the use of a C++-11 compiler optional

* configure.ac: Define a new --enable-cxx11 switch to control the
	use of the C++-11 compiler.  Define a WITH_CXX11 C macro and an
	automake ENABLE_CXX11 variable.
	* config.h.in: Initialize the new WITH_CXX11 C macro.
	* src/Makefile.am: Include the files coded in C++-11 only if the
	ENABLE_CXX11 automake variable is defined.
	* tests/Makefile.am: Likewise, build the runtestsvg test program
	only if C++-11 usage is enabled.
	* include/abg-diff-utils.h (class d_path_vec): Remove useless
	usage of the 'typename' keyword.
	* include/abg-fwd.h (is_enum_type): Renamed is_enum into this,
	because of a name clash with a tr1 function when not using C++-11.
	(is_pointer_type): Likewise, renamed is_pointer into this because
	of a name clash with a tr1 function when not using C++-11.
	* src/abg-comp-filter.cc (has_harmless_name_change): Adjust for
	the is_enum -> is_enum_type change.
	* src/abg-comparison.cc (type_suppression::suppresses_diff):
	Likewise.
	(class function_suppression::priv): Add a missing "class" keyword
	in friend declaration.
	(diff_context::diff_has_been_traversed)
	(diff_context::mark_diff_as_traversed): Do not use the C++-11
	specific type uintptr_t.
	* src/abg-dwarf-reader.cc (create_default_dwfl): Do not use
	designated initializers.  Sigh.  This is handy though.
	(expr_result::abs): Cast the argument of std::abs to avoid
	ambiguous call.
	(finish_member_function_reading): Adjust for the is_pointer ->
	is_pointer_type renaming.
	* src/abg-hash.cc (scope_decl:#️⃣:operator)
	(class_decl::base_spec:#️⃣:operator)
	(type_composition:#️⃣:operator): Use std::tr1::hash string,
	rather than the C++-11 specific std::hash function.
	* src/abg-ini.cc (read_sections, write_sections): Make
	std::ifstream constructor take a const char* rather than a string.
	* src/abg-ir.cc (is_enum_type, is_pointer_type): Renamed is_enum
	into is_enum_type and is_pointer into is_pointer_type.
	* src/abg-writer.cc (write_translation_unit): Remove useless
	typename keyword.  Make ofstream take a const char* rather than a
	string.
	(write_namespace_decl): Remove useless typename keyword.
	(write_corpus_to_native_xml_file): Make ofstream take a const
	char* rather than a string.
	* tests/test-abidiff.cc (main): Make ofstream take a const char*
	rather than a string.
	* tests/test-diff-dwarf.cc (main): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
Dodji Seketeli 2014-11-05 10:08:33 +01:00
parent 3b3b5b2b1d
commit 1082520383
15 changed files with 71 additions and 45 deletions

View File

@ -86,6 +86,9 @@
/* Version number of package */
#undef VERSION
/* Defined to 1 if a C++11 compiler is used */
#undef WITH_CXX11
/* compile the zip archive support */
#undef WITH_ZIP_ARCHIVE

View File

@ -35,6 +35,13 @@ AC_ARG_ENABLE(zip-archive,
ENABLE_ZIP_ARCHIVE=auto)
ENABLE_CXX11=no
AC_ARG_ENABLE(cxx11,
AS_HELP_STRING([--enable-cxx11=yes|no],
[enable features that use the C++11 compiler]),
ENABLE_CXX11=$enableval,
ENABLE_CXX11=no)
dnl *************************************************
dnl Here is the list of versions of the dependencies
dnl *************************************************
@ -120,6 +127,13 @@ AM_CONDITIONAL(ENABLE_ZIP_ARCHIVE, test x$ENABLE_ZIP_ARCHIVE = xyes)
DEPS_CPPFLAGS="$XML_CFLAGS $LIBZIP_CFLAGS"
AC_SUBST(DEPS_CPPFLAGS)
dnl Handle conditional use of a C++11 compiler
if test x$ENABLE_CXX11 = xyes; then
AC_DEFINE([WITH_CXX11], 1, [Defined to 1 if a C++11 compiler is used])
fi
AM_CONDITIONAL(ENABLE_CXX11, test x$ENABLE_CXX11 = xyes)
DEPS_LIBS="$XML_LIBS $LIBZIP_LIBS $DW_LIBS $ELF_LIBS"
AC_SUBST(DEPS_LIBS)
@ -153,5 +167,5 @@ AC_MSG_NOTICE([
OPTIONAL FEATURES:
Enable zip archives : ${ENABLE_ZIP_ARCHIVE}
Uses a C++-11 compiler : ${ENABLE_CXX11}
])

View File

@ -474,7 +474,7 @@ private:
/// Forbid vector size modifications
void
push_back(const typename vector<int>::value_type&);
push_back(const vector<int>::value_type&);
/// Forbid default constructor.
d_path_vec();
@ -522,15 +522,15 @@ public:
{
}
typename std::vector<int>::const_reference
std::vector<int>::const_reference
operator[](int index) const
{return at(index);}
typename std::vector<int>::reference
std::vector<int>::reference
operator[](int index)
{return at(index);}
typename std::vector<int>::reference
std::vector<int>::reference
at(long long index)
{
//check_index_against_bound(index);
@ -538,7 +538,7 @@ public:
return vector<int>::operator[](i);
}
typename std::vector<int>::const_reference
std::vector<int>::const_reference
at(long long index) const
{
check_index_against_bound(index);

View File

@ -186,10 +186,10 @@ shared_ptr<typedef_decl>
is_typedef(const shared_ptr<decl_base>);
shared_ptr<enum_type_decl>
is_enum(const shared_ptr<type_base>&);
is_enum_type(const shared_ptr<type_base>&);
shared_ptr<enum_type_decl>
is_enum(const shared_ptr<decl_base>&);
is_enum_type(const shared_ptr<decl_base>&);
shared_ptr<class_decl>
is_class_type(const shared_ptr<type_base>);
@ -198,7 +198,7 @@ shared_ptr<class_decl>
is_class_type(const shared_ptr<decl_base>);
shared_ptr<pointer_type_def>
is_pointer(const shared_ptr<type_base>);
is_pointer_type(const shared_ptr<type_base>);
shared_ptr<qualified_type_def>
is_qualified_type(const shared_ptr<type_base>);

View File

@ -1,6 +1,15 @@
lib_LTLIBRARIES=libabigail.la
libabigaildir=$(libdir)
if ENABLE_CXX11
CXX11_SOURCES = abg-viz-common.cc \
abg-viz-dot.cc \
abg-viz-svg.cc
AM_CXXFLAGS="-std=gnu++11"
else
CXX11_SOURCES =
endif
libabigail_la_SOURCES = \
abg-traverse.cc \
abg-ir.cc \
@ -16,12 +25,10 @@ abg-hash.cc \
abg-writer.cc \
abg-config.cc \
abg-ini.cc \
abg-viz-common.cc \
abg-viz-dot.cc \
abg-viz-svg.cc
$(CXX11_SOURCES)
libabigail_la_LIBADD = $(DEPS_LIBS)
libabigail_la_LDFLAGS = -Wl,--as-needed -no-undefined
AM_CPPFLAGS=$(DEPS_CPPFLAGS) -Wall -I$(abs_top_srcdir)/include -I$(abs_top_builddir)/include -I$(abs_top_builddir)
AM_CXXFLAGS="-std=gnu++11"

View File

@ -369,7 +369,7 @@ has_harmless_name_change(decl_base_sptr f, decl_base_sptr s)
return (decl_name_changed(f, s)
&& ((is_typedef(f) && is_typedef(s))
|| (is_data_member(f) && is_data_member(s))
|| (is_enum(f) && is_enum(s))));
|| (is_enum_type(f) && is_enum_type(s))));
}
/// Test if a class_diff node has non-static members added or

View File

@ -538,7 +538,7 @@ type_suppression::suppresses_diff(const diff* diff) const
// replace the abort here by a "break;" statement.
abort();
case type_suppression::ENUM_TYPE_KIND:
if (!is_enum(ft) && !is_enum(st))
if (!is_enum_type(ft) && !is_enum_type(st))
return false;
break;
case type_suppression::ARRAY_TYPE_KIND:
@ -791,7 +791,7 @@ function_suppression::parameter_spec::set_parameter_type_name_regex_str
/// type.
class function_suppression::priv
{
friend function_suppression;
friend class function_suppression;
string name_;
string name_regex_str_;
@ -2404,7 +2404,7 @@ diff_context::diff_has_been_traversed(const diff* d) const
if (!canonical)
canonical = d;
size_t ptr_value = reinterpret_cast<uintptr_t>(canonical);
size_t ptr_value = reinterpret_cast<size_t>(canonical);
return (priv_->traversed_diff_nodes_.find(ptr_value)
!= priv_->traversed_diff_nodes_.end());
}
@ -2430,7 +2430,7 @@ diff_context::mark_diff_as_traversed(const diff* d)
canonical = d;
}
size_t ptr_value = reinterpret_cast<uintptr_t>(canonical);
size_t ptr_value = reinterpret_cast<size_t>(canonical);
priv_->traversed_diff_nodes_[ptr_value] = true;
}

View File

@ -2447,14 +2447,11 @@ finish_member_function_reading(Dwarf_Die* die,
static Dwfl*
create_default_dwfl(char** debug_info_root_path)
{
static Dwfl_Callbacks offline_callbacks =
{
0,
.find_debuginfo = dwfl_standard_find_debuginfo,
.section_address = dwfl_offline_section_address,
0
};
static Dwfl_Callbacks offline_callbacks;
memset(&offline_callbacks, 0, sizeof(offline_callbacks));
offline_callbacks.find_debuginfo = dwfl_standard_find_debuginfo;
offline_callbacks.section_address = dwfl_offline_section_address;
offline_callbacks.debuginfo_path = debug_info_root_path;
return dwfl_begin(&offline_callbacks);
}
@ -3290,7 +3287,7 @@ public:
abs() const
{
expr_result r = *this;
r.const_value_ = std::abs(r.const_value());
r.const_value_ = std::abs(static_cast<long double>(r.const_value()));
return r;
}
@ -4920,7 +4917,7 @@ finish_member_function_reading(Dwarf_Die* die,
type_base_sptr other_klass;
if (is_artificial)
this_ptr_type = is_pointer(first_parm->get_type());
this_ptr_type = is_pointer_type(first_parm->get_type());
if (this_ptr_type)
other_klass = this_ptr_type->get_pointed_to_type();
// Sometimes, other_klass can be qualified; e.g, volatile. In

View File

@ -133,7 +133,7 @@ scope_decl::hash::operator()(const scope_decl& d) const
{
if (d.peek_hash_value() == 0 || d.hashing_started())
{
std::hash<string> hash_string;
std::tr1::hash<string> hash_string;
size_t v = hash_string(typeid(d).name());
for (scope_decl::declarations::const_iterator i =
d.get_member_decls().begin();
@ -546,9 +546,9 @@ class_decl::base_spec::hash::operator()(const base_spec& t) const
{
member_base::hash hash_member;
type_base::shared_ptr_hash hash_type_ptr;
std::hash<size_t> hash_size;
std::hash<bool> hash_bool;
std::hash<string> hash_string;
std::tr1::hash<size_t> hash_size;
std::tr1::hash<bool> hash_bool;
std::tr1::hash<string> hash_string;
size_t v = hash_string(typeid(t).name());
v = hashing::combine_hashes(v, hash_member(t));
@ -821,7 +821,7 @@ operator()(const template_parameter* t) const
size_t
type_composition::hash::operator()(const type_composition& t) const
{
std::hash<string> hash_string;
std::tr1::hash<string> hash_string;
type_base::dynamic_hash hash_type;
size_t v = hash_string(typeid(t).name());

View File

@ -663,7 +663,7 @@ bool
read_sections(const string& path,
config::sections_type& sections)
{
std::ifstream in(path, std::ifstream::binary);
std::ifstream in(path.c_str(), std::ifstream::binary);
if (!in.good())
return false;
@ -812,7 +812,7 @@ bool
write_sections(const config::sections_type& sections,
const string& path)
{
std::ofstream f(path, std::ofstream::binary);
std::ofstream f(path.c_str(), std::ofstream::binary);
if (!f.good())
return false;

View File

@ -3012,7 +3012,7 @@ is_typedef(const decl_base_sptr d)
///
/// @return the enum_type_decl_sptr if @p d is an enum, nil otherwise.
enum_type_decl_sptr
is_enum(const decl_base_sptr& d)
is_enum_type(const decl_base_sptr& d)
{return dynamic_pointer_cast<enum_type_decl>(d);}
/// Test if a type is an enum_type_decl
@ -3021,7 +3021,7 @@ is_enum(const decl_base_sptr& d)
///
/// @return the enum_type_decl_sptr if @p t is an enum, nil otherwise.
enum_type_decl_sptr
is_enum(const type_base_sptr& t)
is_enum_type(const type_base_sptr& t)
{return dynamic_pointer_cast<enum_type_decl>(t);}
/// Test whether a type is a class.
@ -3058,7 +3058,7 @@ is_class_type(const decl_base_sptr d)
/// @return the @ref pointer_type_def_sptr if @p t is a
/// pointer_type_def, null otherwise.
pointer_type_def_sptr
is_pointer(const type_base_sptr t)
is_pointer_type(const type_base_sptr t)
{return dynamic_pointer_cast<pointer_type_def>(t);}
/// Test whether a type is a qualified_type_def.

View File

@ -883,7 +883,7 @@ write_translation_unit(const translation_unit& tu,
o << ">";
typedef scope_decl::declarations declarations;
typedef typename declarations::const_iterator const_iterator;
typedef declarations::const_iterator const_iterator;
const declarations& d = tu.get_global_scope()->get_member_decls();
for (const_iterator i = d.begin(); i != d.end(); ++i)
@ -937,7 +937,7 @@ write_translation_unit(const translation_unit& tu,
try
{
ofstream of(path, std::ios_base::trunc);
ofstream of(path.c_str(), std::ios_base::trunc);
if (!of.is_open())
{
cerr << "failed to access " << path << "\n";
@ -1023,7 +1023,7 @@ write_namespace_decl(const shared_ptr<namespace_decl> decl,
o << "<namespace-decl name='" << decl->get_name() << "'>";
typedef scope_decl::declarations declarations;
typedef typename declarations::const_iterator const_iterator;
typedef declarations::const_iterator const_iterator;
const declarations& d = decl->get_member_decls();
for (const_iterator i = d.begin(); i != d.end(); ++i)
@ -2542,7 +2542,7 @@ write_corpus_to_native_xml_file(const corpus_sptr corpus,
try
{
ofstream of(path, std::ios_base::trunc);
ofstream of(path.c_str(), std::ios_base::trunc);
if (!of.is_open())
{
cerr << "failed to access " << path << "\n";

View File

@ -6,6 +6,12 @@ else
ZIP_ARCHIVE_TESTS =
endif
if ENABLE_CXX11
CXX11_TESTS = runtestsvg
else
CXX11_TESTS =
endif
TESTS= \
runtestreadwrite \
${ZIP_ARCHIVE_TESTS} \
@ -17,7 +23,7 @@ runtestabidiff \
runtestdiffdwarf \
runtestdifffilter \
runtestdiffsuppr \
runtestsvg
${CXX11_TESTS}
noinst_PROGRAMS= $(TESTS) testirwalker testdiff2 printdifftree
@ -82,7 +88,6 @@ printdifftree_LDADD = $(top_builddir)/src/libabigail.la
AM_CPPFLAGS=-I${abs_top_srcdir}/include \
-I${abs_top_builddir}/include -I${abs_top_srcdir}/tools
AM_CXXFLAGS="-std=gnu++11"
EXTRA_DIST= \
data/test-read-write/test0.xml \

View File

@ -153,7 +153,7 @@ main(int, char*[])
}
translation_unit_diff_sptr d = compute_diff(tu1, tu2);
ofstream of(out_path, std::ios_base::trunc);
ofstream of(out_path.c_str(), std::ios_base::trunc);
if (!of.is_open())
{
cerr << "failed to read " << s->out_path << "\n";

View File

@ -231,7 +231,7 @@ main()
ref_diff_report_path = get_src_dir() + "/tests/" + s->in_report_path;
out_diff_report_path = get_build_dir() + "/tests/" + s->out_report_path;
ofstream of(out_diff_report_path, std::ios_base::trunc);
ofstream of(out_diff_report_path.c_str(), std::ios_base::trunc);
if (!of.is_open())
{
cerr << "failed to read " << out_diff_report_path << "\n";