浏览代码

cacheset: Fix compilation on new GCC in C++98 mode

Since gcc 4.9, the API for erase slightly changed. In
commit 3dddcdf2432e78f37c74d8c76c2c519a8d935ab2 the
existing checks for __cplusplus where changed to
check the gcc version, as the __cplusplus check
did nothing, because gcc 4.8 already provided the
standard value in there.

Fix the code to check for the gcc version in two
more places, and change the existing checks to
use a convenience macro.
Julian Andres Klode 10 年之前
父节点
当前提交
2c1e4917d9
共有 2 个文件被更改,包括 29 次插入3 次删除
  1. 3 3
      apt-pkg/cacheset.h
  2. 26 0
      test/integration/header-compilation

+ 3 - 3
apt-pkg/cacheset.h

@@ -644,7 +644,7 @@ template<> inline void PackageContainer<std::vector<pkgCache::PkgIterator> >::in
 	for (const_iterator p = begin; p != end; ++p)
 	for (const_iterator p = begin; p != end; ++p)
 		_cont.push_back(*p);
 		_cont.push_back(*p);
 }
 }
-#if __cplusplus < 201103L
+#if APT_GCC_VERSION < 0x409
 template<> inline PackageContainer<std::set<pkgCache::PkgIterator> >::iterator PackageContainer<std::set<pkgCache::PkgIterator> >::erase(iterator i) {
 template<> inline PackageContainer<std::set<pkgCache::PkgIterator> >::iterator PackageContainer<std::set<pkgCache::PkgIterator> >::erase(iterator i) {
 	_cont.erase(i._iter);
 	_cont.erase(i._iter);
 	return end();
 	return end();
@@ -897,7 +897,7 @@ public:									/*{{{*/
 	bool empty() const APT_OVERRIDE { return _cont.empty(); }
 	bool empty() const APT_OVERRIDE { return _cont.empty(); }
 	void clear() APT_OVERRIDE { return _cont.clear(); }
 	void clear() APT_OVERRIDE { return _cont.clear(); }
 	size_t size() const APT_OVERRIDE { return _cont.size(); }
 	size_t size() const APT_OVERRIDE { return _cont.size(); }
-#if __GNUC__ >= 5 || (__GNUC_MINOR__ >= 9 && __GNUC__ >= 4)
+#if APT_GCC_VERSION >= 0x409
 	iterator erase( const_iterator pos ) { return iterator(_cont.erase(pos._iter)); }
 	iterator erase( const_iterator pos ) { return iterator(_cont.erase(pos._iter)); }
 	iterator erase( const_iterator first, const_iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
 	iterator erase( const_iterator first, const_iterator last ) { return iterator(_cont.erase(first._iter, last._iter)); }
 #else
 #else
@@ -1148,7 +1148,7 @@ template<> inline void VersionContainer<std::vector<pkgCache::VerIterator> >::in
 	for (const_iterator v = begin; v != end; ++v)
 	for (const_iterator v = begin; v != end; ++v)
 		_cont.push_back(*v);
 		_cont.push_back(*v);
 }
 }
-#if __cplusplus < 201103L
+#if APT_GCC_VERSION < 0x409
 template<> inline VersionContainer<std::set<pkgCache::VerIterator> >::iterator VersionContainer<std::set<pkgCache::VerIterator> >::erase(iterator i) {
 template<> inline VersionContainer<std::set<pkgCache::VerIterator> >::iterator VersionContainer<std::set<pkgCache::VerIterator> >::erase(iterator i) {
 	_cont.erase(i._iter);
 	_cont.erase(i._iter);
 	return end();
 	return end();

+ 26 - 0
test/integration/header-compilation

@@ -0,0 +1,26 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+setupenvironment
+
+(for i in $TESTDIR/../../build/include/apt-pkg/*.h; do echo "#include \"$i\""; done) > include.h
+
+
+testone() {
+    local cxx=$1
+    shift
+
+    if type $cxx 2>&1 1>/dev/null; then
+        testsuccess $cxx -c -o /dev/null include.h
+        testsuccess $cxx -c -o /dev/null -std=c++98 include.h
+        testsuccess $cxx -c -o /dev/null -std=c++11 include.h
+    else
+        msgskip "Compile $cxx is not installed"
+    fi
+}
+
+testone clang++
+testone g++
+testone g++-4.8