diff --git a/.vscode/settings.json b/.vscode/settings.json index 57bf6c7..2d90911 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,7 +4,9 @@ "-I${workspaceRoot}/include" ], "clang.cxxflags": [ - "-std=c++17", + "-std=c++20", + "-Wall", + "-pedantic", "-I${workspaceRoot}/include" ] } \ No newline at end of file diff --git a/Makefile b/Makefile index 0e44a1b..ee5a1af 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ -CXX= clang++-10 -CXXFLAGS= --std=c++17 -O0 -pthread -DGP_TESTS -DFUZZ_STRENGTH=500 -DNO_BENCH=0 -pedantic -Werror \ - -Wno-unknown-attributes -frtti \ - -g -fprofile-instr-generate -fcoverage-mapping \ +CXX= g++ +CXXFLAGS= --std=c++20 -O0 -g -pthread -DGP_TESTS -DFUZZ_STRENGTH=500 -DNO_BENCH=0 -pedantic \ + -frtti \ + + #-g -fprofile-instr-generate -fcoverage-mapping -Wno-unknown-attributes \ -fsanitize=address -fno-omit-frame-pointer all: tests diff --git a/include/gp/allocator/aggregator.hpp b/include/gp/allocator/aggregator.hpp index dd661d4..3398046 100644 --- a/include/gp/allocator/aggregator.hpp +++ b/include/gp/allocator/aggregator.hpp @@ -35,7 +35,7 @@ namespace gp { return internal_representation.try_reallocate(ptr, sz); } }; - using local_container = ring_list; + using local_container = ring_list; local_container contents; local_container::explorer mark; @@ -99,6 +99,4 @@ namespace gp { return false; } }; - - } \ No newline at end of file diff --git a/include/gp/allocator/buddy.hpp b/include/gp/allocator/buddy.hpp index 8726bc4..67c83a1 100644 --- a/include/gp/allocator/buddy.hpp +++ b/include/gp/allocator/buddy.hpp @@ -52,6 +52,8 @@ namespace gp{ **/ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wreturn-type" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wreturn-type" twig get_twig(size_t idx) const { auto far = idx / 4; auto local = idx % 4; @@ -66,6 +68,7 @@ namespace gp{ return stack[far].d; } } +#pragma GCC diagnostic pop #pragma clang diagnostic pop void set_twig(size_t idx, twig v) { @@ -288,7 +291,6 @@ namespace gp{ auto r = get_twig(get_right(idx)); set_twig(idx, 2*(l.used | l.used_children | r.used | r.used_children)); - }); return true; diff --git a/include/gp/array.hpp b/include/gp/array.hpp index 68e84ba..25b6459 100644 --- a/include/gp/array.hpp +++ b/include/gp/array.hpp @@ -39,19 +39,17 @@ namespace gp{ ); } - template<> - array(T (& oth)[sz]) { + array(T (& oth)[sz]) { gp::move_uninitialized( - gp::nameless_range(oth, oth+sz), - gp::nameless_range(begin(), end()) + gp::nameless_range(oth, oth+sz), + gp::nameless_range(begin(), end()) ); } - template<> - array(T (&& oth)[sz]) { + array(T (&& oth)[sz]) { gp::move_uninitialized( - gp::nameless_range(oth, oth+sz), - gp::nameless_range(begin(), end()) + gp::nameless_range((T*)oth, (T*)oth+sz), + gp::nameless_range(begin(), end()) ); } diff --git a/include/gp/bitops.hpp b/include/gp/bitops.hpp index 142a58c..ca09da6 100644 --- a/include/gp/bitops.hpp +++ b/include/gp/bitops.hpp @@ -8,6 +8,10 @@ namespace gp{ constexpr uint8_t magic_ = (const uint8_t&)uint32_; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wfour-char-constants" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmultichar" enum class endian : uint16_t { #ifdef _WIN32 @@ -21,15 +25,11 @@ namespace gp{ #else little = true, big = false, -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wfour-char-constants" -#pragma gcc diagnostic push -#pragma gcc diagnostic ignored "-Wfour-char-constants" native = ('ABCD'==0x41424344UL) -#pragma gcc diagnostic pop -#pragma clang diagnostic pop -#endif }; +#endif +#pragma GCC diagnostic pop +#pragma clang diagnostic pop template diff --git a/include/gp/concepts.hpp b/include/gp/concepts.hpp new file mode 100644 index 0000000..b62345f --- /dev/null +++ b/include/gp/concepts.hpp @@ -0,0 +1,14 @@ +#pragma once +#include + +template +concept ForwardIteratorLike = requires(T a) { + {++a} -> auto; + {*a} -> auto; +}; + +template +concept RangeLike = requires(T a) { + {a.begin()} -> ForwardIteratorLike; + {a.end()} -> ForwardIteratorLike; +}; \ No newline at end of file diff --git a/include/gp/math/integer_math.hpp b/include/gp/math/integer_math.hpp index 40d3a29..6577d42 100644 --- a/include/gp/math/integer_math.hpp +++ b/include/gp/math/integer_math.hpp @@ -17,8 +17,8 @@ namespace gp { { constexpr int MultiplyDeBruijnBitPosition[32] = { - 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, - 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 + 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, + 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 }; v |= v >> 1; diff --git a/include/gp/optional.hpp b/include/gp/optional.hpp index c8eb4cc..019049a 100644 --- a/include/gp/optional.hpp +++ b/include/gp/optional.hpp @@ -161,6 +161,21 @@ namespace gp{ return *this; } + optional& operator=(optional&& value){ + if(ready) { + delete ptr; // TODO: Use allocators + } + if(value.ready) { + ptr = value.ptr; + value.ready = false; + ready = true; + return *this; + } else { + ready = false; + return *this; + } + } + template optional& operator=(U&& value) { if(ready) { @@ -177,33 +192,6 @@ namespace gp{ return *this; } - template<> - optional& operator=(optional& value) { - if(ready) { - *ptr = value; - } else { - ready = true; - ptr = new optional(value.value()); // TODO: Use allocators - } - return *this; - } - - template<> - optional& operator=(optional&& value){ - if(ready) { - delete ptr; // TODO: Use allocators - } - if(value.ready) { - ptr = value.ptr; - value.ready = false; - ready = true; - return *this; - } else { - ready = false; - return *this; - } - } - operator T&() { gp_config::assertion(ready, "bad optional access"); return *ptr; diff --git a/include/gp/pair.hpp b/include/gp/pair.hpp index 397cabb..91caa31 100644 --- a/include/gp/pair.hpp +++ b/include/gp/pair.hpp @@ -34,39 +34,45 @@ namespace gp{ second = gp::move(v.second); return *this; } + }; - bool operator==(const pair& rhs) { - return first == rhs.first and second == rhs.second; - } + template + bool operator==(const pair& lhs, const pair& rhs) { + return lhs.first == rhs.first and lhs.second == rhs.second; + } - bool operator!=(const pair& rhs) { - return first != rhs.first or second != rhs.second; - } + template + bool operator!=(const pair& lhs, const pair& rhs) { + return lhs.first != rhs.first or lhs.second != rhs.second; + } - bool operator<=(const pair& rhs) { - if(first > rhs.first) { - return false; - } else if(first == rhs.first) { - return second <= rhs.second; - } - return true; + template + bool operator<=(const pair& lhs, const pair& rhs) { + if(lhs.first > rhs.first) { + return false; + } else if(lhs.first == rhs.first) { + return lhs.second <= rhs.second; } + return true; + } - bool operator>=(const pair& rhs) { - if(first < rhs.first) { - return false; - } else if(first == rhs.first) { - return second >= rhs.second; - } - return true; + template + bool operator>=(const pair& lhs, const pair& rhs) { + if(lhs.first < rhs.first) { + return false; + } else if(lhs.first == rhs.first) { + return lhs.second >= rhs.second; } + return true; + } - bool operator<(const pair& rhs) { - return !(*this >= rhs); - } + template + bool operator<(const pair& lhs, const pair& rhs) { + return !(lhs >= rhs); + } - bool operator>(const pair& rhs) { - return !(*this <= rhs); - } - }; + template + bool operator>(const pair& lhs, const pair& rhs) { + return !(lhs <= rhs); + } } \ No newline at end of file diff --git a/include/gp/range.hpp b/include/gp/range.hpp index e35d25b..a2e4df6 100644 --- a/include/gp/range.hpp +++ b/include/gp/range.hpp @@ -2,7 +2,13 @@ #include "gp/algorithm/tmp_manip.hpp" namespace gp{ - template::value> + template + concept IsSubstractible = requires(T a, T b) + { + {a - b} -> std::integral; + }; + + template> class nameless_range; template diff --git a/include/gp/ring_list.hpp b/include/gp/ring_list.hpp index ae885ec..2a60551 100644 --- a/include/gp/ring_list.hpp +++ b/include/gp/ring_list.hpp @@ -5,7 +5,7 @@ #include "gp_config.hpp" namespace gp { - template + template class ring_list{ public: class explorer; @@ -20,8 +20,8 @@ namespace gp { , next{this} {} - friend class gp::ring_list::explorer; - friend class gp::ring_list; + friend class gp::ring_list::explorer; + friend class gp::ring_list; }; class explorer { @@ -149,9 +149,13 @@ namespace gp { gp_config::assertion(used_allocator.deallocate(v), "Bad free of node"); } - ~ring_list() { - while(any_node) { - remove(explore()); + ~ring_list() + { + // TODO: Find a less hackish way to resove this issue + if constexpr (!may_contain_self) { + while(any_node) { + remove(explore()); + } } } }; diff --git a/tests.cpp b/tests.cpp index c2af2e3..9b9cfb8 100644 --- a/tests.cpp +++ b/tests.cpp @@ -9,6 +9,8 @@ #include "pair_test.cpp" #include +#include "gp/concepts.hpp" + alignas(2048) gp::array static_mapper::store; gp::buddy<> static_mapper::impl = gp::buddy<>{store.begin().data, store.size()};