Compare commits

...

20 Commits

Author SHA1 Message Date
Antony Polukhin
bd19ed1a87 Disable link-fail tests and restore MinGW CI 2018-01-23 10:40:56 +03:00
Antony Polukhin
727cdadc86 Restore link-fail 2018-01-16 01:21:20 +03:00
Antony Polukhin
5bc4f54183 Dropped -fail to check the MSVC builds 2018-01-16 01:10:28 +03:00
Antony Polukhin
918e59c109 One more fix in tests for /GR- flag 2018-01-16 00:44:11 +03:00
Antony Polukhin
cd659212aa Workaround for /GR- override in tests 2018-01-16 00:28:48 +03:00
Antony Polukhin
70e51a62e9 Workaround for /GR- override that disables link time assertions 2018-01-15 23:21:34 +03:00
Antony Polukhin
05feacf14b Relax comparing_anonymous_types_between_modules test as it was failing to too many builds (fixes #17) 2018-01-15 00:14:47 +03:00
Antony Polukhin
82ed016577 Use hash_fwd header and use new paths to boost::hash* 2018-01-14 23:41:33 +03:00
Antony Polukhin
1a7226bc0f Do not define BOOST_TEST_*E macros, as they are now defined in boost/core/lightweight_test.hpp 2017-10-01 22:30:59 +03:00
Antony Polukhin
be08eda196 Do not suppress already suppressed warnings 2017-09-26 22:05:57 +03:00
Antony Polukhin
baa5019c90 Merge pull request #16 from bebuch/develop
fix ctti_type_index for GCC 7
2017-07-29 20:13:04 +03:00
Benjamin Buch
4585bab3c3 __PRETTY_FUNCTION__ is slightly different in GCC 7
The output of an unsigned int literal dosn't contain the u anymore.

	#include <iostream>

	template < typename T >
	struct ctti{
		template < unsigned int D = 1 >
		static constexpr auto name()noexcept{
			return __PRETTY_FUNCTION__;
		}
	};

	int main(){
		using ctti = ctti< int >;
		std::cout << ctti::name() << '\n';
	}
2017-07-28 15:07:19 +02:00
Antony Polukhin
93e7b2458b Fixed some warnings 2017-06-25 14:05:08 +03:00
Daniela Engert
09ac338acc Fix compiler warnings about unused initialized variables, and unused formal parameters
Signed-off-by: Daniela Engert <dani@ngrt.de>
2017-06-08 19:05:02 +02:00
Antony Polukhin
b0737f4169 Fix formatting in README 2017-05-18 22:51:47 +03:00
Antony Polukhin
be74716251 Use native hash_code() when possible on GCC-like compilers 2017-05-18 22:50:25 +03:00
Antony Polukhin
f82eab8882 Merge pull request #15 from ecatmur/ecatmur-stl-hash
Include <boost/functional/hash.hpp> if required
2017-05-06 10:26:30 +03:00
Edward Catmur
5cacb67510 Make it derived class responsibility to include <boost/functional/hash.hpp> 2017-02-16 21:55:12 +00:00
Ed Catmur
f2616bcd17 Correct preprocessor condition to match below 2017-02-16 16:30:52 +00:00
Ed Catmur
8c582362d0 Include <boost/functional/hash.hpp> if required 2017-02-16 16:18:48 +00:00
18 changed files with 84 additions and 48 deletions

View File

@@ -1,4 +1,4 @@
#[Boost.TypeIndex](http://boost.org/libs/type_index)
# [Boost.TypeIndex](http://boost.org/libs/type_index)
Boost.TypeIndex is a part of the [Boost C++ Libraries](http://github.com/boostorg). It is a runtime/compile time copyable type info.
### Test results
@@ -6,7 +6,7 @@ Boost.TypeIndex is a part of the [Boost C++ Libraries](http://github.com/boostor
@ | Build | Tests coverage | More info
----------------|-------------- | -------------- |-----------
Develop branch: | [![Build Status](https://travis-ci.org/apolukhin/type_index.svg?branch=develop)](https://travis-ci.org/apolukhin/type_index) [![Build status](https://ci.appveyor.com/api/projects/status/197a5imq10dqx6r8/branch/develop?svg=true)](https://ci.appveyor.com/project/apolukhin/type-index/branch/develop) | [![Coverage Status](https://coveralls.io/repos/apolukhin/type_index/badge.png?branch=develop)](https://coveralls.io/r/apolukhin/type_index?branch=develop) | [details...](http://www.boost.org/development/tests/develop/developer/type_index.html)
Master branch: | [![Build Status](https://travis-ci.org/apolukhin/type_index.svg?branch=master)](https://travis-ci.org/apolukhin/type_index) [![Build status](https://ci.appveyor.com/api/projects/status/197a5imq10dqx6r8/branch/develop?svg=true)](https://ci.appveyor.com/project/apolukhin/type-index/branch/master) | [![Coverage Status](https://coveralls.io/repos/apolukhin/type_index/badge.png?branch=master)](https://coveralls.io/r/apolukhin/type_index?branch=master) | [details...](http://www.boost.org/development/tests/master/developer/type_index.html)
Master branch: | [![Build Status](https://travis-ci.org/apolukhin/type_index.svg?branch=master)](https://travis-ci.org/apolukhin/type_index) [![Build status](https://ci.appveyor.com/api/projects/status/197a5imq10dqx6r8/branch/master?svg=true)](https://ci.appveyor.com/project/apolukhin/type-index/branch/master) | [![Coverage Status](https://coveralls.io/repos/apolukhin/type_index/badge.png?branch=master)](https://coveralls.io/r/apolukhin/type_index?branch=master) | [details...](http://www.boost.org/development/tests/master/developer/type_index.html)
[Open Issues](https://svn.boost.org/trac/boost/query?status=!closed&component=type_index)

View File

@@ -1,4 +1,4 @@
// Copyright 2013-2016 Antony Polukhin
// Copyright 2013-2017 Antony Polukhin
// Distributed under the Boost Software License, Version 1.0.
// (See the accompanying file LICENSE_1_0.txt
@@ -6,6 +6,10 @@
#include <boost/config.hpp>
template <class T>
void do_something(const T&) {}
#if !defined(BOOST_NO_CXX14_CONSTEXPR) && !defined(BOOST_NO_CXX11_CONSTEXPR)
// Implementation of this function is not essential for the example
template <std::size_t N>
@@ -62,6 +66,7 @@ namespace my_project {
// Actual implementation of the serialization goes below
// ...
do_something(value);
}
};

View File

@@ -1,4 +1,4 @@
// Copyright 2013-2016 Antony Polukhin
// Copyright 2013-2017 Antony Polukhin
// Distributed under the Boost Software License, Version 1.0.
// (See the accompanying file LICENSE_1_0.txt
@@ -55,7 +55,7 @@ constexpr bool is_asc_sorted(types<Lhs, Rhs, TN...>) noexcept {
// Using the newly created `is_asc_sorted` trait:
template <class... T>
void do_something(const types<T...>& t) noexcept {
void do_something(const types<T...>& /*value*/) noexcept {
static_assert(
is_asc_sorted( types<T...>() ),
"T... for do_something(const types<T...>& t) must be sorted ascending"

View File

@@ -1,4 +1,4 @@
// Copyright 2013-2015 Antony Polukhin
// Copyright 2013-2017 Antony Polukhin
// Distributed under the Boost Software License, Version 1.0.
// (See the accompanying file LICENSE_1_0.txt
@@ -12,7 +12,6 @@
#include <boost/type_index.hpp>
#include <boost/unordered_set.hpp>
#include <boost/functional/hash.hpp>
//<-
// Making `#include <cassert>` visible in docs, while actually using `BOOST_TEST`
// instead of `assert`. This is required to verify correct behavior even if NDEBUG

View File

@@ -1,4 +1,4 @@
// Copyright 2013-2014 Antony Polukhin
// Copyright 2013-2018 Antony Polukhin
// Distributed under the Boost Software License, Version 1.0.
// (See the accompanying file LICENSE_1_0.txt
@@ -47,11 +47,20 @@ namespace my_namespace { namespace detail {
template <> struct typenum<my_classes>{ enum {value = 3}; };
template <> struct typenum<my_string>{ enum {value = 4}; };
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable: 4510 4512 4610) // non-copyable non-constructable type
#endif
// my_typeinfo structure is used to save type number
struct my_typeinfo {
const char* const type_;
};
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
const my_typeinfo infos[5] = {
{"void"}, {"my_class"}, {"my_struct"}, {"my_classes"}, {"my_string"}
};
@@ -70,7 +79,15 @@ namespace my_namespace { namespace detail {
`my_type_index` is a user created type_index class. If in doubt during this phase, you can always
take a look at the `<boost/type_index/ctti_type_index.hpp>` or `<boost/type_index/stl_type_index.hpp>`
files. Documentation for `type_index_facade` could be also useful.
*/
/*`
Since we are not going to override `type_index_facade::hash_code()` we must additionally include
`<boost/container_hash/hash.hpp>`.
*/
#include <boost/container_hash/hash.hpp>
/*`
See implementation of `my_type_index`:
*/
namespace my_namespace {

View File

@@ -1,5 +1,5 @@
//
// Copyright (c) Antony Polukhin, 2012-2014.
// Copyright (c) Antony Polukhin, 2012-2018.
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

View File

@@ -1,5 +1,5 @@
//
// Copyright (c) Antony Polukhin, 2013-2016.
// Copyright (c) Antony Polukhin, 2013-2018.
//
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -22,6 +22,7 @@
#include <boost/type_index/detail/compile_time_type_info.hpp>
#include <cstring>
#include <boost/container_hash/hash.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <boost/type_traits/remove_reference.hpp>

View File

@@ -11,7 +11,7 @@
/// \file compile_time_type_info.hpp
/// \brief Contains helper macros and implementation details of boost::typeindex::ctti_type_index.
/// Not intended for inclusion from user's code.
/// Not intended for inclusion from user's code.
#include <boost/config.hpp>
#include <boost/static_assert.hpp>
@@ -59,9 +59,12 @@
// sizeof("static const char *boost::detail::ctti<") - 1, sizeof("]") - 1, true, "int>::n() [T = int"
// note: checked on 3.1, 3.4
BOOST_TYPE_INDEX_REGISTER_CTTI_PARSING_PARAMS(39, 1, true, "T = ")
#elif defined(__GNUC__) && !defined(BOOST_NO_CXX14_CONSTEXPR)
// sizeof("static contexpr char boost::detail::ctti<T>::s() [with unsigned int I = 0u; T = ") - 1, sizeof("]") - 1
#elif defined(__GNUC__) && (__GNUC__ < 7) && !defined(BOOST_NO_CXX14_CONSTEXPR)
// sizeof("static constexpr char boost::detail::ctti<T>::s() [with unsigned int I = 0u; T = ") - 1, sizeof("]") - 1
BOOST_TYPE_INDEX_REGISTER_CTTI_PARSING_PARAMS(81, 1, false, "")
#elif defined(__GNUC__) && (__GNUC__ >= 7) && !defined(BOOST_NO_CXX14_CONSTEXPR)
// sizeof("static constexpr char boost::detail::ctti<T>::s() [with unsigned int I = 0; T = ") - 1, sizeof("]") - 1
BOOST_TYPE_INDEX_REGISTER_CTTI_PARSING_PARAMS(80, 1, false, "")
#elif defined(__GNUC__) && defined(BOOST_NO_CXX14_CONSTEXPR)
// sizeof("static const char* boost::detail::ctti<T>::n() [with T = ") - 1, sizeof("]") - 1
BOOST_TYPE_INDEX_REGISTER_CTTI_PARSING_PARAMS(57, 1, false, "")
@@ -72,7 +75,7 @@
#undef BOOST_TYPE_INDEX_REGISTER_CTTI_PARSING_PARAMS
namespace boost { namespace typeindex { namespace detail {
namespace boost { namespace typeindex { namespace detail {
template <bool Condition>
BOOST_CXX14_CONSTEXPR inline void assert_compile_time_legths() BOOST_NOEXCEPT {
BOOST_STATIC_ASSERT_MSG(
@@ -149,7 +152,7 @@ namespace boost { namespace typeindex { namespace detail {
BOOST_CXX14_CONSTEXPR inline const char* skip_begining(const char* begin) BOOST_NOEXCEPT {
assert_compile_time_legths<(ArrayLength > ctti_skip_size_at_begin + ctti_skip_size_at_end)>();
return skip_begining_runtime<ArrayLength - ctti_skip_size_at_begin>(
begin + ctti_skip_size_at_begin,
begin + ctti_skip_size_at_begin,
boost::mpl::bool_<ctti_skip_more_at_runtime>()
);
}
@@ -203,7 +206,7 @@ namespace boost { namespace detail {
/// This name must be as short as possible, to avoid code bloat
template <class T>
struct ctti {
#if !defined(__clang__) && defined(__GNUC__) && !defined(BOOST_NO_CXX14_CONSTEXPR)
//helper functions
template <unsigned int I>
@@ -286,4 +289,3 @@ struct ctti {
}} // namespace boost::detail
#endif // BOOST_TYPE_INDEX_DETAIL_COMPILE_TIME_TYPE_INFO_HPP

View File

@@ -1,5 +1,5 @@
//
// Copyright (c) Antony Polukhin, 2013-2017.
// Copyright (c) Antony Polukhin, 2013-2018.
//
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -40,6 +40,8 @@
#include <boost/mpl/if.hpp>
#include <boost/mpl/or.hpp>
#include <boost/container_hash/hash.hpp>
#if (defined(__EDG_VERSION__) && __EDG_VERSION__ < 245) \
|| (defined(__sgi) && defined(_COMPILER_VERSION) && _COMPILER_VERSION <= 744)
# include <boost/type_traits/is_signed.hpp>
@@ -174,7 +176,9 @@ inline std::string stl_type_index::pretty_name() const {
inline std::size_t stl_type_index::hash_code() const BOOST_NOEXCEPT {
#if (defined(_MSC_VER) && _MSC_VER > 1600) || (__GNUC__ == 4 && __GNUC_MINOR__ > 5 && defined(__GXX_EXPERIMENTAL_CXX0X__))
#if (defined(_MSC_VER) && _MSC_VER > 1600) \
|| (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ > 5 && defined(__GXX_EXPERIMENTAL_CXX0X__)) \
|| (defined(__GNUC__) && __GNUC__ > 4 && __cplusplus >= 201103)
return data_->hash_code();
#else
return boost::hash_range(raw_name(), raw_name() + std::strlen(raw_name()));

View File

@@ -1,5 +1,5 @@
//
// Copyright (c) Antony Polukhin, 2013-2015.
// Copyright (c) Antony Polukhin, 2013-2018.
//
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -10,6 +10,7 @@
#define BOOST_TYPE_INDEX_TYPE_INDEX_FACADE_HPP
#include <boost/config.hpp>
#include <boost/container_hash/hash_fwd.hpp>
#include <string>
#include <cstring>
@@ -25,11 +26,6 @@
# pragma once
#endif
// Forward declaration from #include <boost/functional/hash_fwd.hpp>
namespace boost {
template <class It> std::size_t hash_range(It, It);
}
namespace boost { namespace typeindex {
/// \class type_index_facade
@@ -103,7 +99,8 @@ public:
/// \b Override: This function \b may be redefined in Derived class. Overrides \b must not throw.
/// \return Hash code of a type. By default hashes types by raw_name().
/// \note <boost/functional/hash.hpp> has to be included if this function is used.
/// \note Derived class header \b must include <boost/container_hash/hash.hpp>, \b unless this function is redefined in
/// Derived class to not use boost::hash_range().
inline std::size_t hash_code() const BOOST_NOEXCEPT {
const char* const name_raw = derived().raw_name();
return boost::hash_range(name_raw, name_raw + std::strlen(name_raw));
@@ -288,7 +285,7 @@ inline std::basic_ostream<CharT, TriatT>& operator<<(
#endif // BOOST_NO_IOSTREAM
/// This free function is used by Boost's unordered containers.
/// \note <boost/functional/hash.hpp> has to be included if this function is used.
/// \note <boost/container_hash/hash.hpp> has to be included if this function is used.
template <class Derived, class TypeInfo>
inline std::size_t hash_value(const type_index_facade<Derived, TypeInfo>& lhs) BOOST_NOEXCEPT {
return static_cast<Derived const&>(lhs).hash_code();

View File

@@ -46,7 +46,7 @@ test-suite type_index
[ run ctti_print_name.cpp : : : <test-info>always_show_run_output ]
[ run testing_crossmodule.cpp test_lib_rtti ]
[ run testing_crossmodule.cpp test_lib_nortti : : : <rtti>off $(norttidefines) : testing_crossmodule_no_rtti ]
[ run testing_crossmodule_anonymous.cpp test_lib_anonymous_rtti ]
[ run testing_crossmodule_anonymous.cpp test_lib_anonymous_rtti : : : <test-info>always_show_run_output ]
[ run compare_ctti_stl.cpp ]
[ compile-fail type_index_test_ctti_copy_fail.cpp ]
@@ -54,9 +54,12 @@ test-suite type_index
[ compile type_index_test_ctti_alignment.cpp ]
# Mixing RTTI on and off
[ link-fail testing_crossmodule.cpp test_lib_rtti : $(nortti) : link_fail_nortti_rtti ]
# MSVC sometimes overrides the /GR-, without `detect_missmatch` this test may link
[ link-fail testing_crossmodule.cpp test_lib_nortti : : link_fail_rtti_nortti ]
# MSVC sometimes overrides the /GR-, without `detect_missmatch` this test may link.
# TODO: Disabled on MSVC. Enable again when there'll be an understanding of how to write this test correctly wor MSVC.
[ link-fail testing_crossmodule.cpp test_lib_rtti : $(nortti) <toolset>msvc:<build>no : link_fail_nortti_rtti ]
[ link-fail testing_crossmodule.cpp test_lib_nortti : <toolset>msvc:<build>no : link_fail_rtti_nortti ]
[ run testing_crossmodule.cpp test_lib_rtti_compat : : : $(nortti) $(compat) : testing_crossmodule_nortti_rtti_compat ]
[ run testing_crossmodule.cpp test_lib_nortti_compat : : : $(compat) : testing_crossmodule_rtti_nortti_compat ]
;

View File

@@ -2,7 +2,7 @@
# subject to the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
# Copyright Antony Polukhin 2016-2017.
# Copyright Antony Polukhin 2016-2018.
#
# See https://svn.boost.org/trac/boost/wiki/TravisCoverals for description of this file

View File

@@ -1,5 +1,5 @@
//
// Copyright (c) Antony Polukhin, 2012-2015.
// Copyright (c) Antony Polukhin, 2012-2018.
//
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -31,7 +31,7 @@ boost::typeindex::type_index get_const_user_defined_class() {
return boost::typeindex::type_id_with_cvr<const user_defined_namespace::user_defined>();
}
#ifndef BOOST_HAS_PRAGMA_DETECT_MISMATCH
#if !defined(BOOST_HAS_PRAGMA_DETECT_MISMATCH) || !defined(_CPPRTTI)
// Just do nothing
void accept_typeindex(const boost::typeindex::type_index&) {}
#endif

View File

@@ -1,5 +1,5 @@
//
// Copyright (c) Antony Polukhin, 2012-2015.
// Copyright (c) Antony Polukhin, 2012-2018.
//
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -31,7 +31,7 @@ TEST_LIB_DECL boost::typeindex::type_index get_user_defined_class();
TEST_LIB_DECL boost::typeindex::type_index get_const_integer();
TEST_LIB_DECL boost::typeindex::type_index get_const_user_defined_class();
#ifndef BOOST_HAS_PRAGMA_DETECT_MISMATCH
#if !defined(BOOST_HAS_PRAGMA_DETECT_MISMATCH) || !defined(_CPPRTTI)
// This is required for checking RTTI on/off linkage
TEST_LIB_DECL void accept_typeindex(const boost::typeindex::type_index&);
#endif

View File

@@ -1,5 +1,5 @@
//
// Copyright Antony Polukhin, 2012-2015.
// Copyright Antony Polukhin, 2012-2018.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -41,7 +41,9 @@ void comparing_types_between_modules()
BOOST_TEST_NE(t_int, test_lib::get_user_defined_class());
BOOST_TEST_NE(t_const_int, test_lib::get_const_user_defined_class());
#ifndef BOOST_HAS_PRAGMA_DETECT_MISMATCH
// MSVC supports detect_missmatch pragma, but /GR- silently switch disable the link time check.
// /GR- undefies the _CPPRTTI macro. Using it to detect working detect_missmatch pragma.
#if !defined(BOOST_HAS_PRAGMA_DETECT_MISMATCH) || !defined(_CPPRTTI)
test_lib::accept_typeindex(t_int);
#endif
}

View File

@@ -1,5 +1,5 @@
//
// Copyright Antony Polukhin, 2012-2015.
// Copyright Antony Polukhin, 2012-2018.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -10,6 +10,8 @@
#include <boost/type_index.hpp>
#include "test_lib_anonymous.hpp"
#include <iostream>
#define BOOST_CHECK_NE(x, y) BOOST_CHECK(x != y)
namespace {
@@ -21,8 +23,19 @@ void comparing_anonymous_types_between_modules()
boost::typeindex::type_index t_const_userdef = boost::typeindex::type_id_with_cvr<const user_defined>();
boost::typeindex::type_index t_userdef = boost::typeindex::type_id<user_defined>();
BOOST_TEST_NE(t_userdef, test_lib::get_anonymous_user_defined_class());
BOOST_TEST_NE(t_const_userdef, test_lib::get_const_anonymous_user_defined_class());
// Known to fail on Clang and old versions of GCC.
//BOOST_TEST_NE(t_userdef, test_lib::get_anonymous_user_defined_class());
//BOOST_TEST_NE(t_const_userdef, test_lib::get_const_anonymous_user_defined_class());
std::cout
<< "t_userdef == " << t_userdef
<< ", test_lib::get_anonymous_user_defined_class() == " << test_lib::get_anonymous_user_defined_class()
<< '\n';
std::cout
<< "t_const_userdef == " << t_const_userdef
<< ", test_lib::get_const_anonymous_user_defined_class() == " << test_lib::get_const_anonymous_user_defined_class()
<< '\n';
BOOST_TEST_NE(t_const_userdef, test_lib::get_anonymous_user_defined_class());
BOOST_TEST_NE(t_userdef, test_lib::get_const_anonymous_user_defined_class());
}

View File

@@ -7,14 +7,11 @@
#include <boost/type_index/ctti_type_index.hpp>
#include <boost/functional/hash.hpp>
#include <boost/lexical_cast.hpp>
#include <algorithm>
#include <string>
#include <boost/core/lightweight_test.hpp>
#define BOOST_TEST_LE(x, y) BOOST_TEST(x <= y)
#define BOOST_TEST_GE(x, y) BOOST_TEST(x >= y)
const char* hello1 = "Hello word";
const char* hello1_end = hello1 + sizeof("Hello word");

View File

@@ -7,13 +7,9 @@
#include <boost/type_index.hpp>
#include <boost/functional/hash.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/core/lightweight_test.hpp>
#define BOOST_TEST_LE(x, y) BOOST_TEST(x <= y)
#define BOOST_TEST_GE(x, y) BOOST_TEST(x >= y)
namespace my_namespace1 {
class my_class{};