diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/static_assert | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/static_assert')
22 files changed, 712 insertions, 0 deletions
diff --git a/src/boost/libs/static_assert/CMakeLists.txt b/src/boost/libs/static_assert/CMakeLists.txt new file mode 100644 index 00000000..33877bc8 --- /dev/null +++ b/src/boost/libs/static_assert/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright 2018 Mike Dev +# 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 + +cmake_minimum_required(VERSION 3.5) +project(BoostStaticAssert LANGUAGES CXX) + +add_library(boost_static_assert INTERFACE) +add_library(Boost::static_assert ALIAS boost_static_assert) + +target_include_directories(boost_static_assert INTERFACE include) + +target_link_libraries(boost_static_assert + INTERFACE + Boost::config +) diff --git a/src/boost/libs/static_assert/Jamfile.v2 b/src/boost/libs/static_assert/Jamfile.v2 new file mode 100644 index 00000000..7c0a96b3 --- /dev/null +++ b/src/boost/libs/static_assert/Jamfile.v2 @@ -0,0 +1,9 @@ +# copyright John Maddock 2003 +# 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) + +# bring in the rules for testing +import testing ; + +build-project test ;
\ No newline at end of file diff --git a/src/boost/libs/static_assert/README.md b/src/boost/libs/static_assert/README.md new file mode 100644 index 00000000..c2900106 --- /dev/null +++ b/src/boost/libs/static_assert/README.md @@ -0,0 +1,36 @@ +Boost StaticAssert Library +============================ + +The Boost StaticAssert library provides static assertions for C++, this library is the ancestor to C++ native static_assert's and +can be used on older compilers which don't have that feature. + +The full documentation is available on [boost.org](http://www.boost.org/doc/libs/release/libs/static_assert). + +## Support, bugs and feature requests ## + +Bugs and feature requests can be reported through the [Gitub issue tracker](https://github.com/boostorg/static_assert/issues) +(see [open issues](https://github.com/boostorg/static_assert/issues) and +[closed issues](https://github.com/boostorg/static_assert/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aclosed)). + +You can submit your changes through a [pull request](https://github.com/boostorg/static_assert/pulls). + +There is no mailing-list specific to Boost StaticAssert, although you can use the general-purpose Boost [mailing-list](http://lists.boost.org/mailman/listinfo.cgi/boost-users) using the tag [static_assert]. + + +## Development ## + +Clone the whole boost project, which includes the individual Boost projects as submodules ([see boost+git doc](https://github.com/boostorg/boost/wiki/Getting-Started)): + + git clone https://github.com/boostorg/boost + cd boost + git submodule update --init + +The Boost StaticAssert Library is located in `libs/static_assert/`. + +### Running tests ### +First, make sure you are in `libs/static_assert/test`. +You can either run all the tests listed in `Jamfile.v2` or run a single test: + + ../../../b2 <- run all tests + ../../../b2 static_assert_test <- single test + diff --git a/src/boost/libs/static_assert/example/Jamfile.v2 b/src/boost/libs/static_assert/example/Jamfile.v2 new file mode 100644 index 00000000..0f3c356b --- /dev/null +++ b/src/boost/libs/static_assert/example/Jamfile.v2 @@ -0,0 +1,20 @@ +# copyright John Maddock 2003 +# 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) + +# bring in the rules for testing +import testing ; + +test-suite static_assert : +# [ run static_assert_example_1.cpp ] + [ run static_assert_example_2.cpp ] + [ run static_assert_example_3.cpp ] +; + + + + + + + diff --git a/src/boost/libs/static_assert/example/static_assert_example_1.cpp b/src/boost/libs/static_assert/example/static_assert_example_1.cpp new file mode 100644 index 00000000..14c529c3 --- /dev/null +++ b/src/boost/libs/static_assert/example/static_assert_example_1.cpp @@ -0,0 +1,34 @@ +// (C) Copyright Steve Cleary & 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) + +// See http://www.boost.org for most recent version including documentation. + +#include <climits> +#include <cwchar> +#include <limits> +#include <boost/static_assert.hpp> + +#if !defined(WCHAR_MIN) +#define WCHAR_MIN 0 +#endif + +namespace boost{ + +namespace my_conditions { +BOOST_STATIC_ASSERT(std::numeric_limits<int>::digits >= 32); +BOOST_STATIC_ASSERT(WCHAR_MIN >= 0); + +} // namespace my_conditions + +} // namespace boost + +int main() +{ + return 0; +} + + + + diff --git a/src/boost/libs/static_assert/example/static_assert_example_2.cpp b/src/boost/libs/static_assert/example/static_assert_example_2.cpp new file mode 100644 index 00000000..38a284be --- /dev/null +++ b/src/boost/libs/static_assert/example/static_assert_example_2.cpp @@ -0,0 +1,40 @@ +// (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) + +// See http://www.boost.org for most recent version including documentation. + +#include <boost/static_assert.hpp> +#include <boost/type_traits.hpp> +#include <iterator> +#include <list> +#include <deque> + +template <class RandomAccessIterator > +RandomAccessIterator foo(RandomAccessIterator from, RandomAccessIterator /*to*/) +{ + // this template can only be used with + // random access iterators... + typedef typename std::iterator_traits< RandomAccessIterator >::iterator_category cat; + BOOST_STATIC_ASSERT((boost::is_convertible<cat, const std::random_access_iterator_tag&>::value)); + // + // detail goes here... + return from; +} + +int main() +{ + std::deque<int> d; + std::list<int> l; + foo(d.begin(), d.end()); // OK + //foo(l.begin(), l.end()); // error + return 0; +} + + + + + + + diff --git a/src/boost/libs/static_assert/example/static_assert_example_3.cpp b/src/boost/libs/static_assert/example/static_assert_example_3.cpp new file mode 100644 index 00000000..1cc15450 --- /dev/null +++ b/src/boost/libs/static_assert/example/static_assert_example_3.cpp @@ -0,0 +1,33 @@ +// (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) + +// See http://www.boost.org for most recent version including documentation. + +#include <limits> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> + +template <class UnsignedInt> +class myclass +{ +private: + BOOST_STATIC_ASSERT((std::numeric_limits<UnsignedInt>::digits >= 16) + && std::numeric_limits<UnsignedInt>::is_specialized + && std::numeric_limits<UnsignedInt>::is_integer + && !std::numeric_limits<UnsignedInt>::is_signed); +public: + /* details here */ +}; + +myclass<unsigned> m1; // this should be OK +//myclass<int> m2; // this should fail +//myclass<unsigned char> m3; // and so should this + +int main() +{ + return 0; +} + + diff --git a/src/boost/libs/static_assert/index.html b/src/boost/libs/static_assert/index.html new file mode 100644 index 00000000..f1e6c323 --- /dev/null +++ b/src/boost/libs/static_assert/index.html @@ -0,0 +1,18 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> + <head> + <meta http-equiv="refresh" content="0; URL=../../doc/html/boost_staticassert.html"> + </head> + <body> + Automatic redirection failed, please go to + <a href="../../doc/html/boost_staticassert.html">../../doc/html/boost_staticassert.html</a> + or view the online version at + <a href="http://www.boost.org/regression-logs/cs-win32_metacomm/doc/html/boost_staticassert.html"> + http://www.boost.org/regression-logs/cs-win32_metacomm/doc/html/boost_staticassert.html</a> + <P>Copyright John Maddock 2006</P> + <P>Distributed under the Boost Software License, Version 1.0. (See accompanying file <A href="../../LICENSE_1_0.txt"> + LICENSE_1_0.txt</A> or copy at <A href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</A>).</P> + </body> +</html> + + diff --git a/src/boost/libs/static_assert/meta/libraries.json b/src/boost/libs/static_assert/meta/libraries.json new file mode 100644 index 00000000..6d0bd321 --- /dev/null +++ b/src/boost/libs/static_assert/meta/libraries.json @@ -0,0 +1,16 @@ +{ + "key": "static_assert", + "name": "Static Assert", + "authors": [ + "John Maddock" + ], + "description": "Static assertions (compile time assertions).", + "category": [ + "Correctness", + "Generic", + "Metaprogramming" + ], + "maintainers": [ + "John Maddock <john -at- johnmaddock.co.uk>" + ] +} diff --git a/src/boost/libs/static_assert/static_assert.htm b/src/boost/libs/static_assert/static_assert.htm new file mode 100644 index 00000000..f1e6c323 --- /dev/null +++ b/src/boost/libs/static_assert/static_assert.htm @@ -0,0 +1,18 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> + <head> + <meta http-equiv="refresh" content="0; URL=../../doc/html/boost_staticassert.html"> + </head> + <body> + Automatic redirection failed, please go to + <a href="../../doc/html/boost_staticassert.html">../../doc/html/boost_staticassert.html</a> + or view the online version at + <a href="http://www.boost.org/regression-logs/cs-win32_metacomm/doc/html/boost_staticassert.html"> + http://www.boost.org/regression-logs/cs-win32_metacomm/doc/html/boost_staticassert.html</a> + <P>Copyright John Maddock 2006</P> + <P>Distributed under the Boost Software License, Version 1.0. (See accompanying file <A href="../../LICENSE_1_0.txt"> + LICENSE_1_0.txt</A> or copy at <A href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</A>).</P> + </body> +</html> + + diff --git a/src/boost/libs/static_assert/test/Jamfile.v2 b/src/boost/libs/static_assert/test/Jamfile.v2 new file mode 100644 index 00000000..acb28e7f --- /dev/null +++ b/src/boost/libs/static_assert/test/Jamfile.v2 @@ -0,0 +1,30 @@ +# copyright John Maddock 2003 +# 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) + +# bring in the rules for testing +import testing ; + +test-suite static_assert : + [ run static_assert_test.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 ] + [ compile-fail static_assert_test_fail_9.cpp ] + [ compile-fail static_assert_test_fail_10.cpp ] +; + +build-project ../example ; + + + + + + + diff --git a/src/boost/libs/static_assert/test/static_assert_test.cpp b/src/boost/libs/static_assert/test/static_assert_test.cpp new file mode 100644 index 00000000..bddebcb3 --- /dev/null +++ b/src/boost/libs/static_assert/test/static_assert_test.cpp @@ -0,0 +1,107 @@ +// (C) Copyright Steve Cleary & 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) + +// See http://www.boost.org for most recent version including documentation. + +#include <boost/static_assert.hpp> + +// +// all these tests should succeed. +// some of these tests are rather simplistic (ie useless) +// in order to ensure that they compile on all platforms. +// + +// Namespace scope +BOOST_STATIC_ASSERT(sizeof(int) >= sizeof(short)); +BOOST_STATIC_ASSERT(sizeof(char) == 1); +BOOST_STATIC_ASSERT_MSG(sizeof(int) >= sizeof(short), "msg1"); +BOOST_STATIC_ASSERT_MSG(sizeof(char) == 1, "msg2"); + +// Function (block) scope +void f() +{ + BOOST_STATIC_ASSERT(sizeof(int) >= sizeof(short)); + BOOST_STATIC_ASSERT(sizeof(char) == 1); + BOOST_STATIC_ASSERT_MSG(sizeof(int) >= sizeof(short), "msg3"); + BOOST_STATIC_ASSERT_MSG(sizeof(char) == 1, "msg4"); +} + +struct Bob +{ + private: // can be in private, to avoid namespace pollution + BOOST_STATIC_ASSERT(sizeof(int) >= sizeof(short)); + BOOST_STATIC_ASSERT(sizeof(char) == 1); + BOOST_STATIC_ASSERT_MSG(sizeof(int) >= sizeof(short), "msg5"); + BOOST_STATIC_ASSERT_MSG(sizeof(char) == 1, "msg6"); + public: + + // Member function scope: provides access to member variables + int x; + char c; + int f() + { +#if defined(_MSC_VER) && _MSC_VER < 1300 // broken sizeof in VC6 + BOOST_STATIC_ASSERT(sizeof(x) >= sizeof(short)); + BOOST_STATIC_ASSERT(sizeof(c) == 1); + BOOST_STATIC_ASSERT_MSG(sizeof(x) >= sizeof(short), "msg7"); + BOOST_STATIC_ASSERT_MSG(sizeof(c) == 1, "msg8"); +#endif + return x; + } +}; + + + +// Template class scope +template <class Int, class Char> +struct Bill +{ + BOOST_STATIC_CONSTANT(int, value = 1); + private: // can be in private, to avoid namespace pollution + BOOST_STATIC_ASSERT(sizeof(Int) > sizeof(char)); + BOOST_STATIC_ASSERT_MSG(sizeof(Int) > sizeof(char), "msg9"); + public: + + // Template member function scope: provides access to member variables + Int x; + Char c; + template <class Int2, class Char2> + void f(Int2 , Char2 ) + { + BOOST_STATIC_ASSERT(sizeof(Int) == sizeof(Int2)); + BOOST_STATIC_ASSERT(sizeof(Char) == sizeof(Char2)); + BOOST_STATIC_ASSERT_MSG(sizeof(Int) == sizeof(Int2), "msg10"); + BOOST_STATIC_ASSERT_MSG(sizeof(Char) == sizeof(Char2), "msg11"); + } +}; + +void test_Bill() // BOOST_STATIC_ASSERTs are not triggerred until instantiated +{ + Bill<int, char> z; + //Bill<int, int> bad; // will not compile + int i = 3; + char ch = 'a'; + z.f(i, ch); + //z.f(i, i); // should not compile +} + +int main() +{ + test_Bill(); + // + // Test variadic macro support: + // +#ifndef BOOST_NO_CXX11_VARIADIC_MACROS + BOOST_STATIC_ASSERT(Bill<int, char>::value); +#ifndef BOOST_NO_CXX11_STATIC_ASSERT + BOOST_STATIC_ASSERT_MSG(Bill<int, char>::value, "This is a message"); +#endif +#endif + return 0; +} + + + + diff --git a/src/boost/libs/static_assert/test/static_assert_test_fail_1.cpp b/src/boost/libs/static_assert/test/static_assert_test_fail_1.cpp new file mode 100644 index 00000000..d8e01075 --- /dev/null +++ b/src/boost/libs/static_assert/test/static_assert_test_fail_1.cpp @@ -0,0 +1,23 @@ +// (C) Copyright Steve Cleary & 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) + +// See http://www.boost.org for most recent version including documentation. + +#include <boost/static_assert.hpp> + +// +// all these tests should fail: +// +typedef char a1[2]; +typedef char a2[3]; + +// Namespace scope +BOOST_STATIC_ASSERT(sizeof(a1) == sizeof(a2)); // will not compile + + + + + + diff --git a/src/boost/libs/static_assert/test/static_assert_test_fail_10.cpp b/src/boost/libs/static_assert/test/static_assert_test_fail_10.cpp new file mode 100644 index 00000000..ddc2d1a5 --- /dev/null +++ b/src/boost/libs/static_assert/test/static_assert_test_fail_10.cpp @@ -0,0 +1,18 @@ +//~ Copyright 2005 Redshift Software, Inc. +//~ Distributed under the Boost Software License, Version 1.0. +//~ (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) + +#include <boost/static_assert.hpp> + +template <int N> +int foo() +{ + BOOST_STATIC_ASSERT( N < 2 ); + + return N; +} + +int main() +{ + return foo<5>(); +} diff --git a/src/boost/libs/static_assert/test/static_assert_test_fail_2.cpp b/src/boost/libs/static_assert/test/static_assert_test_fail_2.cpp new file mode 100644 index 00000000..c75de491 --- /dev/null +++ b/src/boost/libs/static_assert/test/static_assert_test_fail_2.cpp @@ -0,0 +1,25 @@ +// (C) Copyright Steve Cleary & 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) + +// See http://www.boost.org for most recent version including documentation. + +#include <boost/static_assert.hpp> + +// +// all these tests should fail: +// +typedef char a1[2]; +typedef char a2[3]; + +// Function (block) scope +void f() +{ + BOOST_STATIC_ASSERT(sizeof(a1) == sizeof(a2)); // should not compile +} + + + + + diff --git a/src/boost/libs/static_assert/test/static_assert_test_fail_3.cpp b/src/boost/libs/static_assert/test/static_assert_test_fail_3.cpp new file mode 100644 index 00000000..182658a4 --- /dev/null +++ b/src/boost/libs/static_assert/test/static_assert_test_fail_3.cpp @@ -0,0 +1,39 @@ +// (C) Copyright Steve Cleary & 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) + +// See http://www.boost.org for most recent version including documentation. + +#include <boost/static_assert.hpp> + +// +// 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(a1) == sizeof(a2)); // will not compile + public: + + // Member function scope: provides access to member variables + int x; + char c; + int f() + { +#ifndef _MSC_VER // broken sizeof in VC6 + BOOST_STATIC_ASSERT(sizeof(x) == 4); + BOOST_STATIC_ASSERT(sizeof(c) == 1); +#endif + return x; + } +}; + + + + + + diff --git a/src/boost/libs/static_assert/test/static_assert_test_fail_4.cpp b/src/boost/libs/static_assert/test/static_assert_test_fail_4.cpp new file mode 100644 index 00000000..89c27329 --- /dev/null +++ b/src/boost/libs/static_assert/test/static_assert_test_fail_4.cpp @@ -0,0 +1,38 @@ +// (C) Copyright Steve Cleary & 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) + +// See http://www.boost.org for most recent version including documentation. + +#include <boost/config.hpp> +#include <boost/static_assert.hpp> + +// +// all these tests should fail: +// + + +struct Bob +{ + public: + + // Member function scope: provides access to member variables + char x[4]; + char c; + int f() + { +#if !defined(BOOST_MSVC) || BOOST_MSVC > 1200 // broken sizeof in VC6 + BOOST_STATIC_ASSERT(sizeof(x) == 4); + BOOST_STATIC_ASSERT(sizeof(c) == 1); + BOOST_STATIC_ASSERT((sizeof(x) == sizeof(c))); // should not compile +#endif + return x; + } +}; + + + + + + diff --git a/src/boost/libs/static_assert/test/static_assert_test_fail_5.cpp b/src/boost/libs/static_assert/test/static_assert_test_fail_5.cpp new file mode 100644 index 00000000..155c199e --- /dev/null +++ b/src/boost/libs/static_assert/test/static_assert_test_fail_5.cpp @@ -0,0 +1,39 @@ +// (C) Copyright Steve Cleary & 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) + +// See http://www.boost.org for most recent version including documentation. + +#include <boost/static_assert.hpp> + +// +// all these tests should fail: +// + +// Template class scope +template <class Int, class Char> +struct Bill +{ + private: // can be in private, to avoid namespace pollution + BOOST_STATIC_ASSERT(sizeof(Int) == 4); + BOOST_STATIC_ASSERT(sizeof(Int) == sizeof(Char)); // should not compile when instantiated + public: + + // Template member function scope: provides access to member variables + Int x; + Char c; + template <class Int2, class Char2> + void f(Int2 , Char2 ) + { + BOOST_STATIC_ASSERT(sizeof(Int) == sizeof(Int2)); + BOOST_STATIC_ASSERT(sizeof(Char) == sizeof(Char2)); + //BOOST_STATIC_ASSERT(sizeof(Int) == sizeof(Char)); // should not compile when instantiated + } +}; + +Bill<int, char> b; + + + + diff --git a/src/boost/libs/static_assert/test/static_assert_test_fail_6.cpp b/src/boost/libs/static_assert/test/static_assert_test_fail_6.cpp new file mode 100644 index 00000000..b41aa747 --- /dev/null +++ b/src/boost/libs/static_assert/test/static_assert_test_fail_6.cpp @@ -0,0 +1,46 @@ +// (C) Copyright Steve Cleary & 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) + +// See http://www.boost.org for most recent version including documentation. + +#include <boost/static_assert.hpp> + +// +// all these tests should fail: +// + +// Template class scope +template <class Int, class Char> +struct Bill +{ + private: // can be in private, to avoid namespace pollution + BOOST_STATIC_ASSERT(sizeof(Int) == 4); + //BOOST_STATIC_ASSERT(sizeof(Int) == sizeof(Char)); // should not compile when instantiated + public: + + // Template member function scope: provides access to member variables + Int x; + Char c; + template <class Int2, class Char2> + void f(Int2 , Char2 ) + { + BOOST_STATIC_ASSERT(sizeof(Int) == sizeof(Int2)); + BOOST_STATIC_ASSERT(sizeof(Char) == sizeof(Char2)); + BOOST_STATIC_ASSERT(sizeof(Int) == sizeof(Char)); // should not compile when instantiated + } +}; + +void foo() +{ + int i = 0; + char c = 0; + Bill<int, char> b; + // this should fail: + b.f(i, c); +} + + + + diff --git a/src/boost/libs/static_assert/test/static_assert_test_fail_7.cpp b/src/boost/libs/static_assert/test/static_assert_test_fail_7.cpp new file mode 100644 index 00000000..7e901269 --- /dev/null +++ b/src/boost/libs/static_assert/test/static_assert_test_fail_7.cpp @@ -0,0 +1,31 @@ +// (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) + +// See http://www.boost.org for most recent version including documentation. + +#include <climits> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> + +template <class UnsignedInt> +class myclass +{ +private: + BOOST_STATIC_ASSERT(sizeof(UnsignedInt) * CHAR_BIT >= 16); + BOOST_STATIC_ASSERT(std::numeric_limits<UnsignedInt>::is_specialized + && std::numeric_limits<UnsignedInt>::is_integer + && !std::numeric_limits<UnsignedInt>::is_signed); +public: + /* details here */ +}; + +myclass<int> m2; // this should fail +myclass<unsigned char> m3; // and so should this + +int main() +{ + return 0; +} + diff --git a/src/boost/libs/static_assert/test/static_assert_test_fail_8.cpp b/src/boost/libs/static_assert/test/static_assert_test_fail_8.cpp new file mode 100644 index 00000000..a087bb70 --- /dev/null +++ b/src/boost/libs/static_assert/test/static_assert_test_fail_8.cpp @@ -0,0 +1,44 @@ +// (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) + +// See http://www.boost.org for most recent version including documentation. + +#include <iterator> +#include <list> +#include <deque> +#include <boost/static_assert.hpp> +#include <boost/type_traits.hpp> + +template <class RandomAccessIterator > +RandomAccessIterator foo(RandomAccessIterator from, RandomAccessIterator) +{ + // this template can only be used with + // random access iterators... + typedef typename std::iterator_traits< RandomAccessIterator >::iterator_category cat; + BOOST_STATIC_ASSERT((boost::is_convertible<cat*, std::random_access_iterator_tag*>::value)); + // + // detail goes here... + 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; + std::list<int> l; + foo(d.begin(), d.end()); // OK + foo(l.begin(), l.end()); // error + return 0; +} + + + + + diff --git a/src/boost/libs/static_assert/test/static_assert_test_fail_9.cpp b/src/boost/libs/static_assert/test/static_assert_test_fail_9.cpp new file mode 100644 index 00000000..09e4af9e --- /dev/null +++ b/src/boost/libs/static_assert/test/static_assert_test_fail_9.cpp @@ -0,0 +1,32 @@ +// (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) + +// See http://www.boost.org for most recent version including documentation. + +#include <climits> +#include <boost/limits.hpp> +#include <boost/static_assert.hpp> + +template <class UnsignedInt> +class myclass +{ +private: + BOOST_STATIC_ASSERT(sizeof(UnsignedInt) * CHAR_BIT >= 16); + BOOST_STATIC_ASSERT(std::numeric_limits<UnsignedInt>::is_specialized + && std::numeric_limits<UnsignedInt>::is_integer + && !std::numeric_limits<UnsignedInt>::is_signed); +public: + /* details here */ +}; + +myclass<unsigned> m1; // this should be OK +//myclass<int> m2; // this should fail +myclass<unsigned char> m3; // and so should this + +int main() +{ + return 0; +} + |