forked from boostorg/type_traits
Assert when we try to use an incomplete type on a trait which requires complete types as arguments.
This prevents some traits from doing the wrong thing (ie compiling but giving the wrong answer when handed an incomplete type. See https://svn.boost.org/trac10/ticket/12285. A by-product of this is we add is_complete as a new trait.
This commit is contained in:
1 parent
85a03d3453
commit
ac351390b2
35 files changed
+572
-17
No files matched your search
@@ -39,6 +39,10 @@ rule all-tests {
|
||||
{
|
||||
result += [ run $(source) ] ;
|
||||
}
|
||||
for local source in [ glob compile_fail/*.cpp ]
|
||||
{
|
||||
result += [ compile-fail $(source) ] ;
|
||||
}
|
||||
#
|
||||
# These traits have both intrinsic support, and a std conforming version, test a version with intrinsics disabled for better code coverage:
|
||||
#
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/common_type.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return sizeof(boost::common_type<int, incomplete_type>::type);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/common_type.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return sizeof(boost::common_type<incomplete_type, int>::type);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/has_nothrow_assign.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::has_nothrow_assign<incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/has_nothrow_constructor.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::has_nothrow_constructor<incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/has_nothrow_copy.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::has_nothrow_copy<incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/has_nothrow_destructor.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::has_nothrow_destructor<incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/is_assignable.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::is_assignable<incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/is_base_of.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::is_base_of<UDT, incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/is_constructible.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::is_constructible<incomplete_type, int>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/is_convertible.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
#if defined(CI_SUPPRESS_KNOWN_ISSUES) && defined(BOOST_MSVC) && (BOOST_MSVC <= 1800)
|
||||
#error "Sorry check doesn't work"
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::is_convertible<incomplete_type, UDT>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/is_convertible.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::is_convertible<UDT, incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/is_copy_assignable.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::is_copy_assignable<incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/is_copy_constructible.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::is_copy_constructible<incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/is_default_constructible.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::is_default_constructible<incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/is_destructible.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::is_destructible<incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/is_empty.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::is_empty<incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/is_list_constructible.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::is_list_constructible<incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/is_nothrow_move_assignable.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::is_nothrow_move_assignable<incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/is_nothrow_move_constructible.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::is_nothrow_move_constructible<incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/is_polymorphic.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::is_polymorphic<incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/is_stateless.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::is_stateless<incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// (C) Copyright John Maddock 2017.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
# include <boost/type_traits/is_virtual_base_of.hpp>
|
||||
#include "../test.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
return boost::is_virtual_base_of<UDT, incomplete_type>::value;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
|
||||
// (C) Copyright John Maddock 2000.
|
||||
// Use, modification and distribution are 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)
|
||||
|
||||
#ifdef TEST_STD
|
||||
# include <type_traits>
|
||||
#else
|
||||
# include <boost/type_traits/is_complete.hpp>
|
||||
#endif
|
||||
#include "test.hpp"
|
||||
#include "check_integral_constant.hpp"
|
||||
|
||||
TT_TEST_BEGIN(is_complete)
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int const>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int volatile>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int const volatile>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int const&>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int volatile&>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int const volatile&>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int*>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int const*>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int volatile*>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int const volatile*>::value, true);
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int[2]>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int const[3]>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int volatile[2][3]>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int const volatile[4][5][6]>::value, true);
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<int[]>::value, false);
|
||||
#endif
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<enum_UDT>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<UDT>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<f1>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<mf1>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<cmf>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<mf8>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<union_UDT>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<test_abc1>::value, true);
|
||||
#ifndef BOOST_NO_SFINAE
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<incomplete_type>::value, false);
|
||||
#endif
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<polymorphic_base>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<virtual_inherit6>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<foo0_t>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete<foo4_t>::value, true);
|
||||
|
||||
TT_TEST_END
|
||||
|
||||
Reference in new issue
Block a user