forked from boostorg/static_assert
Compare commits
19 Commits
svn-branch
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
f378c96f35 | |||
68545773d5 | |||
328b4fee16 | |||
21ab9ce12a | |||
0e39de168b | |||
52bc1a8fb7 | |||
0566bafd1d | |||
a2c78d51be | |||
d06c7261fc | |||
5e7c100b55 | |||
c26dde8e6e | |||
19e8840ad7 | |||
dd969b13ab | |||
5ea5535e1a | |||
64973e2132 | |||
02c6fb40a6 | |||
5ea88d2e64 | |||
1029ee8032 | |||
f2732e699f |
31
Jamfile
31
Jamfile
@ -1,16 +1,25 @@
|
||||
# copyright John Maddock 2003
|
||||
|
||||
subproject libs/static_assert ;
|
||||
# bring in the rules for testing
|
||||
import testing ;
|
||||
|
||||
test-suite static_assert :
|
||||
[ run static_assert_test.cpp ]
|
||||
# [ run static_assert_example_1.cpp ]
|
||||
[ run static_assert_example_2.cpp ]
|
||||
[ run static_assert_example_3.cpp ]
|
||||
[ compile-fail static_assert_test_fail_1.cpp ]
|
||||
[ compile-fail static_assert_test_fail_2.cpp ]
|
||||
[ compile-fail static_assert_test_fail_3.cpp ]
|
||||
[ compile-fail static_assert_test_fail_4.cpp ]
|
||||
[ compile-fail static_assert_test_fail_5.cpp ]
|
||||
[ compile-fail static_assert_test_fail_6.cpp ]
|
||||
[ compile-fail static_assert_test_fail_7.cpp ]
|
||||
[ compile-fail static_assert_test_fail_8.cpp ]
|
||||
;
|
||||
|
||||
|
||||
|
||||
unit-test static_assert_test : static_assert_test.cpp
|
||||
: <sysinclude>$(BOOST_ROOT) : ;
|
||||
|
||||
unit-test static_assert_example_1 : static_assert_example_1.cpp
|
||||
: <sysinclude>$(BOOST_ROOT) : ;
|
||||
|
||||
unit-test static_assert_example_2 : static_assert_example_2.cpp
|
||||
: <sysinclude>$(BOOST_ROOT) : ;
|
||||
|
||||
unit-test static_assert_example_3 : static_assert_example_3.cpp
|
||||
: <sysinclude>$(BOOST_ROOT) : ;
|
||||
|
||||
|
||||
|
24
Jamfile.v2
Normal file
24
Jamfile.v2
Normal file
@ -0,0 +1,24 @@
|
||||
# copyright John Maddock 2003
|
||||
|
||||
# bring in the rules for testing
|
||||
import testing ;
|
||||
|
||||
test-suite static_assert :
|
||||
[ run static_assert_test.cpp ]
|
||||
# [ run static_assert_example_1.cpp ]
|
||||
[ run static_assert_example_2.cpp ]
|
||||
[ run static_assert_example_3.cpp ]
|
||||
[ compile-fail static_assert_test_fail_1.cpp ]
|
||||
[ compile-fail static_assert_test_fail_2.cpp ]
|
||||
[ compile-fail static_assert_test_fail_3.cpp ]
|
||||
[ compile-fail static_assert_test_fail_4.cpp ]
|
||||
[ compile-fail static_assert_test_fail_5.cpp ]
|
||||
[ compile-fail static_assert_test_fail_6.cpp ]
|
||||
[ compile-fail static_assert_test_fail_7.cpp ]
|
||||
[ compile-fail static_assert_test_fail_8.cpp ]
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
// (C) Copyright John Maddock 2000.
|
||||
// Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
// See http://www.boost.org/libs/static_assert for documentation.
|
||||
|
||||
/*
|
||||
Revision history:
|
||||
@ -16,6 +15,7 @@
|
||||
#define BOOST_STATIC_ASSERT_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
//
|
||||
@ -28,7 +28,7 @@ namespace boost{
|
||||
// HP aCC cannot deal with missing names for template value parameters
|
||||
template <bool x> struct STATIC_ASSERTION_FAILURE;
|
||||
|
||||
template <> struct STATIC_ASSERTION_FAILURE<true>{};
|
||||
template <> struct STATIC_ASSERTION_FAILURE<true> { enum { value = 1 }; };
|
||||
|
||||
// HP aCC cannot deal with missing names for template value parameters
|
||||
template<int x> struct static_assert_test{};
|
||||
@ -57,20 +57,44 @@ template<int x> struct static_assert_test{};
|
||||
// style casts: too many compilers currently have problems with static_cast
|
||||
// when used inside integral constant expressions.
|
||||
//
|
||||
#if !defined(BOOST_BUGGY_INTEGRAL_CONSTANT_EXPRESSIONS) && !defined(__MWERKS__)
|
||||
#ifndef BOOST_MSVC
|
||||
#define BOOST_STATIC_ASSERT( B ) \
|
||||
typedef ::boost::static_assert_test<\
|
||||
sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >)>\
|
||||
BOOST_JOIN(boost_static_assert_typedef_, __LINE__)
|
||||
#else
|
||||
#if !defined(BOOST_BUGGY_INTEGRAL_CONSTANT_EXPRESSIONS) && \
|
||||
!BOOST_WORKAROUND(__MWERKS__, < 0x3003)
|
||||
|
||||
#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
|
||||
// __LINE__ macro broken when -ZI is used see Q199057
|
||||
// fortunately MSVC ignores duplicate typedef's.
|
||||
#define BOOST_STATIC_ASSERT( B ) \
|
||||
typedef ::boost::static_assert_test<\
|
||||
sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >)\
|
||||
> boost_static_assert_typedef_
|
||||
#elif defined(BOOST_MSVC)
|
||||
#define BOOST_STATIC_ASSERT( B ) \
|
||||
typedef ::boost::static_assert_test<\
|
||||
sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >)>\
|
||||
BOOST_JOIN(boost_static_assert_typedef_, __COUNTER__)
|
||||
#elif defined(BOOST_INTEL_CXX_VERSION)
|
||||
// agurt 15/sep/02: a special care is needed to force Intel C++ issue an error
|
||||
// instead of warning in case of failure
|
||||
# define BOOST_STATIC_ASSERT( B ) \
|
||||
typedef char BOOST_JOIN(boost_static_assert_typedef_, __LINE__) \
|
||||
[ ::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >::value ]
|
||||
#elif defined(__sgi)
|
||||
// special version for SGI MIPSpro compiler
|
||||
#define BOOST_STATIC_ASSERT( B ) \
|
||||
BOOST_STATIC_CONSTANT(bool, \
|
||||
BOOST_JOIN(boost_static_assert_test_, __LINE__) = ( B )); \
|
||||
typedef ::boost::static_assert_test<\
|
||||
sizeof(::boost::STATIC_ASSERTION_FAILURE< \
|
||||
BOOST_JOIN(boost_static_assert_test_, __LINE__) >)>\
|
||||
BOOST_JOIN(boost_static_assert_typedef_, __LINE__)
|
||||
#else
|
||||
// generic version
|
||||
#define BOOST_STATIC_ASSERT( B ) \
|
||||
typedef ::boost::static_assert_test<\
|
||||
sizeof(::boost::STATIC_ASSERTION_FAILURE< (bool)( B ) >)>\
|
||||
BOOST_JOIN(boost_static_assert_typedef_, __LINE__)
|
||||
#endif
|
||||
|
||||
#else
|
||||
// alternative enum based implementation:
|
||||
#define BOOST_STATIC_ASSERT( B ) \
|
||||
@ -82,5 +106,3 @@ template<int x> struct static_assert_test{};
|
||||
#endif // BOOST_STATIC_ASSERT_HPP
|
||||
|
||||
|
||||
|
||||
|
||||
|
9
index.html
Normal file
9
index.html
Normal file
@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0; URL=static_assert.htm">
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="static_assert.htm">static_assert.htm</a>.
|
||||
</body>
|
||||
</html>
|
@ -265,7 +265,7 @@ warranty, and with no claim as to its suitability for any purpose.</p>
|
||||
|
||||
<p>Based on contributions by Steve Cleary and John Maddock.</p>
|
||||
|
||||
<p>Maintained by <a href="mailto:John_Maddock@compuserve.com">John
|
||||
<p>Maintained by <a href="mailto:john@johnmaddock.co.uk">John
|
||||
Maddock</a>, the latest version of this file can be found at <a
|
||||
href="http://www.boost.org/">www.boost.org</a>, and the boost
|
||||
discussion list at <a
|
||||
|
@ -1,8 +1,7 @@
|
||||
// (C) Copyright Steve Cleary & John Maddock 2000.
|
||||
// Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
@ -30,3 +29,4 @@ int main()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
// (C) Copyright John Maddock 2000.
|
||||
// Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
@ -38,3 +37,4 @@ int main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
// (C) Copyright John Maddock 2000.
|
||||
// Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
@ -30,3 +29,4 @@ int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
// (C) Copyright Steve Cleary & John Maddock 2000.
|
||||
// Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
@ -84,3 +83,4 @@ int main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
// (C) Copyright Steve Cleary & John Maddock 2000.
|
||||
// Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
@ -11,9 +10,12 @@
|
||||
//
|
||||
// all these tests should fail:
|
||||
//
|
||||
typedef char a1[2];
|
||||
typedef char a2[3];
|
||||
|
||||
// Namespace scope
|
||||
BOOST_STATIC_ASSERT(sizeof(int) == sizeof(char)); // will not compile
|
||||
BOOST_STATIC_ASSERT(sizeof(a1) == sizeof(a2)); // will not compile
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
// (C) Copyright Steve Cleary & John Maddock 2000.
|
||||
// Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
@ -11,13 +10,16 @@
|
||||
//
|
||||
// all these tests should fail:
|
||||
//
|
||||
typedef char a1[2];
|
||||
typedef char a2[3];
|
||||
|
||||
// Function (block) scope
|
||||
void f()
|
||||
{
|
||||
BOOST_STATIC_ASSERT(sizeof(int) == sizeof(char)); // should not compile
|
||||
BOOST_STATIC_ASSERT(sizeof(a1) == sizeof(a2)); // should not compile
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
// (C) Copyright Steve Cleary & John Maddock 2000.
|
||||
// Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
@ -11,11 +10,13 @@
|
||||
//
|
||||
// this tests should fail:
|
||||
//
|
||||
typedef char a1[2];
|
||||
typedef char a2[3];
|
||||
|
||||
struct Bob
|
||||
{
|
||||
private: // can be in private, to avoid namespace pollution
|
||||
BOOST_STATIC_ASSERT(sizeof(int) == sizeof(char)); // will not compile
|
||||
BOOST_STATIC_ASSERT(sizeof(a1) == sizeof(a2)); // will not compile
|
||||
public:
|
||||
|
||||
// Member function scope: provides access to member variables
|
||||
@ -27,7 +28,6 @@ struct Bob
|
||||
BOOST_STATIC_ASSERT(sizeof(x) == 4);
|
||||
BOOST_STATIC_ASSERT(sizeof(c) == 1);
|
||||
#endif
|
||||
//BOOST_STATIC_ASSERT((sizeof(x) == sizeof(c))); // should not compile
|
||||
return x;
|
||||
}
|
||||
};
|
||||
@ -36,3 +36,4 @@ struct Bob
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
// (C) Copyright Steve Cleary & John Maddock 2000.
|
||||
// Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
@ -19,7 +18,7 @@ struct Bob
|
||||
public:
|
||||
|
||||
// Member function scope: provides access to member variables
|
||||
int x;
|
||||
char x[4];
|
||||
char c;
|
||||
int f()
|
||||
{
|
||||
@ -36,3 +35,4 @@ struct Bob
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
// (C) Copyright Steve Cleary & John Maddock 2000.
|
||||
// Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
@ -37,3 +36,4 @@ Bill<int, char> b;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
// (C) Copyright Steve Cleary & John Maddock 2000.
|
||||
// Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
@ -44,3 +43,4 @@ void foo()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
// (C) Copyright John Maddock 2000.
|
||||
// Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
@ -29,3 +28,4 @@ int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
// (C) Copyright John Maddock 2000.
|
||||
// Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
@ -24,6 +23,12 @@ RandomAccessIterator foo(RandomAccessIterator from, RandomAccessIterator)
|
||||
return from;
|
||||
}
|
||||
|
||||
// ensure that delayed instantiation compilers like Comeau see the failure early
|
||||
// enough for "compile-fail" testing with the Boost.Build testing framework. (Greg Comeau)
|
||||
template
|
||||
std::list<int>::iterator
|
||||
foo(std::list<int>::iterator, std::list<int>::iterator);
|
||||
|
||||
int main()
|
||||
{
|
||||
std::deque<int> d;
|
||||
@ -36,3 +41,4 @@ int main()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
// (C) Copyright John Maddock 2000.
|
||||
// Permission to copy, use, modify, sell and
|
||||
// distribute this software is granted provided this copyright notice appears
|
||||
// in all copies. This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
// 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)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
@ -30,3 +29,4 @@ int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user