summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/static_assert/test
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/static_assert/test
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/static_assert/test')
-rw-r--r--src/boost/libs/static_assert/test/Jamfile.v230
-rw-r--r--src/boost/libs/static_assert/test/static_assert_test.cpp107
-rw-r--r--src/boost/libs/static_assert/test/static_assert_test_fail_1.cpp23
-rw-r--r--src/boost/libs/static_assert/test/static_assert_test_fail_10.cpp18
-rw-r--r--src/boost/libs/static_assert/test/static_assert_test_fail_2.cpp25
-rw-r--r--src/boost/libs/static_assert/test/static_assert_test_fail_3.cpp39
-rw-r--r--src/boost/libs/static_assert/test/static_assert_test_fail_4.cpp38
-rw-r--r--src/boost/libs/static_assert/test/static_assert_test_fail_5.cpp39
-rw-r--r--src/boost/libs/static_assert/test/static_assert_test_fail_6.cpp46
-rw-r--r--src/boost/libs/static_assert/test/static_assert_test_fail_7.cpp31
-rw-r--r--src/boost/libs/static_assert/test/static_assert_test_fail_8.cpp44
-rw-r--r--src/boost/libs/static_assert/test/static_assert_test_fail_9.cpp32
12 files changed, 472 insertions, 0 deletions
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 000000000..acb28e7ff
--- /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 000000000..bddebcb36
--- /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 000000000..d8e010758
--- /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 000000000..ddc2d1a5d
--- /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 000000000..c75de491c
--- /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 000000000..182658a45
--- /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 000000000..89c27329f
--- /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 000000000..155c199eb
--- /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 000000000..b41aa7471
--- /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 000000000..7e9012694
--- /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 000000000..a087bb709
--- /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 000000000..09e4af9e6
--- /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;
+}
+