Remove some warnings in tests

This commit is contained in:
Krystian Stasiowski
2020-02-27 15:51:09 -05:00
parent 4a494ed9b5
commit 54c5d7cef4
4 changed files with 81 additions and 130 deletions

View File

@ -62,11 +62,13 @@
// Can we use [[nodiscard]]?
// KRYSTIAN TODO: these checks need to be improved
#if defined(__has_attribute) && __has_attribute(nodiscard)
#if defined(__has_attribute)
#if __has_attribute(nodiscard)
#define BOOST_STATIC_STRING_NODISCARD [[nodiscard]]
#else
#define BOOST_STATIC_STRING_NODISCARD
#endif
#endif
// _MSVC_LANG isn't avaliable until after VS2015
#if defined(_MSC_VER) && _MSC_VER < 1910L

View File

@ -1,38 +1,18 @@
#include <fstream>
#include <streambuf>
#include <boost/static_string/detail/static_string.hpp>
namespace boost {
namespace static_strings {
static_assert(std::is_base_of<
detail::static_string_base_zero<0, char, std::char_traits<char>>,
detail::static_string_base<0, char, std::char_traits<char>>,
static_string<0>>::value,
"the zero size optimization shall be used for N = 0");
#ifdef BOOST_STATIC_STRING_USE_NULL_OPTIMIZATION
static_assert(std::is_base_of<
detail::static_string_base_null<1, char, std::char_traits<char>>,
static_string<1>>::value,
"the null terminator optimization shall be used for N <= (std::numeric_limits<char>::max)()");
static_assert(std::is_base_of<
detail::static_string_base_null<(std::numeric_limits<char>::max)(), char, std::char_traits<char>>,
static_string<(std::numeric_limits<char>::max)()>>::value,
"the null terminator optimization shall be used for N <= std::numeric_limits<char>::max()");
static_assert(std::is_base_of<
detail::static_string_base_zero<(std::numeric_limits<char>::max)() + 1, char, std::char_traits<char>>,
static_string<(std::numeric_limits<char>::max)() + 1>>::value,
"the minimum size type optimization shall be used for N > std::numeric_limits<char>::max()");
#else
static_assert(std::is_base_of<
detail::static_string_base_zero<(std::numeric_limits<char>::max)() + 1, char, std::char_traits<char>>,
detail::static_string_base<(std::numeric_limits<char>::max)() + 1, char, std::char_traits<char>>,
static_string<(std::numeric_limits<char>::max)() + 1>>::value,
"the minimum size type optimization shall be used for N > 0");
#endif
static_assert(!detail::is_input_iterator<int>::value, "is_input_iterator is incorrect");
static_assert(!detail::is_input_iterator<double>::value, "is_input_iterator is incorrect");
@ -43,5 +23,5 @@ static_assert(!detail::is_forward_iterator<int>::value, "is_forward_iterator is
static_assert(!detail::is_forward_iterator<double>::value, "is_forward_iterator is incorrect");
static_assert(detail::is_forward_iterator<int*>::value, "is_forward_iterator is incorrect");
static_assert(!detail::is_forward_iterator<std::istreambuf_iterator<char>>::value, "is_forward_iterator is incorrect");
}
}
} // boost
} // static_strings

View File

@ -7,36 +7,36 @@
// Official repository: https://github.com/boostorg/static_string
//
#include <string>
#include <boost/static_string/static_string.hpp>
#include <string>
namespace boost {
namespace static_strings {
// char_traits aren't fully constexpr until c++20
#if BOOST_STATIC_STRING_STANDARD_VERSION <= 201703L && BOOST_STATIC_STRING_STANDARD_VERSION >= 201402L
struct cxper_char_traits
{
using char_type = char;
using int_type = int;
using state_type = mbstate_t;
using state_type = std::mbstate_t;
static constexpr void assign(char_type& c1, const char_type& c2) noexcept {}
static constexpr bool eq(char_type c1, char_type c2) noexcept { return true; }
static constexpr bool lt(char_type c1, char_type c2) noexcept { return true; }
static constexpr void assign(char_type&, const char_type&) noexcept {}
static constexpr bool eq(char_type, char_type) noexcept { return true; }
static constexpr bool lt(char_type, char_type) noexcept { return true; }
static constexpr int compare(const char_type* s1, const char_type* s2, size_t n) { return 0; }
static constexpr size_t length(const char_type* s) { return 0; }
static constexpr const char_type* find(const char_type* s, size_t n,
const char_type& a)
{
return 0;
}
static constexpr char_type* move(char_type* s1, const char_type* s2, size_t n) { return s1; }
static constexpr char_type* copy(char_type* s1, const char_type* s2, size_t n) { return s1; }
static constexpr char_type* assign(char_type* s, size_t n, char_type a) { return s; }
static constexpr int compare(const char_type*, const char_type*, std::size_t) { return 0; }
static constexpr std::size_t length(const char_type*) { return 0; }
static constexpr const char_type* find(const char_type*, std::size_t, const char_type&){ return 0; }
static constexpr char_type* move(char_type* s1, const char_type*, std::size_t) { return s1; }
static constexpr char_type* copy(char_type* s1, const char_type*, std::size_t) { return s1; }
static constexpr char_type* assign(char_type* s, std::size_t, char_type) { return s; }
};
#else
using cxper_char_traits = std::char_traits<char>;
#endif
using cstatic_string = boost::static_strings::basic_static_string<50, char, cxper_char_traits>;
using cstatic_string = basic_static_string<50, char, cxper_char_traits>;
inline
constexpr
@ -73,55 +73,39 @@ testConstantEvaluation()
// element access
{
auto j = a.at(0);
static_cast<void>(j);
}
{
auto j = a[0];
static_cast<void>(j);
}
{
auto j = a.front();
static_cast<void>(j);
}
{
auto j = a.back();
static_cast<void>(j);
}
{
auto j = a.data();
}
{
auto j = a.c_str();
}
{
auto j = a.begin();
}
{
auto j = a.cbegin();
}
{
auto j = a.end();
}
{
auto j = a.cend();
}
a.data();
a.c_str();
a.begin();
a.cbegin();
a.end();
a.cend();
// reverse iterators
{
auto j = a.rbegin();
}
{
auto j = a.crbegin();
}
{
auto j = a.rend();
}
{
auto j = a.crend();
}
a.rbegin();
a.crbegin();
a.rend();
a.crend();
// capacity and size
auto j = cstatic_string().size() +
cstatic_string().empty() +
cstatic_string().length() +
cstatic_string().max_size() +
cstatic_string().capacity();
cstatic_string().size();
cstatic_string().empty();
cstatic_string().length();
cstatic_string().max_size();
cstatic_string().capacity();
// clear
a.clear();
@ -263,34 +247,26 @@ testConstantEvaluation()
// element access
{
auto j = a.at(0);
static_cast<void>(j);
}
{
auto j = a[0];
static_cast<void>(j);
}
{
auto j = a.front();
static_cast<void>(j);
}
{
auto j = a.back();
static_cast<void>(j);
}
{
auto j = a.data();
}
{
auto j = a.c_str();
}
{
auto j = a.begin();
}
{
auto j = a.cbegin();
}
{
auto j = a.end();
}
{
auto j = a.cend();
}
a.data();
a.c_str();
a.begin();
a.cbegin();
a.end();
a.cend();
// reverse iterators
//{
@ -307,11 +283,11 @@ testConstantEvaluation()
//}
// capacity and size
auto j = cstatic_string().size() +
cstatic_string().empty() +
cstatic_string().length() +
cstatic_string().max_size() +
cstatic_string().capacity();
cstatic_string().size();
cstatic_string().empty();
cstatic_string().length();
cstatic_string().max_size();
cstatic_string().capacity();
// clear
a.clear();
@ -453,41 +429,33 @@ testConstantEvaluation()
// element access
{
auto j = a.at(0);
static_cast<void>(j);
}
{
auto j = a[0];
static_cast<void>(j);
}
{
auto j = a.front();
static_cast<void>(j);
}
{
auto j = a.back();
static_cast<void>(j);
}
{
auto j = a.data();
}
{
auto j = a.c_str();
}
{
auto j = a.begin();
}
{
auto j = a.cbegin();
}
{
auto j = a.end();
}
{
auto j = a.cend();
}
a.data();
a.c_str();
a.begin();
a.cbegin();
a.end();
a.cend();
// capacity and size
auto j = cstatic_string().size() +
cstatic_string().empty() +
cstatic_string().length() +
cstatic_string().max_size() +
cstatic_string().capacity();
cstatic_string().size();
cstatic_string().empty();
cstatic_string().length();
cstatic_string().max_size();
cstatic_string().capacity();
// clear
a.clear();
@ -605,3 +573,5 @@ testConstantEvaluation()
cstatic_string().capacity();
#endif
}
} // static_strings
} // boost

View File

@ -10,11 +10,10 @@
// Test that header file is self-contained.
#include <boost/static_string/static_string.hpp>
#include "constexpr_tests.hpp"
#include "compile_fail.hpp"
#include <boost/core/lightweight_test.hpp>
#include "constexpr_tests.hpp"
#include <cstdlib>
#include <cwchar>
#include <sstream>
@ -243,14 +242,14 @@ testTS(Arithmetic value, const char* str_expected = "", const wchar_t* wstr_expe
{
if (std::is_signed<Arithmetic>::value)
{
return std::strtoll(str.begin(), nullptr, 10) == value &&
std::wcstoll(wstr.begin(), nullptr, 10) == value &&
return Arithmetic(std::strtoll(str.begin(), nullptr, 10)) == value &&
Arithmetic(std::wcstoll(wstr.begin(), nullptr, 10)) == value &&
(test_expected ? str == str_expected && wstr == wstr_expected : true);
}
else
{
return std::strtoull(str.begin(), nullptr, 10) == value &&
std::wcstoull(wstr.begin(), nullptr, 10) == value &&
return Arithmetic(std::strtoull(str.begin(), nullptr, 10)) == value &&
Arithmetic(std::wcstoull(wstr.begin(), nullptr, 10)) == value &&
(test_expected ? str == str_expected && wstr == wstr_expected : true);
}
}