From 639dd11c73bf4535a320af3b03c13549533a91ef Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Mon, 6 Jul 2026 11:42:11 -0600 Subject: [PATCH] :rotating_light: Relax `google-explicit-constructor` lint directives Problem: - The clang-tidy `google-explicit-constructor` can now (clang-22, but perhaps earlier also) deal with `explicit(false)` directives, so we don't need to mark such constructors with a lint-workaround comment. Solution: - Remove the `NOLINT` directives from constructors that can be marked `explicit(false)`. Note: - Implicit conversion operators must still be marked. - In clang-23 it looks like `misc-explicit-constructor` is now the "base" clang-tidy, which `google-explicit-constructor` aliases. --- include/stdx/ct_string.hpp | 3 +-- include/stdx/env.hpp | 6 ++---- include/stdx/span.hpp | 13 +++++-------- include/stdx/utility.hpp | 9 +++------ 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/include/stdx/ct_string.hpp b/include/stdx/ct_string.hpp index f6da6a5..0881b9e 100644 --- a/include/stdx/ct_string.hpp +++ b/include/stdx/ct_string.hpp @@ -27,7 +27,7 @@ concept format_convertible = requires(T t) { template struct ct_string { consteval ct_string() = default; - // NOLINTNEXTLINE(*-avoid-c-arrays, google-explicit-constructor) + // NOLINTNEXTLINE(*-avoid-c-arrays) consteval explicit(false) ct_string(char const (&str)[N]) { for (auto i = std::size_t{}; i < N; ++i) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-*) @@ -36,7 +36,6 @@ template struct ct_string { } template - // NOLINTNEXTLINE(google-explicit-constructor) consteval explicit(false) ct_string(T t) : ct_string(+t) {} consteval explicit(true) ct_string(char const *str, std::size_t sz) { diff --git a/include/stdx/env.hpp b/include/stdx/env.hpp index 69cb04c..f8b3a1f 100644 --- a/include/stdx/env.hpp +++ b/include/stdx/env.hpp @@ -44,8 +44,7 @@ concept envlike = is_specialization_of_v; namespace _env { template struct autowrap { - // NOLINTNEXTLINE(google-explicit-constructor) - consteval autowrap(T t) : value(t) {} + consteval explicit(false) autowrap(T t) : value(t) {} T value; }; @@ -53,8 +52,7 @@ template struct autowrap { template using str_lit_t = char const (&)[N]; template struct autowrap> { - // NOLINTNEXTLINE(google-explicit-constructor) - consteval autowrap(str_lit_t str) : value(str) {} + consteval explicit(false) autowrap(str_lit_t str) : value(str) {} stdx::ct_string value; }; diff --git a/include/stdx/span.hpp b/include/stdx/span.hpp index da7919c..b5c543d 100644 --- a/include/stdx/span.hpp +++ b/include/stdx/span.hpp @@ -93,16 +93,15 @@ class span : public detail::span_base { : base_t{first, sore}, ptr{stdx::to_address(first)} {} template - // NOLINTNEXTLINE(google-explicit-constructor) - constexpr span(std::array &arr LIFETIMEBOUND) noexcept + constexpr explicit(false) span(std::array &arr LIFETIMEBOUND) noexcept : base_t{std::data(arr), N}, ptr{std::data(arr)} { static_assert(Extent == dynamic_extent or Extent <= N, "Span extends beyond available storage"); } template - // NOLINTNEXTLINE(google-explicit-constructor) - constexpr span(std::array const &arr LIFETIMEBOUND) noexcept + constexpr explicit(false) + span(std::array const &arr LIFETIMEBOUND) noexcept : base_t{std::data(arr), N}, ptr{std::data(arr)} { static_assert(Extent == dynamic_extent or Extent <= N, "Span extends beyond available storage"); @@ -112,8 +111,7 @@ class span : public detail::span_base { template using arr_t = type_identity_t (&)[N]; template - // NOLINTNEXTLINE(google-explicit-constructor) - constexpr span(arr_t arr LIFETIMEBOUND) noexcept + constexpr explicit(false) span(arr_t arr LIFETIMEBOUND) noexcept : base_t{std::data(arr), N}, ptr{std::data(arr)} { static_assert(Extent == dynamic_extent or Extent <= N, "Span extends beyond available storage"); @@ -136,8 +134,7 @@ class span : public detail::span_base { template requires(dependent_extent == dynamic_extent or N != dynamic_extent) - // NOLINTNEXTLINE(google-explicit-constructor) - constexpr span(span const &s) noexcept + constexpr explicit(false) span(span const &s) noexcept : base_t{s.data(), s.size()}, ptr{s.data()} {} [[nodiscard]] constexpr auto data() const noexcept -> pointer { diff --git a/include/stdx/utility.hpp b/include/stdx/utility.hpp index fd94f8b..184670b 100644 --- a/include/stdx/utility.hpp +++ b/include/stdx/utility.hpp @@ -192,10 +192,8 @@ template consteval auto operator""_z64() { namespace cxv_detail { struct from_any { - // NOLINTNEXTLINE(google-explicit-constructor) - template constexpr from_any(Ts const &...) {} - // NOLINTNEXTLINE(google-explicit-constructor) - constexpr operator int() const { return 0; } + template + constexpr explicit(false) from_any(Ts const &...) {} }; struct value_marker {}; @@ -252,8 +250,7 @@ constexpr auto is_aligned_with = [](auto v) -> bool { namespace detail { template struct ct_helper { - // NOLINTNEXTLINE(google-explicit-constructor) - consteval ct_helper(auto t) : value(t) {} + consteval explicit(false) ct_helper(auto t) : value(t) {} T value; };