Merge pull request #41 from mat007/fix-c++17-compliance

Fix clang build
This commit is contained in:
Mathieu Champlon 2018-04-08 17:47:22 +02:00 committed by GitHub
commit d162eeb8fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 98 additions and 123 deletions

1
.gitattributes vendored Normal file
View file

@ -0,0 +1 @@
*.sh text eol=lf

View file

@ -10,23 +10,32 @@
# #
sudo: false sudo: false
language: cpp
os:
- linux
env: env:
- CXX_STANDARD=c++98 BRANCH_TO_TEST=boost-1.58.0
- CXX_STANDARD=c++11 BRANCH_TO_TEST=boost-1.58.0
- CXX_STANDARD=c++98 BRANCH_TO_TEST=boost-1.59.0
- CXX_STANDARD=c++11 BRANCH_TO_TEST=boost-1.59.0
- CXX_STANDARD=c++98 BRANCH_TO_TEST=master
- CXX_STANDARD=c++11 BRANCH_TO_TEST=master
- CXX_STANDARD=c++14 BRANCH_TO_TEST=master
- CXX_STANDARD=c++17 BRANCH_TO_TEST=master - CXX_STANDARD=c++17 BRANCH_TO_TEST=master
- CXX_STANDARD=c++14 BRANCH_TO_TEST=master
- CXX_STANDARD=c++11 BRANCH_TO_TEST=master
- CXX_STANDARD=c++98 BRANCH_TO_TEST=master
- CXX_STANDARD=c++11 BRANCH_TO_TEST=boost-1.58.0
- CXX_STANDARD=c++98 BRANCH_TO_TEST=boost-1.58.0
- CXX_STANDARD=c++11 BRANCH_TO_TEST=boost-1.59.0
- CXX_STANDARD=c++98 BRANCH_TO_TEST=boost-1.59.0
compiler:
- clang
- gcc
addons: addons:
apt: apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise
packages: packages:
- gcc-5
- g++-5
- clang-5.0
- lld-5.0
- xsltproc - xsltproc
- docbook-xsl - docbook-xsl
- docbook-xml - docbook-xml
@ -35,6 +44,9 @@ before_install:
- DOCBOOK_XSL_DIR=/usr/share/xml/docbook/stylesheet/docbook-xsl - DOCBOOK_XSL_DIR=/usr/share/xml/docbook/stylesheet/docbook-xsl
- DOCBOOK_DTD_DIR=/usr/share/xml/docbook/schema/dtd/4.2 - DOCBOOK_DTD_DIR=/usr/share/xml/docbook/schema/dtd/4.2
- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 60 --slave /usr/bin/g++ g++ /usr/bin/g++-5
- gcc --version
# Set this to the name of your Boost library # Set this to the name of your Boost library
# Autodetect library name by using the following code: - PROJECT_TO_TEST=$(basename $(pwd)) # Autodetect library name by using the following code: - PROJECT_TO_TEST=$(basename $(pwd))
- PROJECT_TO_TEST=$(basename $(pwd)) - PROJECT_TO_TEST=$(basename $(pwd))
@ -57,7 +69,7 @@ script:
- cd $PROJECT_DIR/build - cd $PROJECT_DIR/build
- export BOOST_ROOT=$BOOST - export BOOST_ROOT=$BOOST
# `--coverage` flags required to generate coverage info for Coveralls # `--coverage` flags required to generate coverage info for Coveralls
- ./build.sh "cxxflags=-std=$CXX_STANDARD --coverage" "linkflags=--coverage" - ./build.sh --toolset=$CC "cxxflags=-std=$CXX_STANDARD -Wno-unused-variable -Wno-unused-function -Wno-deprecated-declarations --coverage" "--coverage"
after_success: after_success:
- COVERALS_DIR=$PROJECT_DIR/coverals - COVERALS_DIR=$PROJECT_DIR/coverals

View file

@ -11,7 +11,7 @@ rem error if BOOST_ROOT not set
set BOOST=%BOOST_ROOT% set BOOST=%BOOST_ROOT%
pushd ..\test pushd ..\test
%BOOST%\b2 -q %* %BOOST%\b2.exe -q %*
popd popd
if errorlevel 1 exit /b %ERRORLEVEL% if errorlevel 1 exit /b %ERRORLEVEL%
@ -24,6 +24,6 @@ xcopy /Y /S /Q /I %BOOST%\doc\src\images\*.png ..\doc\html\images
xcopy /Y /S /Q /I %BOOST%\doc\src\images\callouts\*.png ..\doc\html\images\callouts xcopy /Y /S /Q /I %BOOST%\doc\src\images\callouts\*.png ..\doc\html\images\callouts
if errorlevel 1 exit /b %ERRORLEVEL% if errorlevel 1 exit /b %ERRORLEVEL%
pushd ..\doc pushd ..\doc
%BOOST%\b2 -q %* %BOOST%\b2.exe -q %*
popd popd
if errorlevel 1 exit /b %ERRORLEVEL% if errorlevel 1 exit /b %ERRORLEVEL%

View file

@ -12,7 +12,7 @@ copy()
cp $@ cp $@
} }
set -x set -ex
export BOOST=$BOOST_ROOT export BOOST=$BOOST_ROOT
@ -28,5 +28,5 @@ copy "$BOOST"/doc/src/boostbook.css ../doc/html
copy "$BOOST"/doc/src/images/*.png ../doc/html/images copy "$BOOST"/doc/src/images/*.png ../doc/html/images
copy "$BOOST"/doc/src/images/callouts/*.png ../doc/html/images/callouts copy "$BOOST"/doc/src/images/callouts/*.png ../doc/html/images/callouts
cd ../doc cd ../doc
$BOOST/b2 -q "$C" $BOOST/b2 -q "$@"
cd ../build cd ../build

View file

@ -18,17 +18,6 @@
<property name="version" value="unreleased"/> <property name="version" value="unreleased"/>
<import file="${env.PONEY_HOME}/poney.xml"/>
<target name="reports" description="generate code analysis reports">
<headers name="turtle" excludes="**/*_iterate.hpp,**/*_template.hpp"/>
<check name="turtle"/>
</target>
<target name="build" description="build tests and documentation">
<run dir="." script="build"/>
</target>
<target name="package" depends="build" description="produce release packages"> <target name="package" depends="build" description="produce release packages">
<fail unless="version" message="missing version property"/> <fail unless="version" message="missing version property"/>
<copy file="version.hpp" tofile="${out.dir}/version.hpp" overwrite="true"> <copy file="version.hpp" tofile="${out.dir}/version.hpp" overwrite="true">

17
build/clang/Dockerfile Normal file
View file

@ -0,0 +1,17 @@
# $ docker build --platform=linux -f clang/Dockerfile -t turtle-clang .
FROM buildpack-deps:stretch
RUN apt-get update && apt-get install -y xsltproc docbook-xsl docbook-xml && apt-get autoremove && apt-get clean
ENV DOCBOOK_XSL_DIR=/usr/share/xml/docbook/stylesheet/docbook-xsl \
DOCBOOK_DTD_DIR=/usr/share/xml/docbook/schema/dtd/4.2 \
BOOST_ROOT=/home/dev/cpp/boost/
# wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|apt-key add - && \
RUN echo "deb http://apt.llvm.org/stretch/ llvm-toolchain-stretch-5.0 main" >> /etc/apt/sources.list && \
apt-get update && \
apt-get install -y --allow-unauthenticated clang-5.0 lld-5.0 libc++1 && \
apt-get autoremove && \
apt-get clean && \
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-5.0 100 && \
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-5.0 100
RUN echo 'cd /home/dev/cpp/turtle/build' >> ~/.bashrc
# $ docker run --platform=linux --rm -v C:/dev:/home/dev -m 32g -it turtle-clang
# ./build.sh --toolset=clang "cxxflags=-std=c++17 -stdlib=libc++ -Wno-unused-variable"

9
build/gcc/Dockerfile Normal file
View file

@ -0,0 +1,9 @@
# $ docker build -f Dockerfile -t turtle-gcc .
FROM gcc
RUN apt-get update && apt-get install -y xsltproc docbook-xsl docbook-xml && apt-get autoremove && apt-get clean
ENV DOCBOOK_XSL_DIR=/usr/share/xml/docbook/stylesheet/docbook-xsl \
DOCBOOK_DTD_DIR=/usr/share/xml/docbook/schema/dtd/4.2 \
BOOST_ROOT=/home/dev/cpp/boost/
RUN echo 'cd /home/dev/cpp/turtle/build' >> ~/.bashrc
# $ docker run --platform=linux --rm -v C:/dev:/home/dev -m 16g -it turtle-gcc
# ./build.sh --toolset=gcc "cxxflags=-std=c++17 -Wno-noexcept-type -Wno-unused-variable -Wno-unused-function -Wno-deprecated-declarations"

View file

@ -12,18 +12,21 @@
namespace namespace
{ {
//[ limitations_private_method_problem //[ limitations_protected_private_method_problem
class base class base
{ {
private: private:
virtual void method() = 0; virtual void method_1() = 0;
private:
virtual void method_2() = 0;
}; };
//] //]
//[ limitations_private_method_solution //[ limitations_protected_private_method_solution
MOCK_BASE_CLASS( mock_base, base ) MOCK_BASE_CLASS( mock_base, base )
{ {
MOCK_METHOD( method, 0, void() ) MOCK_METHOD( method_1, 0, void() )
MOCK_METHOD( method_2, 0, void() )
}; };
//] //]
} }

View file

@ -14,7 +14,7 @@ namespace
class base_class class base_class
{ {
public: public:
virtual void method( boost::function< void( int ) > functor ) = 0; virtual void method( const boost::function< void( int ) >& functor ) = 0;
}; };
void function( base_class& ); // the function will call 'method' with a functor to be applied void function( base_class& ); // the function will call 'method' with a functor to be applied

View file

@ -249,16 +249,6 @@ MOCK_CLASS( mock_class )
}; };
//] //]
} }
#elif defined( BOOST_GCC )
namespace member_function_example_10
{
//[ member_function_example_10
MOCK_CLASS( mock_class )
{
MOCK_METHOD( __attribute((stdcall)) method, 0, void(), method ) // all parameters must be provided when specifying a different calling convention
};
//]
}
#endif #endif
namespace static_member_function_example_1 namespace static_member_function_example_1
@ -292,16 +282,6 @@ MOCK_CLASS( mock_class )
}; };
//] //]
} }
#elif defined( BOOST_GCC )
namespace static_member_function_example_4
{
//[ static_member_function_example_4
MOCK_CLASS( mock_class )
{
MOCK_STATIC_METHOD( __attribute((stdcall)) method, 0, void(), method ) // all parameters must be provided when specifying a different calling convention
};
//]
}
#endif #endif
namespace constructor_example_1 namespace constructor_example_1
@ -336,16 +316,6 @@ MOCK_CLASS( mock_class )
}; };
//] //]
} }
#elif defined( BOOST_GCC )
namespace constructor_example_4
{
//[ constructor_example_4
MOCK_CLASS( mock_class )
{
MOCK_CONSTRUCTOR( __attribute((stdcall)) mock_class, 0, (), constructor )
};
//]
}
#endif #endif
namespace destructor_example_1 namespace destructor_example_1
@ -368,16 +338,6 @@ MOCK_CLASS( mock_class )
}; };
//] //]
} }
#elif defined( BOOST_GCC )
namespace destructor_example_3
{
//[ destructor_example_3
MOCK_CLASS( mock_class )
{
MOCK_DESTRUCTOR( __attribute((stdcall)) ~mock_class, destructor )
};
//]
}
#endif #endif
namespace conversion_operator_example_1 namespace conversion_operator_example_1
@ -414,16 +374,6 @@ MOCK_CLASS( mock_class )
}; };
//] //]
} }
#elif defined( BOOST_GCC )
namespace conversion_operator_example_4
{
//[ conversion_operator_example_4
MOCK_CLASS( mock_class )
{
MOCK_CONVERSION_OPERATOR( __attribute((stdcall)) operator, int, conversion_to_int )
};
//]
}
#endif #endif
namespace function_example_1 namespace function_example_1
@ -445,13 +395,6 @@ namespace function_example_2
MOCK_FUNCTION( __stdcall f, 0, void(), f ) // all parameters must be provided when specifying a different calling convention MOCK_FUNCTION( __stdcall f, 0, void(), f ) // all parameters must be provided when specifying a different calling convention
//] //]
} }
#elif defined( BOOST_GCC )
namespace function_example_3
{
//[ function_example_3
MOCK_FUNCTION( __attribute((stdcall)) f, 0, void(), f ) // all parameters must be provided when specifying a different calling convention
//]
}
#endif #endif
namespace functor_example_1 namespace functor_example_1

View file

@ -11,7 +11,7 @@
[import example/limitations_non_virtual_method.cpp] [import example/limitations_non_virtual_method.cpp]
[import example/limitations_template_base_class_method.cpp] [import example/limitations_template_base_class_method.cpp]
[import example/limitations_template_method.cpp] [import example/limitations_template_method.cpp]
[import example/limitations_private_method.cpp] [import example/limitations_protected_private_method.cpp]
[import example/limitations_comma_in_macro.cpp] [import example/limitations_comma_in_macro.cpp]
[import example/limitations_const_parameter_warning.cpp] [import example/limitations_const_parameter_warning.cpp]
@ -116,18 +116,19 @@ A workaround would be to add the signature to MOCK_METHOD :
Given : Given :
[limitations_private_method_problem] [limitations_protected_private_method_problem]
the following code does not compile : the following code does not compile :
MOCK_BASE_CLASS( mock_base, base ) MOCK_BASE_CLASS( mock_base, base )
{ {
MOCK_METHOD( method, 0 ) // this fails because 'method' is not visible MOCK_METHOD( method_1, 0 ) // this fails because a function pointer on 'base::method_1' is not allowed
MOCK_METHOD( method_2, 0 ) // this fails because 'method_2' is not visible
}; };
A workaround would be to add the signature to MOCK_METHOD : A workaround would be to add the signature to MOCK_METHOD :
[limitations_private_method_solution] [limitations_protected_private_method_solution]
[endsect] [endsect]

View file

@ -94,7 +94,7 @@
# endif # endif
#endif #endif
#if defined(__cplusplus) && (__cplusplus >= 201703L) || \ #if defined(__cpp_lib_uncaught_exceptions) || \
defined(_MSC_VER) && (_MSC_VER >= 1900) defined(_MSC_VER) && (_MSC_VER >= 1900)
# ifndef MOCK_NO_UNCAUGHT_EXCEPTIONS # ifndef MOCK_NO_UNCAUGHT_EXCEPTIONS
# define MOCK_UNCAUGHT_EXCEPTIONS # define MOCK_UNCAUGHT_EXCEPTIONS

View file

@ -22,7 +22,7 @@
namespace mock namespace mock
{ {
MOCK_UNARY_CONSTRAINT( any, 0,, true && &actual ) MOCK_UNARY_CONSTRAINT( any, 0,, ((void)actual, true) )
MOCK_UNARY_CONSTRAINT( affirm, 0,, !! actual ) MOCK_UNARY_CONSTRAINT( affirm, 0,, !! actual )
MOCK_UNARY_CONSTRAINT( negate, 0,, ! actual ) MOCK_UNARY_CONSTRAINT( negate, 0,, ! actual )
MOCK_UNARY_CONSTRAINT( evaluate, 0,, actual() ) MOCK_UNARY_CONSTRAINT( evaluate, 0,, actual() )

View file

@ -109,11 +109,17 @@ namespace detail
{ {
this->set( this->set(
boost::bind( boost::bind(
&boost::move< BOOST_RV_REF(Value) >, &move< Value >,
boost::ref( store( boost::move( v ) ) ) ) ); boost::ref( store( boost::move( v ) ) ) ) );
} }
private: private:
template< typename T >
static T&& move( T& t )
{
return std::move( t );
}
struct value : boost::noncopyable struct value : boost::noncopyable
{ {
virtual ~value() virtual ~value()

View file

@ -87,10 +87,11 @@ namespace detail
E* e_; E* e_;
}; };
inline int uncaught_exceptions() inline int exceptions()
{ {
#ifdef MOCK_UNCAUGHT_EXCEPTIONS #ifdef MOCK_UNCAUGHT_EXCEPTIONS
return std::uncaught_exceptions(); using namespace std;
return uncaught_exceptions();
#else #else
return std::uncaught_exception() ? 1 : 0; return std::uncaught_exception() ? 1 : 0;
#endif #endif

View file

@ -43,12 +43,12 @@ namespace detail
function_impl() function_impl()
: context_( 0 ) : context_( 0 )
, valid_( true ) , valid_( true )
, exceptions_( exceptions() )
, mutex_( boost::make_shared< mutex >() ) , mutex_( boost::make_shared< mutex >() )
, exceptions_( uncaught_exceptions() )
{} {}
virtual ~function_impl() virtual ~function_impl()
{ {
if( valid_ && exceptions_ >= uncaught_exceptions() ) if( valid_ && exceptions_ >= exceptions() )
for( expectations_cit it = expectations_.begin(); for( expectations_cit it = expectations_.begin();
it != expectations_.end(); ++it ) it != expectations_.end(); ++it )
if( ! it->verify() ) if( ! it->verify() )
@ -183,9 +183,9 @@ namespace detail
this->e_->throws( t ); this->e_->throws( t );
} }
template< typename TT > template< typename TT >
void moves( TT t ) void moves( BOOST_RV_REF(TT) t )
{ {
this->e_->moves( t ); this->e_->moves( boost::move( t ) );
} }
lock lock_; lock lock_;

View file

@ -43,8 +43,8 @@
#else // MOCK_VARIADIC_MACROS #else // MOCK_VARIADIC_MACROS
#define MOCK_BASE_CLASS(T, B) \ #define MOCK_BASE_CLASS(T, I) \
struct T : B, mock::object, mock::detail::base< B > struct T : I, mock::object, mock::detail::base< I >
#define MOCK_FUNCTOR(f, S) \ #define MOCK_FUNCTOR(f, S) \
mock::detail::functor< MOCK_FUNCTION_TYPE((S),) > f, f##_mock mock::detail::functor< MOCK_FUNCTION_TYPE((S),) > f, f##_mock
@ -177,11 +177,8 @@
#define MOCK_VARIADIC_ELEM_1(e0, e1, ...) e1 #define MOCK_VARIADIC_ELEM_1(e0, e1, ...) e1
#define MOCK_VARIADIC_ELEM_2(e0, e1, e2, ...) e2 #define MOCK_VARIADIC_ELEM_2(e0, e1, e2, ...) e2
#define MOCK_METHOD_SIGNATURE(M, n, S, t) \
typedef MOCK_FUNCTION_TYPE((S),) BOOST_PP_CAT(t,_sig_type); \
MOCK_METHOD_EXT(M, n, BOOST_PP_CAT(t,_sig_type), t)
#define MOCK_METHOD(M, ...) \ #define MOCK_METHOD(M, ...) \
MOCK_METHOD_SIGNATURE(M, \ MOCK_METHOD_EXT(M, \
MOCK_VARIADIC_ELEM_0(__VA_ARGS__ ), \ MOCK_VARIADIC_ELEM_0(__VA_ARGS__ ), \
MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M)), \ MOCK_VARIADIC_ELEM_1(__VA_ARGS__, MOCK_SIGNATURE(M)), \
MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M)) MOCK_VARIADIC_ELEM_2(__VA_ARGS__, M, M))
@ -228,8 +225,7 @@
#else // MOCK_VARIADIC_MACROS #else // MOCK_VARIADIC_MACROS
#define MOCK_METHOD(M, n) \ #define MOCK_METHOD(M, n) \
typedef MOCK_SIGNATURE(M) M##_sig_type; \ MOCK_METHOD_EXT(M, n, MOCK_SIGNATURE(M), M)
MOCK_METHOD_EXT(M, n, M##_sig_type, M)
#define MOCK_FUNCTION(F, n, S, t) \ #define MOCK_FUNCTION(F, n, S, t) \
MOCK_FUNCTION_AUX(F, n, S, t, inline,) MOCK_FUNCTION_AUX(F, n, S, t, inline,)

View file

@ -23,7 +23,7 @@ namespace
BOOST_AUTO_TEST_CASE( mock_signature_generates_signature ) BOOST_AUTO_TEST_CASE( mock_signature_generates_signature )
{ {
BOOST_MPL_ASSERT(( BOOST_MPL_ASSERT((
boost::is_same< void(), MOCK_SIGNATURE( method_1 ) > )); boost::is_same< void(), MOCK_SIGNATURE(method_1) > ));
BOOST_MPL_ASSERT(( BOOST_MPL_ASSERT((
boost::is_same< float( int ), MOCK_SIGNATURE( method_2 ) > )); boost::is_same< float( int ), MOCK_SIGNATURE(method_2) > ));
} }

View file

@ -84,8 +84,8 @@ namespace
class my_ambiguited_interface : boost::noncopyable class my_ambiguited_interface : boost::noncopyable
{ {
public: public:
virtual ~my_ambiguited_interface() {} virtual ~my_ambiguited_interface()
{}
virtual void my_method() = 0; virtual void my_method() = 0;
virtual void my_method( int ) = 0; virtual void my_method( int ) = 0;
}; };
@ -110,8 +110,8 @@ namespace
class my_const_ambiguited_interface : boost::noncopyable class my_const_ambiguited_interface : boost::noncopyable
{ {
public: public:
virtual ~my_const_ambiguited_interface() {} virtual ~my_const_ambiguited_interface()
{}
virtual void my_method() = 0; virtual void my_method() = 0;
virtual void my_method() const = 0; virtual void my_method() const = 0;
}; };

View file

@ -364,7 +364,7 @@ namespace
{ {
virtual ~base() virtual ~base()
{} {}
protected:
virtual void m1() = 0; virtual void m1() = 0;
}; };
@ -384,7 +384,7 @@ namespace
template< typename T > template< typename T >
MOCK_BASE_CLASS( variadic_tpl, base ) MOCK_BASE_CLASS( variadic_tpl, base )
{ {
MOCK_METHOD( m1, 0 ) MOCK_METHOD( m1, 0, void() )
MOCK_METHOD_TPL( m2, 0, T() ) MOCK_METHOD_TPL( m2, 0, T() )
MOCK_METHOD_TPL( m3, 0, T(), m3 ) MOCK_METHOD_TPL( m3, 0, T(), m3 )
MOCK_CONST_METHOD_TPL( m4, 0, T() ) MOCK_CONST_METHOD_TPL( m4, 0, T() )
@ -413,7 +413,7 @@ namespace
{ {
virtual ~base() virtual ~base()
{} {}
protected:
virtual void m1() = 0; virtual void m1() = 0;
}; };
@ -425,7 +425,7 @@ namespace
template< typename T > template< typename T >
MOCK_BASE_CLASS( derived_tpl, base ) MOCK_BASE_CLASS( derived_tpl, base )
{ {
MOCK_METHOD( m1, 0 ) MOCK_METHOD_EXT( m1, 0, void(), m1 )
}; };
} }
@ -433,11 +433,9 @@ namespace
#ifdef BOOST_MSVC #ifdef BOOST_MSVC
# define MOCK_STDCALL __stdcall # define MOCK_STDCALL __stdcall
#elif defined( BOOST_GCC )
# define MOCK_STDCALL __attribute((stdcall))
#else #else
# define MOCK_STDCALL # define MOCK_STDCALL
#endif // BOOST_GCC #endif
namespace stdcall namespace stdcall
{ {
@ -446,7 +444,6 @@ namespace stdcall
virtual ~base() virtual ~base()
{} {}
protected:
virtual void MOCK_STDCALL m1() = 0; virtual void MOCK_STDCALL m1() = 0;
}; };