Skip to content

Commit

Permalink
Clang 14 support
Browse files Browse the repository at this point in the history
1. Bug fix
2. Clear warnings
3. Fix typo
  • Loading branch information
HenryAWE committed Jan 28, 2024
1 parent efd3d59 commit 6202f3b
Show file tree
Hide file tree
Showing 16 changed files with 83 additions and 61 deletions.
2 changes: 1 addition & 1 deletion doc/en/build.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Building
## Prerequisites
1. Compiler that supports C++20. Recommended compilers: `MSVC 19.3` (`Visual Studio 2022`) or higher, `GCC 12` or higher.
1. Compiler that supports C++20. Recommended compilers: `MSVC 19.3` (`Visual Studio 2022`) or higher, `GCC 12` or higher, `Clang 14` or higher.
2. `CMake`: `3.20` or higher.
3. `GoogleTest` (optional): Only required when building unit tests.

Expand Down
2 changes: 1 addition & 1 deletion doc/zh-CN/build.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 构建
## 前置要求
1. 任意支持 C++20 的编译器,推荐:`MSVC 19.3``Visual Studio 2022`)或以上、`GCC 12` 或以上
1. 任意支持 C++20 的编译器,推荐:`MSVC 19.3``Visual Studio 2022`)或以上、`GCC 12` 或以上`Clang 14` 或以上
2. `CMake``3.20` 或以上
3. `GoogleTest` (可选):仅构建单元测试时需要

Expand Down
3 changes: 3 additions & 0 deletions example/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ int main()
#ifdef PAPILIO_COMPILER_GCC
println("PAPILIO_COMPILER_GCC = {}", PAPILIO_COMPILER_GCC);
#endif
#ifdef PAPILIO_COMPILER_CLANG
println("PAPILIO_COMPILER_CLANG = {}", PAPILIO_COMPILER_CLANG);
#endif

#ifdef PAPILIO_HAS_MULTIDIMENSIONAL_SUBSCRIPT
println("PAPILIO_HAS_MULTIDIMENSIONAL_SUBSCRIPT = {:d}L", PAPILIO_HAS_MULTIDIMENSIONAL_SUBSCRIPT);
Expand Down
3 changes: 3 additions & 0 deletions example/playground/ipapilio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class ipapilio

std::string help;
callback_t callback;

command_data(std::string h, callback_t cb)
: help(std::move(h)), callback(cb) {}
};

std::map<std::string, command_data, std::less<>> m_cmds;
Expand Down
2 changes: 1 addition & 1 deletion include/papilio/access/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct tuple_accessor
using format_arg_type = basic_format_arg<Context>;

[[nodiscard]]
static consteval std::size_t size() noexcept
static constexpr std::size_t size() noexcept
{
return std::tuple_size_v<Tuple>;
}
Expand Down
21 changes: 10 additions & 11 deletions include/papilio/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class small_vector_base : public detail::small_vector_impl
using difference_type = std::ptrdiff_t;
using reference = value_type&;
using const_reference = const value_type&;
using pointer = std::allocator_traits<Allocator>::pointer;
using const_pointer = std::allocator_traits<Allocator>::const_pointer;
using pointer = typename std::allocator_traits<Allocator>::pointer;
using const_pointer = typename std::allocator_traits<Allocator>::const_pointer;
using iterator = pointer;
using const_iterator = const_pointer;
using reverse_iterator = std::reverse_iterator<iterator>;
Expand Down Expand Up @@ -250,12 +250,12 @@ class small_vector : public small_vector_base<T, Allocator>
using difference_type = std::ptrdiff_t;
using reference = value_type&;
using const_reference = const value_type&;
using pointer = my_base::pointer;
using const_pointer = my_base::const_pointer;
using iterator = my_base::iterator;
using const_iterator = my_base::const_iterator;
using reverse_iterator = my_base::reverse_iterator;
using const_reverse_iterator = my_base::const_reverse_iterator;
using pointer = typename my_base::pointer;
using const_pointer = typename my_base::const_pointer;
using iterator = typename my_base::iterator;
using const_iterator = typename my_base::const_iterator;
using reverse_iterator = typename my_base::reverse_iterator;
using const_reverse_iterator = typename my_base::const_reverse_iterator;

small_vector() noexcept(std::is_nothrow_default_constructible_v<Allocator>)
: my_base(), m_data()
Expand Down Expand Up @@ -708,7 +708,6 @@ class small_vector : public small_vector_base<T, Allocator>
PAPILIO_ASSERT(this->size() < this->capacity());

size_type tmp_size = this->size();
size_type tmp_capacity = this->capacity();
pointer tmp_ptr = std::allocator_traits<Allocator>::allocate(
getal(), tmp_size
);
Expand Down Expand Up @@ -1169,8 +1168,8 @@ class fixed_flat_map : public detail::fixed_flat_map_impl
using key_compare = Compare;
using reference = value_type&;
using const_reference = value_type&;
using iterator = underlying_type::iterator;
using const_iterator = underlying_type::const_iterator;
using iterator = typename underlying_type::iterator;
using const_iterator = typename underlying_type::const_iterator;

class value_compare :
public detail::value_compare_base<key_compare, is_transparent_v<Compare>>
Expand Down
28 changes: 17 additions & 11 deletions include/papilio/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class basic_format_arg
{
public:
using value_type = std::remove_cvref_t<T>;
using accessor_t = handle_impl<T>::accessor_t;
using accessor_t = typename handle_impl<T>::accessor_t;

handle_impl_ptr(const T& val) noexcept
: m_ptr(std::addressof(val), false) {}
Expand Down Expand Up @@ -235,7 +235,7 @@ class basic_format_arg
{
public:
using value_type = std::remove_cvref_t<T>;
using accessor_t = handle_impl<T>::accessor_t;
using accessor_t = typename handle_impl<T>::accessor_t;

template <typename Arg>
requires std::is_constructible_v<T, Arg>
Expand Down Expand Up @@ -415,7 +415,7 @@ class basic_format_arg
void construct_impl(Args&&... args)
{
static_assert(detail::use_handle<typename Impl::value_type, char_type>);
static_assert(sizeof(Impl) <= m_storage.size());
static_assert(sizeof(Impl) <= storage_size);

new(ptr()) Impl(std::forward<Args>(args)...);
}
Expand Down Expand Up @@ -806,7 +806,7 @@ namespace detail
return idx.visit(
[this]<typename T>(const T& v) -> bool
{
if constexpr(std::is_same_v<T, indexing_value_type::index_type>)
if constexpr(std::is_same_v<T, typename indexing_value_type::index_type>)
{
if(v < 0)
return false;
Expand Down Expand Up @@ -912,7 +912,7 @@ class static_format_args final : public detail::format_args_base<Context, CharT>
using my_base::get;

[[nodiscard]]
bool check(string_view_type key) const noexcept
bool check(string_view_type key) const noexcept override
{
return m_named_args.contains(key);
}
Expand Down Expand Up @@ -1394,7 +1394,7 @@ class basic_format_parse_context
using string_type = std::basic_string<char_type>;
using string_view_type = std::basic_string_view<char_type>;
using string_ref_type = utf::basic_string_ref<char_type>;
using const_iterator = string_ref_type::const_iterator;
using const_iterator = typename string_ref_type::const_iterator;
using iterator = const_iterator;
using size_type = std::size_t;
using format_context_type = FormatContext;
Expand Down Expand Up @@ -1499,13 +1499,19 @@ namespace detail
{
// clang-format off

template <typename T, typename Context, typename Formatter = Context::template formatter_type<std::remove_const_t<T>>>
template <
typename T,
typename Context,
typename Formatter = typename Context::template formatter_type<std::remove_const_t<T>>>
concept formattable_with_impl =
std::semiregular<Formatter> &&
requires(Formatter& f, const Formatter& cf, T&& val, Context fmt_ctx, basic_format_parse_context<Context> parse_ctx)
{
{ f.parse(parse_ctx) } -> std::same_as<typename decltype(parse_ctx)::iterator>;
{ cf.format(val, fmt_ctx) } -> std::same_as<typename Context::iterator>;
requires(Formatter& f, const Formatter& cf, T&& val, Context fmt_ctx, basic_format_parse_context<Context> parse_ctx) {
{
f.parse(parse_ctx)
} -> std::same_as<typename decltype(parse_ctx)::iterator>;
{
cf.format(val, fmt_ctx)
} -> std::same_as<typename Context::iterator>;
};

// clang-format on
Expand Down
6 changes: 3 additions & 3 deletions include/papilio/core.inl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void basic_format_arg<Context>::handle_impl_ptr<T>::format(parse_context& parse_
{
if constexpr(formattable_with<value_type, Context>)
{
using formatter_t = Context::template formatter_type<value_type>;
using formatter_t = typename Context::template formatter_type<value_type>;
formatter_t fmt;
parse_ctx.advance_to(fmt.parse(parse_ctx));

Expand All @@ -34,7 +34,7 @@ void basic_format_arg<Context>::handle_impl_soo<T>::format(parse_context& parse_
{
if constexpr(formattable_with<value_type, Context>)
{
using formatter_t = Context::template formatter_type<value_type>;
using formatter_t = typename Context::template formatter_type<value_type>;
formatter_t fmt;
parse_ctx.advance_to(fmt.parse(parse_ctx));

Expand Down Expand Up @@ -77,7 +77,7 @@ void basic_format_arg<Context>::format(parse_context& parse_ctx, Context& out_ct
}
else if constexpr(formattable_with<T, Context>)
{
using formatter_t = Context::template formatter_type<T>;
using formatter_t = typename Context::template formatter_type<T>;
formatter_t fmt;
parse_ctx.advance_to(fmt.parse(parse_ctx));

Expand Down
7 changes: 2 additions & 5 deletions include/papilio/detail/compat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ inline void unreachable()
std::unreachable();
#elif defined PAPILIO_COMPILER_MSVC
__assume(false);
#elif defined PAPILIO_COMPILER_GCC
#elif defined PAPILIO_COMPILER_GCC || defined PAPILIO_COMPILER_CLANG
__builtin_unreachable();

// TODO: Clang support

#else
// An empty function body and the [[noreturn]] attribute is enough to raise undefined behavior.
#endif
}

// forwark_like<T, U> of C++ 23
// forward_like<T, U> of C++ 23
// Use implementation from cppreference.com
PAPILIO_EXPORT template <class T, class U>
[[nodiscard]]
Expand Down
8 changes: 5 additions & 3 deletions include/papilio/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
# define PAPILIO_COMPILER_MSVC _MSC_VER
#endif
#ifdef __GNUC__
# define PAPILIO_COMPILER_GCC __GNUC__
# ifndef __clang__
# define PAPILIO_COMPILER_GCC __GNUC__
# else
# define PAPILIO_COMPILER_CLANG __clang_major__
# endif
#endif

// TODO: Clang support

#define PAPILIO_ASSERT(expr) assert(expr)

#if defined(_WIN32) || defined(_WIN64)
Expand Down
8 changes: 4 additions & 4 deletions include/papilio/script/interpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ class basic_interpreter_base : public script_base

if constexpr(char8_like<char_type>)
{
auto result = std::from_chars(
std::from_chars(
std::bit_cast<const char_type*>(start.base()),
std::bit_cast<const char_type*>(stop.base()),
val
Expand All @@ -717,7 +717,7 @@ class basic_interpreter_base : public script_base
else
{
std::string tmp = string_ref_type(start, stop).to_string();
auto result = std::from_chars(
std::from_chars(
std::to_address(tmp.begin()),
std::to_address(tmp.end()),
val
Expand Down Expand Up @@ -895,7 +895,7 @@ class basic_interpreter :

using parse_context = basic_format_parse_context<FormatContext>;

using iterator = my_base::iterator;
using iterator = typename my_base::iterator;
static_assert(std::is_same_v<iterator, typename parse_context::iterator>);

basic_interpreter() = default;
Expand Down Expand Up @@ -1111,7 +1111,7 @@ class basic_interpreter :
}
else
{
using int_t = variable_type::int_type;
using int_t = typename variable_type::int_type;
int_t val = my_base::template parse_integer<int_t>(start, int_end).first;

return std::make_pair(val, int_end);
Expand Down
2 changes: 2 additions & 0 deletions include/papilio/utf/codepoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ PAPILIO_EXPORT class codepoint
return *this;
}

constexpr codepoint& operator=(const codepoint&) noexcept = default;

constexpr void clear() noexcept
{
m_data[0] = 0;
Expand Down
21 changes: 15 additions & 6 deletions include/papilio/utf/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ namespace detail
constexpr const_str_iter_impl() noexcept = default;
constexpr const_str_iter_impl(const const_str_iter_impl&) noexcept = default;

constexpr const_str_iter_impl& operator=(const const_str_iter_impl&) noexcept = default;

protected:
constexpr const_str_iter_impl(string_view_type str, size_type offset, std::uint8_t len) noexcept
: m_str(str), m_offset(offset), m_len(len) {}
Expand Down Expand Up @@ -150,6 +152,8 @@ namespace detail
constexpr const_str_iter_impl() noexcept = default;
constexpr const_str_iter_impl(const const_str_iter_impl&) noexcept = default;

constexpr const_str_iter_impl& operator=(const const_str_iter_impl&) noexcept = default;

protected:
constexpr const_str_iter_impl(string_view_type str, size_type offset, std::uint8_t len) noexcept
: m_str(str), m_offset(offset), m_len(len) {}
Expand Down Expand Up @@ -238,8 +242,13 @@ namespace detail
constexpr const_str_iter_impl() noexcept = default;
constexpr const_str_iter_impl(const const_str_iter_impl&) noexcept = default;

constexpr const_str_iter_impl& operator=(const const_str_iter_impl&) noexcept = default;

private:
using base_iter_t = typename string_view_type::const_iterator;

protected:
constexpr const_str_iter_impl(string_view_type::const_iterator iter) noexcept
constexpr const_str_iter_impl(base_iter_t iter) noexcept
: m_iter(iter) {}

constexpr void next() noexcept
Expand Down Expand Up @@ -288,7 +297,7 @@ namespace detail
}

private:
string_view_type::const_iterator m_iter;
base_iter_t m_iter;
};

class str_static_base
Expand Down Expand Up @@ -833,9 +842,9 @@ class basic_string_ref<CharT> : public detail::str_base<CharT, basic_string_ref<
using string_type = std::basic_string<CharT>;
using string_view_type = std::basic_string_view<CharT>;

using const_iterator = my_base::const_iterator;
using const_iterator = typename my_base::const_iterator;
using iterator = const_iterator;
using const_reverse_iterator = my_base::const_reverse_iterator;
using const_reverse_iterator = typename my_base::const_reverse_iterator;
using reverse_iterator = const_reverse_iterator;

constexpr basic_string_ref() noexcept = default;
Expand Down Expand Up @@ -1260,8 +1269,8 @@ class basic_string_container<CharT> : public detail::str_base<CharT, basic_strin
using string_type = std::basic_string<CharT>;
using string_ref_type = basic_string_ref<CharT>;

using const_iterator = my_base::const_iterator;
using const_reverse_iterator = my_base::const_reverse_iterator;
using const_iterator = typename my_base::const_iterator;
using const_reverse_iterator = typename my_base::const_reverse_iterator;

basic_string_container() noexcept = default;
basic_string_container(std::nullptr_t) = delete;
Expand Down
10 changes: 6 additions & 4 deletions include/papilio/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ inline namespace literals

PAPILIO_EXPORT template <typename T>
struct independent_proxy : public std::reference_wrapper<T>
{};
{
using std::reference_wrapper<T>::reference_wrapper;
};

PAPILIO_EXPORT struct independent_t
{
Expand Down Expand Up @@ -623,7 +625,7 @@ namespace detail
return *this;
}

constexpr void swap(compressed_pair_impl& other) noexcept
constexpr void swap(compressed_pair_impl&) noexcept
{
// empty
}
Expand Down Expand Up @@ -698,8 +700,8 @@ class basic_iterbuf :
public:
using char_type = CharT;
using iterator = Iterator;
using int_type = base::int_type;
using traits_type = base::traits_type;
using int_type = typename base::int_type;
using traits_type = typename base::traits_type;

basic_iterbuf() = default;

Expand Down
5 changes: 4 additions & 1 deletion test/test_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class yes_no_numpunct : public std::numpunct<CharT>
using base = std::numpunct<CharT>;

public:
using string_type = base::string_type;
using string_type = typename base::string_type;

protected:
string_type do_truename() const override
Expand Down Expand Up @@ -262,6 +262,9 @@ struct large_unformattable_type
struct custom_type
{
int val = 0;

custom_type(int v)
: val(v) {}
};

struct large_custom_type
Expand Down
Loading

0 comments on commit 6202f3b

Please sign in to comment.