mirror of
https://github.com/boostorg/core.git
synced 2025-11-29 05:40:14 +01:00
Add tests for BOOST_CORE_STATIC_ASSERT
This commit is contained in:
@@ -469,3 +469,12 @@ run minstd_rand_test.cpp
|
|||||||
|
|
||||||
use-project /boost/core/swap : ./swap ;
|
use-project /boost/core/swap : ./swap ;
|
||||||
build-project ./swap ;
|
build-project ./swap ;
|
||||||
|
|
||||||
|
compile static_assert_test.cpp ;
|
||||||
|
compile static_assert_test2.cpp ;
|
||||||
|
compile static_assert_test3.cpp ;
|
||||||
|
|
||||||
|
compile-fail static_assert_fail.cpp ;
|
||||||
|
compile-fail static_assert_fail2.cpp ;
|
||||||
|
compile-fail static_assert_fail3.cpp ;
|
||||||
|
compile-fail static_assert_fail4.cpp ;
|
||||||
|
|||||||
11
test/static_assert_fail.cpp
Normal file
11
test/static_assert_fail.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// Copyright 2025 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/core/static_assert.hpp>
|
||||||
|
|
||||||
|
BOOST_CORE_STATIC_ASSERT( sizeof(char[1]) != 1 );
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
}
|
||||||
14
test/static_assert_fail2.cpp
Normal file
14
test/static_assert_fail2.cpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright 2025 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/core/static_assert.hpp>
|
||||||
|
|
||||||
|
struct X
|
||||||
|
{
|
||||||
|
BOOST_CORE_STATIC_ASSERT( sizeof(char[2]) != 2 );
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
}
|
||||||
10
test/static_assert_fail3.cpp
Normal file
10
test/static_assert_fail3.cpp
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// Copyright 2025 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/core/static_assert.hpp>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BOOST_CORE_STATIC_ASSERT( sizeof(char[3]) != 3 );
|
||||||
|
}
|
||||||
16
test/static_assert_fail4.cpp
Normal file
16
test/static_assert_fail4.cpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2025 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/core/static_assert.hpp>
|
||||||
|
|
||||||
|
template<int C> struct X
|
||||||
|
{
|
||||||
|
BOOST_CORE_STATIC_ASSERT( C >= 0 );
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
X< -4 > x;
|
||||||
|
(void)x;
|
||||||
|
}
|
||||||
17
test/static_assert_test.cpp
Normal file
17
test/static_assert_test.cpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2025 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/core/static_assert.hpp>
|
||||||
|
|
||||||
|
BOOST_CORE_STATIC_ASSERT( sizeof(char[1]) == 1 );
|
||||||
|
|
||||||
|
struct X
|
||||||
|
{
|
||||||
|
BOOST_CORE_STATIC_ASSERT( sizeof(char[2]) == 2 );
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BOOST_CORE_STATIC_ASSERT( sizeof(char[3]) == 3 );
|
||||||
|
}
|
||||||
25
test/static_assert_test2.cpp
Normal file
25
test/static_assert_test2.cpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// Copyright 2025 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/core/static_assert.hpp>
|
||||||
|
|
||||||
|
template<int A, int B> struct plus
|
||||||
|
{
|
||||||
|
static const int value = A + B;
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_CORE_STATIC_ASSERT((plus<1, 2>::value == 3));
|
||||||
|
|
||||||
|
template<int C> struct X
|
||||||
|
{
|
||||||
|
BOOST_CORE_STATIC_ASSERT((plus<C, 1>::value == C + 1));
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
BOOST_CORE_STATIC_ASSERT((plus<3, 4>::value == 7));
|
||||||
|
|
||||||
|
X<4> x;
|
||||||
|
(void)x;
|
||||||
|
}
|
||||||
16
test/static_assert_test3.cpp
Normal file
16
test/static_assert_test3.cpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2025 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/core/static_assert.hpp>
|
||||||
|
|
||||||
|
template<int C> struct X
|
||||||
|
{
|
||||||
|
BOOST_CORE_STATIC_ASSERT( C >= 0 );
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
X<4> x;
|
||||||
|
(void)x;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user