From 750f66d235654c7802c46df1719a17b50cac02d6 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Fri, 10 Jul 2020 20:20:40 -0700 Subject: [PATCH 1/4] Limit line length to 120 columns Teach validate.cpp to complain if there are more than 120 code units between line endings in files with particular extensions. Fix the files that it complains about. --- stl/inc/memory | 3 +- .../test.cpp | 65 ++++++++-------- tests/std/tests/P0088R3_variant/test.cpp | 12 ++- .../VSO_0191296_allocator_construct/test.cpp | 74 ++++++++++--------- tools/validate/validate.cpp | 35 ++++++++- 5 files changed, 113 insertions(+), 76 deletions(-) diff --git a/stl/inc/memory b/stl/inc/memory index 3b77c4313b3..69eed6da175 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -142,7 +142,8 @@ namespace ranges { using _Not_quite_object::_Not_quite_object; // clang-format off - template _Se1, _No_throw_forward_iterator _It2, _No_throw_sentinel_for<_It2> _Se2> + template _Se1, _No_throw_forward_iterator _It2, + _No_throw_sentinel_for<_It2> _Se2> requires constructible_from, iter_rvalue_reference_t<_It1>> uninitialized_move_result<_It1, _It2> operator()(_It1 _First1, _Se1 _Last1, _It2 _First2, _Se2 _Last2) const { // clang-format on diff --git a/tests/std/tests/Dev11_0437519_container_requirements/test.cpp b/tests/std/tests/Dev11_0437519_container_requirements/test.cpp index 9dc7c995fc2..2a5eff8a9bd 100644 --- a/tests/std/tests/Dev11_0437519_container_requirements/test.cpp +++ b/tests/std/tests/Dev11_0437519_container_requirements/test.cpp @@ -329,42 +329,43 @@ struct emplace_argument { // clang-format off -#define DEFINE_TYPE(name, dtor, default_ctor, copy_ctor, move_ctor, emplace_ctor, copy_assign, move_assign, emplace_assign) \ - class name { \ - public: name(key) { } \ - private: dtor ~name() { } \ - private: default_ctor name() { } \ - private: copy_ctor name(name const&) { } \ - private: move_ctor name(name&&) { } \ - private: emplace_ctor name(emplace_argument&&) { } \ - private: emplace_ctor name(emplace_argument&&, emplace_argument&&) { } \ - private: emplace_ctor name(emplace_argument&&, emplace_argument&&, emplace_argument&&) { } \ - private: copy_assign name& operator=(name const&) { return *this; } \ - private: move_assign name& operator=(name&&) noexcept { return *this; } \ - private: emplace_assign name& operator=(emplace_argument&&) { return *this; } \ +#define DEFINE_TYPE(name, dtor, def_ctor, copy_ctor, move_ctor, emp_ctor, copy_assign, move_assign, emp_assign) \ + class name { \ + public: name(key) { } \ + private: dtor ~name() { } \ + private: def_ctor name() { } \ + private: copy_ctor name(name const&) { } \ + private: move_ctor name(name&&) { } \ + private: emp_ctor name(emp_argument&&) { } \ + private: emp_ctor name(emp_argument&&, emp_argument&&) { } \ + private: emp_ctor name(emp_argument&&, emp_argument&&, emp_argument&&) { } \ + private: copy_assign name& operator=(name const&) { return *this; } \ + private: move_assign name& operator=(name&&) noexcept { return *this; } \ + private: emp_assign name& operator=(emp_argument&&) { return *this; } \ } #define YES public: -// dtor default ctor copy ctor move ctor emplace ctor copy assign move assign emplace assign -DEFINE_TYPE(erasable , YES , , , , , , , ); -DEFINE_TYPE(default_constructible, YES , YES , , , , , , ); -DEFINE_TYPE(copy_insertable , YES , , YES , YES , , , , ); -DEFINE_TYPE(move_insertable , YES , , , YES , , , , ); -DEFINE_TYPE(emplace_constructible, YES , , , , YES , , , ); -DEFINE_TYPE(copy_assignable , YES , , , , , YES , YES , ); -DEFINE_TYPE(move_assignable , YES , , , , , , YES , ); -DEFINE_TYPE(equality_comparable , YES , , , , , , , ); -DEFINE_TYPE(less_comparable , YES , , , , , , , ); - -DEFINE_TYPE(ca_ci , YES , , YES , YES , , YES , YES , ); -DEFINE_TYPE(ci_ma , YES , , YES , YES , , , YES , ); -DEFINE_TYPE(dc_mi , YES , YES , , YES , , , , ); -DEFINE_TYPE(ec_ma_mi , YES , , , YES , YES , , YES , ); -DEFINE_TYPE(ec_mi , YES , , , YES , YES , , , ); -DEFINE_TYPE(ma_mi , YES , , , YES , , , YES , ); -DEFINE_TYPE(ec_ea , YES , , , , YES , , , YES ); -DEFINE_TYPE(ec_ea_mi , YES , , , YES , YES , , , YES ); +// default copy move emplace copy move emplace +// dtor ctor ctor ctor ctor assign assign assign +DEFINE_TYPE(erasable , YES , , , , , , , ); +DEFINE_TYPE(default_constructible, YES , YES , , , , , , ); +DEFINE_TYPE(copy_insertable , YES , , YES , YES , , , , ); +DEFINE_TYPE(move_insertable , YES , , , YES , , , , ); +DEFINE_TYPE(emplace_constructible, YES , , , , YES , , , ); +DEFINE_TYPE(copy_assignable , YES , , , , , YES , YES , ); +DEFINE_TYPE(move_assignable , YES , , , , , , YES , ); +DEFINE_TYPE(equality_comparable , YES , , , , , , , ); +DEFINE_TYPE(less_comparable , YES , , , , , , , ); + +DEFINE_TYPE(ca_ci , YES , , YES , YES , , YES , YES , ); +DEFINE_TYPE(ci_ma , YES , , YES , YES , , , YES , ); +DEFINE_TYPE(dc_mi , YES , YES , , YES , , , , ); +DEFINE_TYPE(ec_ma_mi , YES , , , YES , YES , , YES , ); +DEFINE_TYPE(ec_mi , YES , , , YES , YES , , , ); +DEFINE_TYPE(ma_mi , YES , , , YES , , , YES , ); +DEFINE_TYPE(ec_ea , YES , , , , YES , , , YES ); +DEFINE_TYPE(ec_ea_mi , YES , , , YES , YES , , , YES ); #undef YES diff --git a/tests/std/tests/P0088R3_variant/test.cpp b/tests/std/tests/P0088R3_variant/test.cpp index 2cf2dd5210d..2857e561b3a 100644 --- a/tests/std/tests/P0088R3_variant/test.cpp +++ b/tests/std/tests/P0088R3_variant/test.cpp @@ -1771,8 +1771,10 @@ int run_test() #if 0 // TRANSITION, P0608 static_assert(std::is_assignable, int>::value == VariantAllowsNarrowingConversions, ""); - static_assert(std::is_assignable, int>::value == VariantAllowsNarrowingConversions, ""); - static_assert(std::is_assignable, int>::value == VariantAllowsNarrowingConversions, ""); + static_assert(std::is_assignable, int>::value + == VariantAllowsNarrowingConversions, ""); + static_assert(std::is_assignable, int>::value + == VariantAllowsNarrowingConversions, ""); static_assert(!std::is_assignable, int>::value, ""); static_assert(!std::is_assignable, decltype("meow")>::value, ""); @@ -3267,8 +3269,10 @@ int run_test() #if 0 // TRANSITION, P0608 static_assert(std::is_constructible, int>::value == VariantAllowsNarrowingConversions, ""); - static_assert(std::is_constructible, int>::value == VariantAllowsNarrowingConversions, ""); - static_assert(std::is_constructible, int>::value == VariantAllowsNarrowingConversions, ""); + static_assert(std::is_constructible, int>::value + == VariantAllowsNarrowingConversions, ""); + static_assert(std::is_constructible, int>::value + == VariantAllowsNarrowingConversions, ""); static_assert(!std::is_constructible, int>::value, ""); static_assert(!std::is_constructible, decltype("meow")>::value, ""); diff --git a/tests/std/tests/VSO_0191296_allocator_construct/test.cpp b/tests/std/tests/VSO_0191296_allocator_construct/test.cpp index 2d368f26821..365347b36c7 100644 --- a/tests/std/tests/VSO_0191296_allocator_construct/test.cpp +++ b/tests/std/tests/VSO_0191296_allocator_construct/test.cpp @@ -217,44 +217,45 @@ struct emplace_argument { // clang-format off -#define DEFINE_TYPE(name, default_ctor, copy_ctor, move_ctor, emplace_ctor, swappable, copy_assign, move_assign, emplace_assign) \ - class name { \ - public: name(key) { } \ - public: ~name() { } \ - private: default_ctor name(alloc_key) { } \ - private: copy_ctor name(alloc_key, name const&) { } \ - private: move_ctor name(alloc_key, name&&) { } \ - private: emplace_ctor name(alloc_key, emplace_argument&&) { } \ - private: emplace_ctor name(alloc_key, emplace_argument&&, emplace_argument&&) { } \ - private: emplace_ctor name(alloc_key, emplace_argument&&, emplace_argument&&, emplace_argument&&) { } \ - private: swappable friend void swap(name&, name&) {} \ - private: copy_assign name& operator=(name const&) { return *this; } \ - private: move_assign name& operator=(name&&) { return *this; } \ - private: emplace_assign name& operator=(emplace_argument&&) { return *this; } \ - private: name() {} \ - private: name(const name&) {} \ +#define DEFINE_TYPE(name, def_ctor, copy_ctor, move_ctor, emp_ctor, swappable, copy_assign, move_assign, emp_assign) \ + class name { \ + public: name(key) { } \ + public: ~name() { } \ + private: def_ctor name(alloc_key) { } \ + private: copy_ctor name(alloc_key, name const&) { } \ + private: move_ctor name(alloc_key, name&&) { } \ + private: emp_ctor name(alloc_key, emp_argument&&) { } \ + private: emp_ctor name(alloc_key, emp_argument&&, emp_argument&&) { } \ + private: emp_ctor name(alloc_key, emp_argument&&, emp_argument&&, emp_argument&&) { } \ + private: swappable friend void swap(name&, name&) {} \ + private: copy_assign name& operator=(name const&) { return *this; } \ + private: move_assign name& operator=(name&&) { return *this; } \ + private: emp_assign name& operator=(emp_argument&&) { return *this; } \ + private: name() {} \ + private: name(const name&) {} \ } #define YES public: -// default ctor copy ctor move ctor emplace ctor swappable copy assign move assign emplace assign -DEFINE_TYPE(erasable , , , , , , , , ); -DEFINE_TYPE(default_constructible, YES , , , , , , , ); -DEFINE_TYPE(copy_insertable , , YES , YES , , , , , ); -DEFINE_TYPE(move_insertable , , , YES , , , , , ); -DEFINE_TYPE(emplace_constructible, , , , YES , , , , ); -DEFINE_TYPE(copy_assignable , , , , , YES , YES , YES , ); -DEFINE_TYPE(move_assignable , , , , , YES , , YES , ); -DEFINE_TYPE(equality_comparable , , , , , , , , ); -DEFINE_TYPE(less_comparable , , , , , , , , ); -DEFINE_TYPE(ca_ci , , YES , YES , , YES , YES , YES , ); -DEFINE_TYPE(ci_ma , , YES , YES , , YES , , YES , ); -DEFINE_TYPE(dc_mi , YES , , YES , , , , , ); -DEFINE_TYPE(ec_ma_mi , , , YES , YES , YES , , YES , ); -DEFINE_TYPE(ec_mi , , , YES , YES , , , , ); -DEFINE_TYPE(ma_mi , , , YES , , YES , , YES , ); -DEFINE_TYPE(ec_ea , , , , YES , , , , YES ); -DEFINE_TYPE(ec_ea_mi , , , YES , YES , , , , YES ); +// default copy move emplace copy move emplace +// ctor ctor ctor ctor swappable assign assign assign +DEFINE_TYPE(erasable , , , , , , , , ); +DEFINE_TYPE(default_constructible, YES , , , , , , , ); +DEFINE_TYPE(copy_insertable , , YES , YES , , , , , ); +DEFINE_TYPE(move_insertable , , , YES , , , , , ); +DEFINE_TYPE(emplace_constructible, , , , YES , , , , ); +DEFINE_TYPE(copy_assignable , , , , , YES , YES , YES , ); +DEFINE_TYPE(move_assignable , , , , , YES , , YES , ); +DEFINE_TYPE(equality_comparable , , , , , , , , ); +DEFINE_TYPE(less_comparable , , , , , , , , ); +DEFINE_TYPE(ca_ci , , YES , YES , , YES , YES , YES , ); +DEFINE_TYPE(ci_ma , , YES , YES , , YES , , YES , ); +DEFINE_TYPE(dc_mi , YES , , YES , , , , , ); +DEFINE_TYPE(ec_ma_mi , , , YES , YES , YES , , YES , ); +DEFINE_TYPE(ec_mi , , , YES , YES , , , , ); +DEFINE_TYPE(ma_mi , , , YES , , YES , , YES , ); +DEFINE_TYPE(ec_ea , , , , YES , , , , YES ); +DEFINE_TYPE(ec_ea_mi , , , YES , YES , , , , YES ); #undef YES @@ -1429,8 +1430,9 @@ DEFINE_TEST(test_specific_unordered_associative_constructors, copy_constructible_hash const hf((key())); copy_constructible_compare const eq((key())); - (container_type(0, hf, eq, construct_applying_allocator::type>())); - container_type a(0, hf, eq, construct_applying_allocator::type>()); + using T = typename Traits::template bind_value::type + (container_type(0, hf, eq, construct_applying_allocator())); + container_type a(0, hf, eq, construct_applying_allocator()); } // X(i, j, n, hf, eq, allocator) diff --git a/tools/validate/validate.cpp b/tools/validate/validate.cpp index 02e1e236311..4e640fc8c3f 100644 --- a/tools/validate/validate.cpp +++ b/tools/validate/validate.cpp @@ -14,6 +14,8 @@ #include using namespace std; +constexpr size_t max_line_length = 120; + class BinaryFile { public: explicit BinaryFile(const filesystem::path& filepath) { @@ -61,6 +63,7 @@ void scan_file(const filesystem::path& filepath, const TabPolicy tab_policy, vec bool has_crlf = false; bool has_utf8_bom = false; + size_t overlength_lines = 0; size_t disallowed_characters = 0; size_t tab_characters = 0; size_t trailing_whitespace_lines = 0; @@ -69,6 +72,8 @@ void scan_file(const filesystem::path& filepath, const TabPolicy tab_policy, vec unsigned char previous2 = '@'; unsigned char previous3 = '@'; + size_t columns = 0; + for (BinaryFile binary_file{filepath}; binary_file.read_next_block(buffer);) { for (const auto& ch : buffer) { if (prev == CR) { @@ -100,10 +105,17 @@ void scan_file(const filesystem::path& filepath, const TabPolicy tab_policy, vec } } - if ((prev == ' ' || prev == '\t') && (ch == CR || ch == LF)) { - ++trailing_whitespace_lines; - } + if (ch == CR || ch == LF) { + if (prev == ' ' || prev == '\t') { + ++trailing_whitespace_lines; + } + if (columns > max_line_length) { + ++overlength_lines; + } + columns = ~size_t{0}; + } + ++columns; previous3 = exchange(previous2, exchange(prev, ch)); } } @@ -149,6 +161,23 @@ void scan_file(const filesystem::path& filepath, const TabPolicy tab_policy, vec fwprintf(stderr, L"Validation failed: %ls contains %zu lines with trailing whitespace.\n", filepath.c_str(), trailing_whitespace_lines); } + + if (overlength_lines != 0) { + static constexpr array checked_extensions{ + // line length should be capped in files with these extensions: + L""sv, + L".cpp"sv, + L".h"sv, + L".hpp"sv, + L".yml"sv, + }; + static_assert(is_sorted(checked_extensions.begin(), checked_extensions.end())); + + if (binary_search(checked_extensions.begin(), checked_extensions.end(), filepath.extension().wstring())) { + fwprintf(stderr, L"Validation failed: %ls contains %zu lines with more than %zu columns.\n", + filepath.c_str(), overlength_lines, max_line_length); + } + } } int main() { From f860de76e4e42ee5b30194a4e0e2767cfc88885a Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 20 Aug 2020 18:18:21 -0700 Subject: [PATCH 2/4] Apply suggestions from code review --- tests/std/tests/VSO_0191296_allocator_construct/test.cpp | 2 +- tools/validate/validate.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/std/tests/VSO_0191296_allocator_construct/test.cpp b/tests/std/tests/VSO_0191296_allocator_construct/test.cpp index 365347b36c7..bfb52174251 100644 --- a/tests/std/tests/VSO_0191296_allocator_construct/test.cpp +++ b/tests/std/tests/VSO_0191296_allocator_construct/test.cpp @@ -1430,7 +1430,7 @@ DEFINE_TEST(test_specific_unordered_associative_constructors, copy_constructible_hash const hf((key())); copy_constructible_compare const eq((key())); - using T = typename Traits::template bind_value::type + using T = typename Traits::template bind_value::type; (container_type(0, hf, eq, construct_applying_allocator())); container_type a(0, hf, eq, construct_applying_allocator()); } diff --git a/tools/validate/validate.cpp b/tools/validate/validate.cpp index 4e640fc8c3f..78f8a26b598 100644 --- a/tools/validate/validate.cpp +++ b/tools/validate/validate.cpp @@ -113,9 +113,10 @@ void scan_file(const filesystem::path& filepath, const TabPolicy tab_policy, vec if (columns > max_line_length) { ++overlength_lines; } - columns = ~size_t{0}; + columns = 0; + } else { + ++columns; } - ++columns; previous3 = exchange(previous2, exchange(prev, ch)); } } From 98f18cd366cdceb83f24d8724bad2c18533d232a Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Thu, 20 Aug 2020 20:21:37 -0700 Subject: [PATCH 3/4] restore the name `emplace_argument` --- .../tests/Dev11_0437519_container_requirements/test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/std/tests/Dev11_0437519_container_requirements/test.cpp b/tests/std/tests/Dev11_0437519_container_requirements/test.cpp index 2a5eff8a9bd..1ce8819796f 100644 --- a/tests/std/tests/Dev11_0437519_container_requirements/test.cpp +++ b/tests/std/tests/Dev11_0437519_container_requirements/test.cpp @@ -336,12 +336,12 @@ struct emplace_argument { private: def_ctor name() { } \ private: copy_ctor name(name const&) { } \ private: move_ctor name(name&&) { } \ - private: emp_ctor name(emp_argument&&) { } \ - private: emp_ctor name(emp_argument&&, emp_argument&&) { } \ - private: emp_ctor name(emp_argument&&, emp_argument&&, emp_argument&&) { } \ + private: emp_ctor name(emplace_argument&&) { } \ + private: emp_ctor name(emplace_argument&&, emplace_argument&&) { } \ + private: emp_ctor name(emplace_argument&&, emplace_argument&&, emplace_argument&&) { } \ private: copy_assign name& operator=(name const&) { return *this; } \ private: move_assign name& operator=(name&&) noexcept { return *this; } \ - private: emp_assign name& operator=(emp_argument&&) { return *this; } \ + private: emp_assign name& operator=(emplace_argument&&) { return *this; } \ } #define YES public: From bd3c176fc196e3419518a426ff0ee5469d7549d5 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Thu, 20 Aug 2020 20:38:41 -0700 Subject: [PATCH 4/4] Globally replace `emp_argument` with `emplace_argument` --- tests/std/tests/VSO_0191296_allocator_construct/test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/std/tests/VSO_0191296_allocator_construct/test.cpp b/tests/std/tests/VSO_0191296_allocator_construct/test.cpp index bfb52174251..1d312ad3bb4 100644 --- a/tests/std/tests/VSO_0191296_allocator_construct/test.cpp +++ b/tests/std/tests/VSO_0191296_allocator_construct/test.cpp @@ -224,13 +224,13 @@ struct emplace_argument { private: def_ctor name(alloc_key) { } \ private: copy_ctor name(alloc_key, name const&) { } \ private: move_ctor name(alloc_key, name&&) { } \ - private: emp_ctor name(alloc_key, emp_argument&&) { } \ - private: emp_ctor name(alloc_key, emp_argument&&, emp_argument&&) { } \ - private: emp_ctor name(alloc_key, emp_argument&&, emp_argument&&, emp_argument&&) { } \ + private: emp_ctor name(alloc_key, emplace_argument&&) { } \ + private: emp_ctor name(alloc_key, emplace_argument&&, emplace_argument&&) { } \ + private: emp_ctor name(alloc_key, emplace_argument&&, emplace_argument&&, emplace_argument&&) { } \ private: swappable friend void swap(name&, name&) {} \ private: copy_assign name& operator=(name const&) { return *this; } \ private: move_assign name& operator=(name&&) { return *this; } \ - private: emp_assign name& operator=(emp_argument&&) { return *this; } \ + private: emp_assign name& operator=(emplace_argument&&) { return *this; } \ private: name() {} \ private: name(const name&) {} \ }