Skip to content

Commit

Permalink
Replace C++17 related macros with attributes and specifiers
Browse files Browse the repository at this point in the history
* UPA_FALLTHROUGH -> [[fallthrough]];

* UPA_CONSTEXPR_17 -> constexpr

* UPA_NOEXCEPT_17 -> noexcept
  • Loading branch information
rmisev committed Sep 27, 2024
1 parent c7df091 commit d71eaf3
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 42 deletions.
4 changes: 2 additions & 2 deletions examples/urlparse.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016-2023 Rimas Misevičius
// Copyright 2016-2024 Rimas Misevičius
// Distributed under the BSD-style license that can be
// found in the LICENSE file.
//
Expand Down Expand Up @@ -228,7 +228,7 @@ void read_samples(const char* file_name, SamplesOutput& out)
if (line.empty())
break;
state = State::header;
UPA_FALLTHROUGH
[[fallthrough]];
case State::header: {
bool ok = true;
auto icolon = line.find(':');
Expand Down
14 changes: 1 addition & 13 deletions include/upa/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,11 @@
#endif

// Define UPA_CPP_20 if compiler supports C++20 or later standard
// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
#if defined(_MSVC_LANG) ? (_MSVC_LANG >= 202002) : (__cplusplus >= 202002)
# define UPA_CPP_20
#endif

// Define UPA_CPP_17 if compiler supports C++17 or later standard
// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
#if defined(_MSVC_LANG) ? (_MSVC_LANG >= 201703) : (__cplusplus >= 201703)
# define UPA_CPP_17
# define UPA_FALLTHROUGH [[fallthrough]];
# define UPA_CONSTEXPR_17 constexpr
# define UPA_NOEXCEPT_17 noexcept
#else
# define UPA_FALLTHROUGH
# define UPA_CONSTEXPR_17 inline
# define UPA_NOEXCEPT_17
#endif

// Barrier for pointer anti-aliasing optimizations even across function boundaries.
// This is a slightly modified U_ALIASING_BARRIER macro from the char16ptr.h file
// of the ICU 75.1 library.
Expand Down
24 changes: 12 additions & 12 deletions include/upa/url.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class url {
///
/// @param[in,out] other URL to move to this object
/// @return *this
url& operator=(url&& other) UPA_NOEXCEPT_17;
url& operator=(url&& other) noexcept;

/// @brief Safe move assignment.
///
Expand Down Expand Up @@ -164,7 +164,7 @@ class url {
/// @brief Swaps the contents of two URLs
///
/// @param[in,out] other URL to exchange the contents with
void swap(url& other) UPA_NOEXCEPT_17;
void swap(url& other) noexcept;

// Parser

Expand Down Expand Up @@ -671,7 +671,7 @@ class url {
bool canHaveUsernamePasswordPort() const;

// url record
void move_record(url& other) UPA_NOEXCEPT_17;
void move_record(url& other) noexcept;

// search params
void clear_search_params() noexcept;
Expand Down Expand Up @@ -1080,7 +1080,7 @@ inline url::url(url&& other) noexcept
search_params_ptr_.set_url_ptr(this);
}

inline url& url::operator=(url&& other) UPA_NOEXCEPT_17 {
inline url& url::operator=(url&& other) noexcept {
// move data
move_record(other);
search_params_ptr_ = std::move(other.search_params_ptr_);
Expand Down Expand Up @@ -1108,7 +1108,7 @@ inline url& url::safe_assign(url&& other) {
return *this;
}

inline void url::move_record(url& other) UPA_NOEXCEPT_17 {
inline void url::move_record(url& other) noexcept {
norm_url_ = std::move(other.norm_url_);
part_end_ = other.part_end_;
scheme_inf_ = other.scheme_inf_;
Expand Down Expand Up @@ -1374,7 +1374,7 @@ inline void url::clear() {
clear_search_params();
}

inline void url::swap(url& other) UPA_NOEXCEPT_17 {
inline void url::swap(url& other) noexcept {
url tmp{ std::move(*this) };
*this = std::move(other);
other = std::move(tmp);
Expand Down Expand Up @@ -1796,7 +1796,7 @@ inline validation_errc url_parser::url_parse(url_serializer& urls, const CharT*
state = relative_slash_state;
break;
}
UPA_FALLTHROUGH
[[fallthrough]];
default:
// Set url's username to base's username, url's password to base's password, url's host to base's host,
// url's port to base's port, url's path to base's path, and then remove url's path's last entry, if any
Expand All @@ -1823,7 +1823,7 @@ inline validation_errc url_parser::url_parse(url_serializer& urls, const CharT*
++pointer;
break;
}
UPA_FALLTHROUGH
[[fallthrough]];
default:
// set url's username to base's username, url's password to base's password, url's host to base's host,
// url's port to base's port
Expand Down Expand Up @@ -2152,7 +2152,7 @@ inline validation_errc url_parser::url_parse(url_serializer& urls, const CharT*
break;
case '/':
++pointer;
UPA_FALLTHROUGH
[[fallthrough]];
default:
state = path_state;
break;
Expand Down Expand Up @@ -2566,7 +2566,7 @@ inline std::string& url_serializer::start_part(url::PartType new_pt) {
url_.part_end_[url::PASSWORD] = url_.norm_url_.length();
fill_start_pt = url::HOST_START; // (url::PASSWORD + 1)
}
UPA_FALLTHROUGH
[[fallthrough]];
case url::PASSWORD:
if (new_pt == url::HOST)
url_.norm_url_ += '@';
Expand Down Expand Up @@ -2881,7 +2881,7 @@ inline void url_setter::save_part() {
replace_part(url::HOST_START, "", 0, curr_pt_, 0);
break;
}
UPA_FALLTHROUGH
[[fallthrough]];
default:
if ((curr_pt_ == url::PASSWORD || curr_pt_ == url::PORT) && empty_val)
strp_.clear(); // drop ':'
Expand Down Expand Up @@ -3130,7 +3130,7 @@ inline bool operator==(const url& lhs, const url& rhs) noexcept {
///
/// @param[in,out] lhs
/// @param[in,out] rhs
inline void swap(url& lhs, url& rhs) UPA_NOEXCEPT_17 {
inline void swap(url& lhs, url& rhs) noexcept {
lhs.swap(rhs);
}

Expand Down
2 changes: 1 addition & 1 deletion include/upa/url_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class url_host {
url_host(const url_host&) = default;
url_host(url_host&&) noexcept = default;
url_host& operator=(const url_host&) = default;
url_host& operator=(url_host&&) UPA_NOEXCEPT_17 = default;
url_host& operator=(url_host&&) noexcept = default;

/// Parsing constructor
///
Expand Down
5 changes: 2 additions & 3 deletions include/upa/url_percent_encode.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#ifndef UPA_URL_PERCENT_ENCODE_H
#define UPA_URL_PERCENT_ENCODE_H

#include "config.h"
#include "str_arg.h"
#include "url_utf.h"
#include "util.h"
Expand Down Expand Up @@ -85,7 +84,7 @@ class code_point_set {
/// @brief test code point set contains code point @a c
/// @param[in] c code point to test
template <typename CharT>
UPA_CONSTEXPR_17 bool operator[](CharT c) const {
constexpr bool operator[](CharT c) const {
const auto uc = util::to_unsigned(c);
return is_8bit(uc) && (arr_[uc >> 3] & (1u << (uc & 0x07))) != 0;
}
Expand Down Expand Up @@ -233,7 +232,7 @@ class code_points_multiset {
/// @param[in] c code point to test
/// @param[in] cps code point set
template <typename CharT>
UPA_CONSTEXPR_17 bool char_in_set(CharT c, CP_SET cps) const {
constexpr bool char_in_set(CharT c, CP_SET cps) const {
const auto uc = util::to_unsigned(c);
return is_8bit(uc) && (arr_[uc] & cps);
}
Expand Down
16 changes: 8 additions & 8 deletions include/upa/url_search_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class url_search_params
///
/// @param[in,out] other url_search_params to move to this object
/// @return *this
url_search_params& operator=(url_search_params&& other) UPA_NOEXCEPT_17;
url_search_params& operator=(url_search_params&& other) noexcept;

/// @brief Safe move assignment.
///
Expand All @@ -177,7 +177,7 @@ class url_search_params
/// contents of references returned by url::search_params().
///
/// @param[in,out] other url_search_params to exchange the contents with
void swap(url_search_params& other) UPA_NOEXCEPT_17;
void swap(url_search_params& other) noexcept;

/// Initializes name-value pairs list by parsing query string.
///
Expand Down Expand Up @@ -366,7 +366,7 @@ class url_search_params

void clear_params() noexcept;
void copy_params(const url_search_params& other);
void move_params(url_search_params&& other) UPA_NOEXCEPT_17;
void move_params(url_search_params&& other) noexcept;
void parse_params(string_view query);

void update();
Expand Down Expand Up @@ -462,7 +462,7 @@ inline url_search_params& url_search_params::operator=(const url_search_params&
return *this;
}

inline url_search_params& url_search_params::operator=(url_search_params&& other) UPA_NOEXCEPT_17 {
inline url_search_params& url_search_params::operator=(url_search_params&& other) noexcept {
assert(url_ptr_ == nullptr);
move_params(std::move(other));
return *this;
Expand All @@ -482,7 +482,7 @@ inline void url_search_params::clear() {
update();
}

inline void url_search_params::swap(url_search_params& other) UPA_NOEXCEPT_17 {
inline void url_search_params::swap(url_search_params& other) noexcept {
assert(url_ptr_ == nullptr && other.url_ptr_ == nullptr);

using std::swap;
Expand All @@ -501,7 +501,7 @@ inline void url_search_params::copy_params(const url_search_params& other) {
is_sorted_ = other.is_sorted_;
}

inline void url_search_params::move_params(url_search_params&& other) UPA_NOEXCEPT_17 {
inline void url_search_params::move_params(url_search_params&& other) noexcept {
params_ = std::move(other.params_);
is_sorted_ = other.is_sorted_;
}
Expand Down Expand Up @@ -716,7 +716,7 @@ inline url_search_params::name_value_list url_search_params::do_parse(bool rem_q
break;
}
}
UPA_FALLTHROUGH
[[fallthrough]];
default:
pval->push_back(*it);
break;
Expand Down Expand Up @@ -776,7 +776,7 @@ inline std::string url_search_params::to_string() const {
///
/// @param[in,out] lhs
/// @param[in,out] rhs
inline void swap(url_search_params& lhs, url_search_params& rhs) UPA_NOEXCEPT_17 {
inline void swap(url_search_params& lhs, url_search_params& rhs) noexcept {
lhs.swap(rhs);
}

Expand Down
2 changes: 1 addition & 1 deletion include/upa/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ inline bool contains_null(InputIt first, InputIt last) {
}

template <class CharT>
UPA_CONSTEXPR_17 bool has_xn_label(const CharT* first, const CharT* last) {
constexpr bool has_xn_label(const CharT* first, const CharT* last) {
if (last - first >= 4) {
// search for labels starting with "xn--"
const auto end = last - 4;
Expand Down
4 changes: 2 additions & 2 deletions test/wpt-url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int test_from_file(RunTests run_tests, Args&&... args)
class string_or_null {
public:
// construct
string_or_null() UPA_NOEXCEPT_17 = default;
string_or_null() noexcept = default;
string_or_null(const string_or_null&) = default;
string_or_null(string_or_null&&) noexcept = default;
string_or_null(const picojson::value& json_value)
Expand All @@ -86,7 +86,7 @@ class string_or_null {

// assign
string_or_null& operator=(const string_or_null&) = default;
string_or_null& operator=(string_or_null&&) UPA_NOEXCEPT_17 = default;
string_or_null& operator=(string_or_null&&) noexcept = default;

// has value?
explicit operator bool() const noexcept {
Expand Down

0 comments on commit d71eaf3

Please sign in to comment.