diff --git a/.clang-format b/.clang-format index 194cddeb..d975f596 100644 --- a/.clang-format +++ b/.clang-format @@ -2,7 +2,13 @@ Language: Cpp # BasedOnStyle: LLVM AccessModifierOffset: -2 -AlignAfterOpenBracket: AlwaysBreak +AlignAfterOpenBracket: false +BreakAfterOpenBracketBracedList: true +BreakBeforeCloseBracketBracedList: true +BreakAfterOpenBracketFunction: true +BreakAfterOpenBracketIf: true +BreakAfterOpenBracketLoop: true +BreakAfterOpenBracketSwitch: true AlignConsecutiveMacros: false AlignConsecutiveAssignments: false AlignConsecutiveDeclarations: false @@ -87,6 +93,13 @@ IndentWrappedFunctionNames: false JavaScriptQuotes: Leave JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: true +Macros: + - 'BOOST_OPENMETHOD(ID, PARAMETERS, RETURN_TYPE)=ID PARAMETERS' + - 'BOOST_OPENMETHOD_OVERRIDE(ID, PARAMETERS, RETURN_TYPE)=ID PARAMETERS' + - 'BOOST_OPENMETHOD_INLINE_OVERRIDE(ID, PARAMETERS, RETURN_TYPE)=ID PARAMETERS' + - 'BOOST_OPENMETHOD_DECLARE_OVERRIDER(ID, PARAMETERS, RETURN_TYPE)=ID PARAMETERS' + - 'BOOST_OPENMETHOD_DEFINE_OVERRIDER(ID, PARAMETERS, RETURN_TYPE)=ID PARAMETERS' + - 'BOOST_OPENMETHOD_TYPE(ID, PARAMETERS, RETURN_TYPE)=ID PARAMETERS' MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 diff --git a/CLAUDE.md b/CLAUDE.md index 64a8d345..ea80ae0c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -204,10 +204,72 @@ tables before first use. ## Code Conventions ### Formatting -The project uses clang-format with an LLVM-based style: -- `AlignAfterOpenBracket: AlwaysBreak` + +The project uses clang-format with an LLVM-based style, **pinned to clang-format 22**: +`dev/reformat` calls `clang-format-22` explicitly, because 18 and 19 reject +`BreakAfterOpenBracketFunction` with `unknown key` and refuse to run at all. + +- `AlignAfterOpenBracket: false`, plus `BreakAfterOpenBracket{Function,If,Loop,Switch}` and the + braced-list pair `BreakAfterOpenBracketBracedList` / `BreakBeforeCloseBracketBracedList`. + Continuations indent by 4; they are *not* aligned under the open paren. The pre-22 spelling was + `AlignAfterOpenBracket: AlwaysBreak`, a misnomer - v22 maps that to `true`, which aligns. No + `PenaltyBreak*` value and no `BlockIndent` achieves the 4-space indent; both were probed and + ruled out. - `AllowShortFunctionsOnASingleLine: false` - No short blocks, if statements, or loops on single lines +- `Macros:` teaches clang-format to expand `BOOST_OPENMETHOD`, `BOOST_OPENMETHOD_OVERRIDE` and + their kin to `ID PARAMETERS`. Without it the parameter list is parsed as an *expression*, where + `&` is a binary operator, and the first parameter comes out as `Cat & a1`. The expansion + deliberately omits the return type: with one in it, clang-format breaks after the return type + and indents the method name by 8. `BOOST_OPENMETHOD_OVERRIDER` is deliberately **absent** - it + appears in expression position (`...)::fn(args)`), where the expansion never applies and only + wrecks the wrapping of the sites that do match. + +**A blank line precedes a `return`**, unless the `return` opens its block - the whole body of a +function or lambda, the body of an `if`, a `case`. Where a comment is attached to the `return`, +the blank line goes above the comment, not between them. clang-format has no option for this, so +it is maintained by hand; `dev/reformat` will neither add nor remove these lines. + +**Indentation lands on a multiple of 4.** clang-format measures a continuation from the column of +the enclosing bracket's *content*, not from the line's own indent, so a doubly-nested `((` yields +13/14/17 and no setting moves it - `AlignAfterOpenBracket` and `AlignOperands` were probed in +every combination. The fix is to remove a nesting level from the source (hoist the predicate into +its own trait), never to hunt for an option. + +Three shapes clang-format cannot be configured into, so do not go looking: + +- **A ternary breaks before `?` only when aligning `:` under the `?` would overflow.** It is + fit-driven, so "break both operands unless the whole thing fits on one line" is not expressible. +- **Macro arguments in expression position keep the binary-operator spacing.** A hand fix to + `BOOST_OPENMETHOD_OVERRIDER(poke, (std::ostream & os, ...), void)::fn(...)` is undone by the + next run; only `// clang-format off` holds. +- **Files carrying `// clang-format off`** (most of `doc/modules/ROOT/examples/`) are hand-formatted + for the rendered docs. Edit those by hand; a reformat will not touch them. + +### `using namespace detail` vs `detail::` + +A function body that names `detail::` more than once opens with `using namespace detail;` and +drops the qualification. A blank line follows the opening run of `using` declarations. The +directive covers the body only - the signature stays qualified: + +```cpp +static void save(detail::tuple& to) { + using namespace detail; + + (..., (get(to) = get(Registry::state().policies))); +} +``` + +A single use does not earn a directive: the `using` line costs a line, so it pays only where it +unwraps two or more. Measured across the tree, no single-use body qualified. + +Two things a mechanical strip gets wrong - both were hit while doing this: + +- **A using-*declaration* is not a use.** In `using detail::generic_compiler;` the qualification + *is* the declaration; strip it and `using generic_compiler;` does not compile. Under a directive + the declaration is redundant anyway, so delete the line instead of requalifying it. +- **`BOOST_OPENMETHOD_UNLESS_MRDOCS(detail::)` is not a qualification.** It hides one from MrDocs + (see *Reference (MrDocs) constraints*) and must be left alone. ### Disassembly Always show disassembly in **Intel syntax**, never AT&T (the toolchain's default diff --git a/ce/2-method-vptr-final.cpp b/ce/2-method-vptr-final.cpp index 0adac71f..bb42c61b 100644 --- a/ce/2-method-vptr-final.cpp +++ b/ce/2-method-vptr-final.cpp @@ -62,7 +62,8 @@ auto main() -> int { Cat felix{"Felix"}, sylvester{"Sylvester"}; std::vector> animals = { virtual_ptr::final(hector), virtual_ptr::final(felix), - virtual_ptr::final(sylvester), virtual_ptr::final(snoopy)}; + virtual_ptr::final(sylvester), virtual_ptr::final(snoopy) + }; meet_animals(animals, std::cout); } diff --git a/ce/2-method-vptr.cpp b/ce/2-method-vptr.cpp index 2bfc279b..6ba06036 100644 --- a/ce/2-method-vptr.cpp +++ b/ce/2-method-vptr.cpp @@ -63,7 +63,8 @@ auto main() -> int { Dog hector{"Hector"}, snoopy{"Snoopy"}; Cat felix{"Felix"}, sylvester{"Sylvester"}; std::vector> animals = { - hector, felix, sylvester, snoopy}; + hector, felix, sylvester, snoopy + }; meet_animals(animals, std::cout); } diff --git a/ce/2-method.cpp b/ce/2-method.cpp index 59f9d2cb..23e91d22 100644 --- a/ce/2-method.cpp +++ b/ce/2-method.cpp @@ -26,19 +26,19 @@ using boost::openmethod::virtual_; BOOST_OPENMETHOD( meet, (virtual_, virtual_, std::ostream&), void); -BOOST_OPENMETHOD_OVERRIDE(meet, (Cat & a1, Cat& a2, std::ostream& os), void) { +BOOST_OPENMETHOD_OVERRIDE(meet, (Cat& a1, Cat& a2, std::ostream& os), void) { os << a1.name << " ignores " << a2.name << "\n"; } -BOOST_OPENMETHOD_OVERRIDE(meet, (Dog & a1, Cat& a2, std::ostream& os), void) { +BOOST_OPENMETHOD_OVERRIDE(meet, (Dog& a1, Cat& a2, std::ostream& os), void) { os << a1.name << " chases " << a2.name << "\n"; } -BOOST_OPENMETHOD_OVERRIDE(meet, (Cat & a1, Dog& a2, std::ostream& os), void) { +BOOST_OPENMETHOD_OVERRIDE(meet, (Cat& a1, Dog& a2, std::ostream& os), void) { os << a1.name << " runs away from " << a2.name << "\n"; } -BOOST_OPENMETHOD_OVERRIDE(meet, (Dog & a1, Dog& a2, std::ostream& os), void) { +BOOST_OPENMETHOD_OVERRIDE(meet, (Dog& a1, Dog& a2, std::ostream& os), void) { os << a1.name << " wags tail at " << a2.name << "\n"; } diff --git a/ce/uni-method-vptr-final.cpp b/ce/uni-method-vptr-final.cpp index 54496821..72246838 100644 --- a/ce/uni-method-vptr-final.cpp +++ b/ce/uni-method-vptr-final.cpp @@ -49,7 +49,8 @@ auto main() -> int { Cat felix{"Felix"}, sylvester{"Sylvester"}; std::vector> animals = { final_virtual_ptr(hector), virtual_ptr::final(felix), - final_virtual_ptr(sylvester), virtual_ptr::final(snoopy)}; + final_virtual_ptr(sylvester), virtual_ptr::final(snoopy) + }; poke_animals(animals, std::cout); } diff --git a/ce/uni-method-vptr.cpp b/ce/uni-method-vptr.cpp index e28658e4..62914acf 100644 --- a/ce/uni-method-vptr.cpp +++ b/ce/uni-method-vptr.cpp @@ -48,7 +48,8 @@ auto main() -> int { Dog hector{"Hector"}, snoopy{"Snoopy"}; Cat felix{"Felix"}, sylvester{"Sylvester"}; std::vector> animals = { - hector, felix, sylvester, snoopy}; + hector, felix, sylvester, snoopy + }; poke_animals(animals, std::cout); } diff --git a/ce/uni-method.cpp b/ce/uni-method.cpp index c4e24738..fd4bcd0a 100644 --- a/ce/uni-method.cpp +++ b/ce/uni-method.cpp @@ -25,11 +25,11 @@ using boost::openmethod::virtual_; BOOST_OPENMETHOD(poke, (virtual_, std::ostream&), void); -BOOST_OPENMETHOD_OVERRIDE(poke, (Cat & animal, std::ostream& os), void) { +BOOST_OPENMETHOD_OVERRIDE(poke, (Cat& animal, std::ostream& os), void) { os << animal.name << " hisses.\n"; } -BOOST_OPENMETHOD_OVERRIDE(poke, (Dog & animal, std::ostream& os), void) { +BOOST_OPENMETHOD_OVERRIDE(poke, (Dog& animal, std::ostream& os), void) { os << animal.name << " barks.\n"; } diff --git a/dev/reformat b/dev/reformat index 0910d91f..746b979e 100755 --- a/dev/reformat +++ b/dev/reformat @@ -1,8 +1,11 @@ #!/bin/bash +# Format every C++ source in the repository. Pinned to clang-format 22: the +# house style needs BreakAfterOpenBracket*, which 18 and 19 reject outright. + cd "$(dirname $0)/.." -srcs=$(find include examples test \ - -name '*.?pp' | grep -v cmake_fetchcontent | grep -v /CMakeFiles) +srcs=$(git ls-files --cached --others --exclude-standard \ + '*.hpp' '*.cpp' '*.ipp') -clang-format -i --verbose $srcs +clang-format-22 -i --verbose $srcs diff --git a/doc/modules/ROOT/examples/default_error_handler.cpp b/doc/modules/ROOT/examples/default_error_handler.cpp index ad5a95bc..a7952b61 100644 --- a/doc/modules/ROOT/examples/default_error_handler.cpp +++ b/doc/modules/ROOT/examples/default_error_handler.cpp @@ -24,7 +24,7 @@ BOOST_OPENMETHOD_CLASSES(Animal, Cat, Dog); BOOST_OPENMETHOD(trick, (std::ostream&, virtual_ptr), void); BOOST_OPENMETHOD_OVERRIDE( - trick, (std::ostream & os, virtual_ptr /*dog*/), void) { + trick, (std::ostream& os, virtual_ptr /*dog*/), void) { os << "spin\n"; } diff --git a/doc/modules/ROOT/examples/headers_namespaces/cat.cpp b/doc/modules/ROOT/examples/headers_namespaces/cat.cpp index b1a2b950..ae1d6d92 100644 --- a/doc/modules/ROOT/examples/headers_namespaces/cat.cpp +++ b/doc/modules/ROOT/examples/headers_namespaces/cat.cpp @@ -12,12 +12,12 @@ namespace felines { BOOST_OPENMETHOD_CLASSES(animals::Animal, Cat, Cheetah); BOOST_OPENMETHOD_OVERRIDE( - poke, (std::ostream & os, virtual_ptr cat), void) { + poke, (std::ostream& os, virtual_ptr cat), void) { os << cat->name << " hisses"; } BOOST_OPENMETHOD_OVERRIDE( - poke, (std::ostream & os, virtual_ptr cat), void) { + poke, (std::ostream& os, virtual_ptr cat), void) { BOOST_OPENMETHOD_OVERRIDER( poke, (std::ostream & os, virtual_ptr dog), void)::fn(os, cat); os << " and runs away"; diff --git a/doc/modules/ROOT/examples/headers_namespaces/dog.cpp b/doc/modules/ROOT/examples/headers_namespaces/dog.cpp index 44a7435e..64b32fdc 100644 --- a/doc/modules/ROOT/examples/headers_namespaces/dog.cpp +++ b/doc/modules/ROOT/examples/headers_namespaces/dog.cpp @@ -8,7 +8,7 @@ namespace canines { BOOST_OPENMETHOD_CLASSES(animals::Animal, Dog); BOOST_OPENMETHOD_DEFINE_OVERRIDER( - poke, (std::ostream & os, boost::openmethod::virtual_ptr dog), void) { + poke, (std::ostream& os, boost::openmethod::virtual_ptr dog), void) { os << dog->name << " barks"; } diff --git a/doc/modules/ROOT/examples/headers_namespaces/dog.hpp b/doc/modules/ROOT/examples/headers_namespaces/dog.hpp index 604ee820..e078ef1b 100644 --- a/doc/modules/ROOT/examples/headers_namespaces/dog.hpp +++ b/doc/modules/ROOT/examples/headers_namespaces/dog.hpp @@ -13,7 +13,7 @@ struct Dog : animals::Animal { }; BOOST_OPENMETHOD_DECLARE_OVERRIDER( - poke, (std::ostream & os, boost::openmethod::virtual_ptr dog), void); + poke, (std::ostream& os, boost::openmethod::virtual_ptr dog), void); } // namespace canines diff --git a/doc/modules/ROOT/examples/headers_namespaces/main.cpp b/doc/modules/ROOT/examples/headers_namespaces/main.cpp index 4a088983..ceb1b08f 100644 --- a/doc/modules/ROOT/examples/headers_namespaces/main.cpp +++ b/doc/modules/ROOT/examples/headers_namespaces/main.cpp @@ -15,7 +15,7 @@ struct Bulldog : canines::Dog { BOOST_OPENMETHOD_CLASSES(canines::Dog, Bulldog); BOOST_OPENMETHOD_OVERRIDE( - poke, (std::ostream & os, virtual_ptr dog), void) { + poke, (std::ostream& os, virtual_ptr dog), void) { canines::BOOST_OPENMETHOD_OVERRIDER( poke, (std::ostream & os, virtual_ptr dog), void)::fn(os, dog); diff --git a/doc/modules/ROOT/examples/headers_namespaces/main_unrelated_namespaces.cpp b/doc/modules/ROOT/examples/headers_namespaces/main_unrelated_namespaces.cpp index 4245a0ca..442e5be7 100644 --- a/doc/modules/ROOT/examples/headers_namespaces/main_unrelated_namespaces.cpp +++ b/doc/modules/ROOT/examples/headers_namespaces/main_unrelated_namespaces.cpp @@ -18,6 +18,6 @@ BOOST_OPENMETHOD( using app_specific_behavior::BOOST_OPENMETHOD_GUIDE(meet); BOOST_OPENMETHOD_OVERRIDE( - meet, (std::ostream & os, virtual_ptr, virtual_ptr), void) { + meet, (std::ostream& os, virtual_ptr, virtual_ptr), void) { os << "ignore"; } diff --git a/doc/modules/ROOT/examples/headers_namespaces/main_using_directive.cpp b/doc/modules/ROOT/examples/headers_namespaces/main_using_directive.cpp index 858b1cdd..473784f7 100644 --- a/doc/modules/ROOT/examples/headers_namespaces/main_using_directive.cpp +++ b/doc/modules/ROOT/examples/headers_namespaces/main_using_directive.cpp @@ -17,7 +17,7 @@ struct Bulldog : Dog { BOOST_OPENMETHOD_CLASSES(Dog, Bulldog); BOOST_OPENMETHOD_OVERRIDE( - poke, (std::ostream & os, virtual_ptr dog), void) { + poke, (std::ostream& os, virtual_ptr dog), void) { next(os, dog); os << " and bites back"; } diff --git a/doc/modules/ROOT/examples/rolex/5/main.cpp b/doc/modules/ROOT/examples/rolex/5/main.cpp index c857352b..50d3441d 100644 --- a/doc/modules/ROOT/examples/rolex/5/main.cpp +++ b/doc/modules/ROOT/examples/rolex/5/main.cpp @@ -20,7 +20,7 @@ struct Salesman : Employee { // tag::pay[] BOOST_OPENMETHOD( - pay, (Payroll & payroll, boost::openmethod::virtual_ptr), + pay, (Payroll& payroll, boost::openmethod::virtual_ptr), double); // end::pay[] @@ -52,7 +52,7 @@ class Payroll { // tag::overriders[] BOOST_OPENMETHOD_OVERRIDE( - pay, (Payroll & payroll, boost::openmethod::virtual_ptr), + pay, (Payroll& payroll, boost::openmethod::virtual_ptr), double) { double pay = 5000.0; payroll.update_balance(-pay); @@ -61,8 +61,7 @@ BOOST_OPENMETHOD_OVERRIDE( } BOOST_OPENMETHOD_OVERRIDE( - pay, - (Payroll & payroll, boost::openmethod::virtual_ptr emp), + pay, (Payroll& payroll, boost::openmethod::virtual_ptr emp), double) { double base = next(payroll, emp); double commission = emp->sales * 0.05; diff --git a/doc/modules/ROOT/examples/rolex/6/main.cpp b/doc/modules/ROOT/examples/rolex/6/main.cpp index 043c0aea..337d08ba 100644 --- a/doc/modules/ROOT/examples/rolex/6/main.cpp +++ b/doc/modules/ROOT/examples/rolex/6/main.cpp @@ -20,7 +20,7 @@ struct Salesman : Employee { // tag::pay[] BOOST_OPENMETHOD( - pay, (Payroll & payroll, boost::openmethod::virtual_ptr), + pay, (Payroll& payroll, boost::openmethod::virtual_ptr), double); // end::pay[] @@ -46,7 +46,7 @@ class Payroll { // tag::overriders[] BOOST_OPENMETHOD_OVERRIDE( - pay, (Payroll & payroll, boost::openmethod::virtual_ptr), + pay, (Payroll& payroll, boost::openmethod::virtual_ptr), double) { double pay = 5000.0; payroll.update_balance(-pay); @@ -55,8 +55,7 @@ BOOST_OPENMETHOD_OVERRIDE( } BOOST_OPENMETHOD_OVERRIDE( - pay, - (Payroll & payroll, boost::openmethod::virtual_ptr emp), + pay, (Payroll& payroll, boost::openmethod::virtual_ptr emp), double) { double base = next(payroll, emp); double commission = emp->sales * 0.05; diff --git a/doc/modules/ROOT/examples/throw_error_handler.cpp b/doc/modules/ROOT/examples/throw_error_handler.cpp index 2b94fa94..d8a0a3dc 100644 --- a/doc/modules/ROOT/examples/throw_error_handler.cpp +++ b/doc/modules/ROOT/examples/throw_error_handler.cpp @@ -43,7 +43,7 @@ BOOST_OPENMETHOD_CLASSES(Animal, Cat, Dog); BOOST_OPENMETHOD(trick, (std::ostream&, virtual_ptr), void); BOOST_OPENMETHOD_OVERRIDE( - trick, (std::ostream & os, virtual_ptr /*dog*/), void) { + trick, (std::ostream& os, virtual_ptr /*dog*/), void) { os << "spin\n"; } diff --git a/doc/modules/ROOT/examples/virtual_ptr.cpp b/doc/modules/ROOT/examples/virtual_ptr.cpp index 11ff3076..f81c35ba 100644 --- a/doc/modules/ROOT/examples/virtual_ptr.cpp +++ b/doc/modules/ROOT/examples/virtual_ptr.cpp @@ -22,12 +22,12 @@ BOOST_OPENMETHOD_CLASSES(Animal, Cat, Dog); BOOST_OPENMETHOD(yell, (std::ostream&, virtual_ptr), void); BOOST_OPENMETHOD_OVERRIDE( - yell, (std::ostream & os, virtual_ptr /*cat*/), void) { + yell, (std::ostream& os, virtual_ptr /*cat*/), void) { os << "hiss"; } BOOST_OPENMETHOD_OVERRIDE( - yell, (std::ostream & os, virtual_ptr /*dog*/), void) { + yell, (std::ostream& os, virtual_ptr /*dog*/), void) { os << "bark"; } @@ -36,14 +36,14 @@ BOOST_OPENMETHOD( BOOST_OPENMETHOD_OVERRIDE( encounter, - (std::ostream & os, virtual_ptr dog, virtual_ptr /*cat*/), void) { + (std::ostream& os, virtual_ptr dog, virtual_ptr /*cat*/), void) { yell(os, dog); os << " and chase"; } BOOST_OPENMETHOD_OVERRIDE( encounter, - (std::ostream & os, virtual_ptr cat, virtual_ptr /*dog*/), void) { + (std::ostream& os, virtual_ptr cat, virtual_ptr /*dog*/), void) { yell(os, cat); os << " and run"; } diff --git a/include/boost/openmethod/core.hpp b/include/boost/openmethod/core.hpp index efbfc176..e363db1a 100644 --- a/include/boost/openmethod/core.hpp +++ b/include/boost/openmethod/core.hpp @@ -313,18 +313,21 @@ struct unanimous_registry { // A registry listed explicitly wins, and a class that declares nothing goes // along with it; one that declares another registry does not. -template -struct classes_agree_with { +template +struct class_agrees_with { + using declared = typename registry_affinity_aux::declared; static_assert( - ((std::is_same_v< - typename registry_affinity_aux::declared, void> || - std::is_same_v< - typename registry_affinity_aux::declared, Registry>) && - ...), + std::is_same_v || std::is_same_v, "registry mismatch: a class declares an affinity for another registry"); static constexpr bool value = true; }; +template +struct classes_agree_with { + static constexpr bool value = + (class_agrees_with::value && ...); +}; + template struct pick_class_registry; @@ -355,6 +358,7 @@ template struct init_type_ids> { static auto fn(type_id* ids) { (..., (*ids++ = Registry::rtti::template static_type())); + return ids; } }; @@ -656,6 +660,7 @@ struct virtual_traits { template static auto cast(Class& obj) -> Derived { static_assert(std::is_lvalue_reference_v); + return detail::optimal_cast(obj); } }; @@ -687,6 +692,7 @@ struct virtual_traits { template static auto cast(Class&& obj) -> Derived { static_assert(std::is_rvalue_reference_v); + return detail::optimal_cast(obj); } }; @@ -1018,9 +1024,8 @@ decltype(auto) acquire_vptr(const ArgType& arg) { Registry::require_initialized(); - if constexpr (has_vptr< - virtual_traits, - const ArgType&>) { + if constexpr ( + has_vptr, const ArgType&>) { return virtual_traits::vptr(arg); } else { return Registry::template policy::dynamic_vptr(arg); @@ -1326,7 +1331,7 @@ class virtual_ptr { class Other, typename = std::enable_if_t>, typename = std::enable_if_t>> + IsPolymorphic>> virtual_ptr(Other* other) : vp(detail::box_vptr( detail::acquire_vptr(*other))), @@ -1396,11 +1401,12 @@ class virtual_ptr { class Other, typename = std::enable_if_t>, typename = std::enable_if_t>> + IsPolymorphic>> virtual_ptr& operator=(Other& other) { obj = &other; vp = detail::box_vptr( detail::acquire_vptr(other)); + return *this; } @@ -1433,11 +1439,12 @@ class virtual_ptr { class Other, typename = std::enable_if_t>, typename = std::enable_if_t>> + IsPolymorphic>> virtual_ptr& operator=(Other* other) { obj = other; vp = detail::box_vptr( detail::acquire_vptr(*other)); + return *this; } @@ -1472,6 +1479,7 @@ class virtual_ptr { virtual_ptr& operator=(const virtual_ptr& other) { obj = other.get(); vp = other.vp; + return *this; } @@ -1482,8 +1490,11 @@ class virtual_ptr { //! @par Example //! include:virtual_ptr.cpp#assign_nullptr virtual_ptr& operator=(std::nullptr_t) { + using namespace detail; + obj = nullptr; - vp = detail::box_vptr(detail::null_vptr); + vp = box_vptr(null_vptr); + return *this; } @@ -1567,7 +1578,7 @@ template class virtual_ptr< SmartPtr, Registry, std::enable_if_t>> { + IsSmartPtr>> { #ifndef __MRDOCS__ template @@ -1661,8 +1672,8 @@ class virtual_ptr< BOOST_OPENMETHOD_UNLESS_MRDOCS(detail::) SameSmartPtr && std::is_constructible_v>, - typename = std::enable_if_t>> + typename = std::enable_if_t>> virtual_ptr(const Other& other) : vp(detail::box_vptr( other ? detail::acquire_vptr(*other) @@ -1690,8 +1701,8 @@ class virtual_ptr< BOOST_OPENMETHOD_UNLESS_MRDOCS(detail::) SameSmartPtr && std::is_constructible_v>, - typename = std::enable_if_t>> + typename = std::enable_if_t>> virtual_ptr(Other& other) : vp(detail::box_vptr( other ? detail::acquire_vptr(*other) @@ -1726,8 +1737,8 @@ class virtual_ptr< BOOST_OPENMETHOD_UNLESS_MRDOCS(detail::) SameSmartPtr && std::is_constructible_v>, - typename = std::enable_if_t>> + typename = std::enable_if_t>> virtual_ptr(Other&& other) : vp(detail::box_vptr( other ? detail::acquire_vptr(*other) @@ -1805,8 +1816,11 @@ class virtual_ptr< //! //! @param value A `nullptr`. virtual_ptr& operator=(std::nullptr_t) { + using namespace detail; + obj = SmartPtr(); - vp = detail::box_vptr(detail::null_vptr); + vp = box_vptr(null_vptr); + return *this; } @@ -1830,12 +1844,13 @@ class virtual_ptr< BOOST_OPENMETHOD_UNLESS_MRDOCS(detail::) SameSmartPtr && std::is_assignable_v>, - typename = std::enable_if_t>> + typename = std::enable_if_t>> virtual_ptr& operator=(const Other& other) { obj = other; vp = detail::box_vptr( detail::acquire_vptr(*other)); + return *this; } @@ -1866,12 +1881,13 @@ class virtual_ptr< BOOST_OPENMETHOD_UNLESS_MRDOCS(detail::) SameSmartPtr && std::is_assignable_v>, - typename = std::enable_if_t>> + typename = std::enable_if_t>> virtual_ptr& operator=(Other&& other) { vp = detail::box_vptr( other ? detail::acquire_vptr(*other) : detail::null_vptr); obj = std::move(other); + return *this; } @@ -1899,6 +1915,7 @@ class virtual_ptr< virtual_ptr& operator=(virtual_ptr& other) { obj = other.obj; vp = other.vp; + return *this; } @@ -1928,6 +1945,7 @@ class virtual_ptr< virtual_ptr& operator=(const virtual_ptr& other) { obj = other.obj; vp = other.vp; + return *this; } @@ -2596,7 +2614,7 @@ class method : //! none is more specialized than all the others. //! auto operator()(typename BOOST_OPENMETHOD_UNLESS_MRDOCS(detail::) - StripVirtualDecorator::type... args) const + StripVirtualDecorator::type... args) const -> ReturnType; //! Check if a next most specialized overrider exists @@ -2728,8 +2746,8 @@ class method : template auto resolve_multi_first( - const ArgType& arg, - const MoreArgTypes&... more_args) const -> detail::word; + const ArgType& arg, const MoreArgTypes&... more_args) const + -> detail::word; template< std::size_t VirtualArg, typename MethodArgList, typename ArgType, @@ -2875,8 +2893,9 @@ method::operator()( using namespace detail; auto pf = resolve(args...); - return pf(std::forward::type>( - args)...); + return pf( + std::forward::type>( + args)...); } template< @@ -2896,7 +2915,7 @@ BOOST_FORCEINLINE pf = resolve_uni, ArgType...>(args...).pf; } else { pf = resolve_multi_first, ArgType...>( - args...) + args...) .pf; } @@ -2915,9 +2934,9 @@ BOOST_FORCEINLINE auto method::vptr( if constexpr (detail::has_vptr_fn) { return boost_openmethod_vptr(obj, static_cast(nullptr)); - } else if constexpr (detail::has_vptr< - virtual_traits, - decltype(obj)>) { + } else if constexpr ( + detail::has_vptr< + virtual_traits, decltype(obj)>) { return virtual_traits::vptr(obj); } else { return Registry::template policy::dynamic_vptr(obj); @@ -2930,8 +2949,8 @@ template< template BOOST_FORCEINLINE auto method::resolve_uni( - const ArgType& arg, - const MoreArgTypes&... more_args) const -> detail::word { + const ArgType& arg, const MoreArgTypes&... more_args) const + -> detail::word { using namespace detail; using namespace policies; @@ -2939,6 +2958,7 @@ method::resolve_uni( if constexpr (is_virtual>::value) { vptr_type vtbl = vptr>>(arg); + return vtbl[this->slots_strides[0]]; } else { return resolve_uni>(more_args...); @@ -2950,8 +2970,8 @@ template< template BOOST_FORCEINLINE auto method::resolve_multi_first( - const ArgType& arg, - const MoreArgTypes&... more_args) const -> detail::word { + const ArgType& arg, const MoreArgTypes&... more_args) const + -> detail::word { using namespace detail; using namespace boost::mp11; @@ -2965,6 +2985,7 @@ method::resolve_multi_first( // contains a pointer into the multi-dimensional dispatch table, // already resolved to the appropriate group. auto dispatch = vtbl[slot].pw; + return resolve_multi_next<1, mp_rest, MoreArgTypes...>( dispatch, more_args...); } else { @@ -3063,12 +3084,10 @@ method::fn_ambiguous( namespace detail { template -struct same_reference_category { - static constexpr bool value = (std::is_lvalue_reference::value == - std::is_lvalue_reference::value) && - (std::is_rvalue_reference::value == - std::is_rvalue_reference::value); -}; +constexpr bool same_reference_category = + std::is_lvalue_reference_v == std::is_lvalue_reference_v && + std::is_rvalue_reference_v == std::is_rvalue_reference_v; + template struct validate_overrider_parameter : std::false_type { static_assert( @@ -3080,7 +3099,7 @@ struct validate_overrider_parameter< T1, T2, std::enable_if_t< is_virtual_ptr && is_virtual_ptr && - !same_reference_category::value>> : std::false_type { + !same_reference_category>> : std::false_type { static_assert( false_t, "different virtual_ptr<> reference categories"); }; @@ -3214,7 +3233,7 @@ struct explain_overrider_mismatch< // `true_type` - so the fold is a backstop, not the check. static_assert( (validate_overrider_parameter::value && - ...), + ...), "BOOST_OPENMETHOD_OVERRIDE: the overrider does not match the method"); }; @@ -3230,8 +3249,9 @@ auto method:: using namespace detail; static_assert( (validate_overrider_parameter::value && - ...), + ...), "virtual_ptr category mismatch"); + return Overrider( detail::parameter_traits::template cast< OverriderParameters>( @@ -3263,6 +3283,7 @@ method::override_impl< // coverity[uninit_use] if (overrider_info::method) { BOOST_ASSERT(overrider_info::method == &method::fn); + return; } @@ -3309,9 +3330,9 @@ void method::override_impl< virtual_type>(); this->type = Registry::rtti::template static_type(); using Thunk = thunk; - detail:: - init_type_ids::fn( - this->vp_type_ids); + detail::init_type_ids< + Registry, typename Thunk::OverriderVirtualParameters>::fn(this + ->vp_type_ids); } // ============================================================================= @@ -3355,7 +3376,8 @@ consteval auto is_registry_type(std::meta::info type) -> bool { return std::meta::extract(std::meta::substitute( ^^is_registry, { - type})); + type + })); } // How `register_classes` interprets one item of one of its argument groups. @@ -3428,8 +3450,8 @@ consteval auto register_classes_groups_are_homogeneous() -> bool { return ( ... && (register_classes_group_has_unknown() || - register_classes_group_kind() != - register_classes_kind::invalid)); + register_classes_group_kind() != + register_classes_kind::invalid)); } // The groups must come in the order the `register_classes_kind` enumerators @@ -3445,7 +3467,8 @@ consteval auto register_classes_groups_are_ordered() -> bool { return true; } else { register_classes_kind kinds[] = { - register_classes_group_kind()...}; + register_classes_group_kind()... + }; auto last = register_classes_kind::empty; for (auto kind : kinds) { @@ -3634,7 +3657,8 @@ consteval auto reflected_registered_classes_info() -> std::meta::info { std::meta::substitute( ^^method_classes, { - found})); + found + })); auto types = std::meta::template_arguments_of(list); for (auto type : types) { diff --git a/include/boost/openmethod/detail/ostdstream.hpp b/include/boost/openmethod/detail/ostdstream.hpp index 79c2ad1b..25b533bd 100644 --- a/include/boost/openmethod/detail/ostdstream.hpp +++ b/include/boost/openmethod/detail/ostdstream.hpp @@ -64,8 +64,8 @@ inline auto operator<<(ostdstream& os, const void* value) -> ostdstream& { if (os.stream) { std::array str; auto end = std::to_chars( - str.data(), str.data() + str.size(), - reinterpret_cast(value), 16) + str.data(), str.data() + str.size(), + reinterpret_cast(value), 16) .ptr; os << std::string_view(str.data(), end - str.data()); } @@ -77,8 +77,8 @@ inline auto operator<<(ostdstream& os, void (*value)()) -> ostdstream& { if (os.stream) { std::array str; auto end = std::to_chars( - str.data(), str.data() + str.size(), - reinterpret_cast(value), 16) + str.data(), str.data() + str.size(), + reinterpret_cast(value), 16) .ptr; os << std::string_view(str.data(), end - str.data()); } diff --git a/include/boost/openmethod/detail/static_list.hpp b/include/boost/openmethod/detail/static_list.hpp index 27c86407..7a6763ac 100644 --- a/include/boost/openmethod/detail/static_list.hpp +++ b/include/boost/openmethod/detail/static_list.hpp @@ -41,6 +41,7 @@ class static_list { if (!first) { first = &node; node.prev_ptr = &node; + return; } @@ -63,17 +64,20 @@ class static_list { if (&node == last) { if (&node == first) { first = nullptr; + return; } first->prev_ptr = prev; prev->next_ptr = nullptr; + return; } if (&node == first) { first = next; first->prev_ptr = last; + return; } @@ -116,12 +120,14 @@ class static_list { auto operator++() -> iterator& { BOOST_ASSERT(ptr); ptr = ptr->next_ptr; + return *this; } auto operator++(int) -> iterator { auto tmp = *this; ++(*this); + return tmp; } @@ -168,12 +174,14 @@ class static_list { auto operator++() -> const_iterator& { BOOST_ASSERT(ptr); ptr = ptr->next_ptr; + return *this; } auto operator++(int) -> const_iterator { auto tmp = *this; ++(*this); + return tmp; } diff --git a/include/boost/openmethod/initialize.hpp b/include/boost/openmethod/initialize.hpp index 120cb585..73aa6d64 100644 --- a/include/boost/openmethod/initialize.hpp +++ b/include/boost/openmethod/initialize.hpp @@ -196,15 +196,17 @@ class registry_state_transaction { template struct each> { static void save(detail::tuple& to) { - (..., - (detail::get(to) = - detail::get(Registry::state().policies))); + using namespace detail; + + (..., (get(to) = get(Registry::state().policies))); } static void restore(detail::tuple& from) { + using namespace detail; + (..., - (detail::get(Registry::state().policies) = - std::move(detail::get(from)))); + (get(Registry::state().policies) = + std::move(get(from)))); } }; @@ -461,12 +463,14 @@ struct generic_compiler { auto operator++() -> const_class_iterator& { ++ci_iter_; advance_to_valid(); + return *this; } auto operator++(int) -> const_class_iterator { const_class_iterator tmp = *this; ++(*this); + return tmp; } @@ -477,6 +481,7 @@ struct generic_compiler { if (class_iter_ == class_end_) { return true; } + return ci_iter_ == other.ci_iter_; } @@ -486,8 +491,9 @@ struct generic_compiler { private: void advance_to_valid() { - while (class_iter_ != class_end_ && - ci_iter_ == class_iter_->ci.end()) { + while ( + class_iter_ != class_end_ && + ci_iter_ == class_iter_->ci.end()) { ++class_iter_; if (class_iter_ != class_end_) { ci_iter_ = class_iter_->ci.begin(); @@ -709,6 +715,7 @@ auto operator<<(trace_stream& tr, const T& value) -> auto& { Compiler::Registry::output::stream() << value; } } + return tr; } @@ -1334,8 +1341,9 @@ void registry::compiler::augment_methods() { spec_iter->vp.reserve(first_info->arity()); std::size_t param_index = 0; - for (auto type : - range{overrider_info->vp_begin, overrider_info->vp_end}) { + for ( + auto type : + range{overrider_info->vp_begin, overrider_info->vp_end}) { indent _(tr); auto class_ = class_map[rtti::type_index(type)]; @@ -2196,8 +2204,9 @@ void registry::compiler::print_slots() { auto cls = todo.back(); todo.pop_back(); - for (auto neighbors : - {&cls->direct_bases, &cls->direct_derived}) { + for ( + auto neighbors : + {&cls->direct_bases, &cls->direct_derived}) { for (auto next : *neighbors) { if (component.emplace(next, id).second) { todo.push_back(next); diff --git a/include/boost/openmethod/inplace_vptr.hpp b/include/boost/openmethod/inplace_vptr.hpp index 4dfbfe9d..f73c1328 100644 --- a/include/boost/openmethod/inplace_vptr.hpp +++ b/include/boost/openmethod/inplace_vptr.hpp @@ -126,8 +126,10 @@ class inplace_vptr_base : protected detail::inplace_vptr_base_tag { protected: //! Set the vptr to `Class`\'s v-table. inplace_vptr_base() noexcept { - (void)&detail::inplace_vptr_use_classes; - detail::boost_openmethod_update_vptr(static_cast(this)); + using namespace detail; + + (void)&inplace_vptr_use_classes; + boost_openmethod_update_vptr(static_cast(this)); } //! Set the vptr to `nullptr`. @@ -203,8 +205,9 @@ class inplace_vptr_derived { //! Set the vptr to `Class`\'s v-table. inplace_vptr_derived() noexcept { using namespace detail; - (void)&detail::inplace_vptr_use_classes< - Class, Base, detail::inplace_vptr_registry>; + + (void)&inplace_vptr_use_classes< + Class, Base, inplace_vptr_registry>; boost_openmethod_update_vptr(static_cast(this)); } @@ -246,22 +249,24 @@ class inplace_vptr_derived { protected: //! Set the vptr to `Class`\'s v-table. inplace_vptr_derived() noexcept { - (void)&detail::inplace_vptr_use_classes< - Class, Base1, Base2, MoreBases..., - detail::inplace_vptr_registry>; - detail::boost_openmethod_update_vptr(static_cast(this)); + using namespace detail; + + (void)&inplace_vptr_use_classes< + Class, Base1, Base2, MoreBases..., inplace_vptr_registry>; + boost_openmethod_update_vptr(static_cast(this)); } //! Set the vptr in each base class. //! //! For each base, set its vptr to the base's v-table. ~inplace_vptr_derived() noexcept { + using namespace detail; + auto obj = static_cast(this); - detail::boost_openmethod_update_vptr(static_cast(obj)); - detail::boost_openmethod_update_vptr(static_cast(obj)); - (detail::boost_openmethod_update_vptr( - static_cast(obj)), - ...); + boost_openmethod_update_vptr(static_cast(obj)); + boost_openmethod_update_vptr(static_cast(obj)); + (boost_openmethod_update_vptr(static_cast(obj)), + ...); } }; diff --git a/include/boost/openmethod/interop/boost_any.hpp b/include/boost/openmethod/interop/boost_any.hpp index 320c32a1..8ba304fc 100644 --- a/include/boost/openmethod/interop/boost_any.hpp +++ b/include/boost/openmethod/interop/boost_any.hpp @@ -93,8 +93,11 @@ struct virtual_traits { //! @param arg A reference to a const `any`. //! @return A reference to the v-table pointer for the stored value. static auto vptr(const boost::any& arg) -> const vptr_type& { - detail::assert_std_rtti_boost_any(); - (void)&detail::use_any_classes; + using namespace detail; + + assert_std_rtti_boost_any(); + (void)&use_any_classes; + return Registry::vptr::vptr(&arg.type()); } @@ -127,6 +130,7 @@ struct virtual_traits { } else { (void)&detail::use_any_classes< Registry, boost::any, std::decay_t>; + return boost::any_cast(arg); } } @@ -176,8 +180,11 @@ struct virtual_traits { //! @param arg A reference to a `boost::any`. //! @return A reference to the v-table pointer for the stored value. static auto vptr(const boost::any& arg) -> const vptr_type& { - detail::assert_std_rtti_boost_any(); - (void)&detail::use_any_classes; + using namespace detail; + + assert_std_rtti_boost_any(); + (void)&use_any_classes; + return Registry::vptr::vptr(&arg.type()); } @@ -210,6 +217,7 @@ struct virtual_traits { } else { (void)&detail::use_any_classes< Registry, boost::any, std::decay_t>; + return boost::any_cast(arg); } } @@ -259,8 +267,11 @@ struct virtual_traits { //! @param arg A reference to a `boost::any`. //! @return A reference to the v-table pointer for the stored value. static auto vptr(const boost::any& arg) -> const vptr_type& { - detail::assert_std_rtti_boost_any(); - (void)&detail::use_any_classes; + using namespace detail; + + assert_std_rtti_boost_any(); + (void)&use_any_classes; + return Registry::vptr::vptr(&arg.type()); } @@ -293,6 +304,7 @@ struct virtual_traits { } else { (void)&detail::use_any_classes< Registry, boost::any, std::decay_t>; + return boost::any_cast(std::move(arg)); } } diff --git a/include/boost/openmethod/interop/boost_type_erasure.hpp b/include/boost/openmethod/interop/boost_type_erasure.hpp index a6f53f9b..0cfba56d 100644 --- a/include/boost/openmethod/interop/boost_type_erasure.hpp +++ b/include/boost/openmethod/interop/boost_type_erasure.hpp @@ -185,8 +185,11 @@ struct virtual_traits&, Registry> { //! @return A reference to the v-table pointer for the bound value. static auto vptr(const boost::type_erasure::any& arg) -> const vptr_type& { - detail::assert_std_rtti_type_erasure(); - (void)&detail::use_any_classes>; + using namespace detail; + + assert_std_rtti_type_erasure(); + (void)&use_any_classes>; + return Registry::vptr::vptr(&boost::type_erasure::typeid_of(arg)); } @@ -211,12 +214,14 @@ struct virtual_traits&, Registry> { (!detail::te_mutable_target || detail::te_mutable_bound)>> static auto cast(const boost::type_erasure::any& arg) -> decltype(auto) { - if constexpr ( - detail::te_pass_through>) { + using namespace detail; + + if constexpr (te_pass_through>) { return (arg); } else { - (void)&detail::use_any_classes< + (void)&use_any_classes< Registry, boost::type_erasure::any, std::decay_t>; + return boost::type_erasure::any_cast(arg); } } @@ -260,8 +265,11 @@ struct virtual_traits&, Registry> { //! @return A reference to the v-table pointer for the bound value. static auto vptr(const boost::type_erasure::any& arg) -> const vptr_type& { - detail::assert_std_rtti_type_erasure(); - (void)&detail::use_any_classes>; + using namespace detail; + + assert_std_rtti_type_erasure(); + (void)&use_any_classes>; + return Registry::vptr::vptr(&boost::type_erasure::typeid_of(arg)); } @@ -284,14 +292,16 @@ struct virtual_traits&, Registry> { typename = std::enable_if_t< !std::is_rvalue_reference_v && (!detail::te_mutable_target || detail::te_owning || - detail::te_mutable_bound)>> + detail::te_mutable_bound)>> static auto cast(boost::type_erasure::any& arg) -> decltype(auto) { - if constexpr ( - detail::te_pass_through>) { + using namespace detail; + + if constexpr (te_pass_through>) { return (arg); } else { - (void)&detail::use_any_classes< + (void)&use_any_classes< Registry, boost::type_erasure::any, std::decay_t>; + return boost::type_erasure::any_cast(arg); } } @@ -335,8 +345,11 @@ struct virtual_traits&&, Registry> { //! @return A reference to the v-table pointer for the bound value. static auto vptr(const boost::type_erasure::any& arg) -> const vptr_type& { - detail::assert_std_rtti_type_erasure(); - (void)&detail::use_any_classes>; + using namespace detail; + + assert_std_rtti_type_erasure(); + (void)&use_any_classes>; + return Registry::vptr::vptr(&boost::type_erasure::typeid_of(arg)); } @@ -360,21 +373,21 @@ struct virtual_traits&&, Registry> { typename = std::enable_if_t< (!std::is_rvalue_reference_v || detail::te_owning) && (!detail::te_mutable_target || detail::te_owning || - detail::te_mutable_bound)>> + detail::te_mutable_bound)>> static auto cast(boost::type_erasure::any&& arg) -> decltype(auto) { - if constexpr ( - detail::te_pass_through>) { + using namespace detail; + + if constexpr (te_pass_through>) { return std::move(arg); } else { - (void)&detail::use_any_classes< + (void)&use_any_classes< Registry, boost::type_erasure::any, std::decay_t>; if constexpr (std::is_rvalue_reference_v) { return std::move( boost::type_erasure::any_cast&>( arg)); - } else if constexpr ( - !std::is_reference_v && detail::te_owning) { + } else if constexpr (!std::is_reference_v && te_owning) { return U(std::move(boost::type_erasure::any_cast(arg))); } else { return boost::type_erasure::any_cast(arg); @@ -424,8 +437,11 @@ struct virtual_traits, Registry> { //! @return A reference to the v-table pointer for the bound value. static auto vptr(const boost::type_erasure::any& arg) -> const vptr_type& { - detail::assert_std_rtti_type_erasure(); - (void)&detail::use_any_classes>; + using namespace detail; + + assert_std_rtti_type_erasure(); + (void)&use_any_classes>; + return Registry::vptr::vptr(&boost::type_erasure::typeid_of(arg)); } @@ -445,14 +461,16 @@ struct virtual_traits, Registry> { template< typename U, typename = std::enable_if_t>> static auto cast(boost::type_erasure::any arg) -> decltype(auto) { - if constexpr ( - detail::te_pass_through>) { + using namespace detail; + + if constexpr (te_pass_through>) { // by value: a reference would dangle when this function's // parameter goes out of scope return arg; } else { - (void)&detail::use_any_classes< + (void)&use_any_classes< Registry, boost::type_erasure::any, std::decay_t>; + return boost::type_erasure::any_cast(arg); } } @@ -500,8 +518,11 @@ struct virtual_traits, Registry> { //! @return A reference to the v-table pointer for the bound value. static auto vptr(const boost::type_erasure::any& arg) -> const vptr_type& { - detail::assert_std_rtti_type_erasure(); - (void)&detail::use_any_classes>; + using namespace detail; + + assert_std_rtti_type_erasure(); + (void)&use_any_classes>; + return Registry::vptr::vptr(&boost::type_erasure::typeid_of(arg)); } @@ -522,14 +543,17 @@ struct virtual_traits, Registry> { !std::is_rvalue_reference_v && !detail::te_mutable_target>> static auto cast(boost::type_erasure::any arg) -> decltype(auto) { + using namespace detail; + if constexpr ( - detail::te_pass_through>) { + te_pass_through>) { // by value: a reference would dangle when this function's // parameter goes out of scope return arg; } else { - (void)&detail::use_any_classes< + (void)&use_any_classes< Registry, boost::type_erasure::any, std::decay_t>; + return boost::type_erasure::any_cast(arg); } } @@ -590,6 +614,7 @@ struct openmethod_vptr { static auto apply(const T&) -> vptr_type { (void)&detail::use_any_classes< Registry, boost::type_erasure::any, T>; + return Registry::template static_vptr; } }; diff --git a/include/boost/openmethod/interop/std_any.hpp b/include/boost/openmethod/interop/std_any.hpp index e5ee6247..f80fe1d2 100644 --- a/include/boost/openmethod/interop/std_any.hpp +++ b/include/boost/openmethod/interop/std_any.hpp @@ -91,8 +91,11 @@ struct virtual_traits { //! @param arg A reference to a const `any`. //! @return A reference to the v-table pointer for the stored value. static auto vptr(const std::any& arg) -> const vptr_type& { - detail::assert_std_rtti_std_any(); - (void)&detail::use_any_classes; + using namespace detail; + + assert_std_rtti_std_any(); + (void)&use_any_classes; + return Registry::vptr::vptr(&arg.type()); } @@ -116,6 +119,7 @@ struct virtual_traits { return (arg); } else { (void)&detail::use_any_classes>; + return std::any_cast(arg); } } @@ -163,8 +167,11 @@ struct virtual_traits { //! @param arg A reference to a `std::any`. //! @return A reference to the v-table pointer for the stored value. static auto vptr(const std::any& arg) -> const vptr_type& { - detail::assert_std_rtti_std_any(); - (void)&detail::use_any_classes; + using namespace detail; + + assert_std_rtti_std_any(); + (void)&use_any_classes; + return Registry::vptr::vptr(&arg.type()); } @@ -189,6 +196,7 @@ struct virtual_traits { return (arg); } else { (void)&detail::use_any_classes>; + return std::any_cast(arg); } } @@ -236,8 +244,11 @@ struct virtual_traits { //! @param arg A reference to a const `any`. //! @return A reference to the v-table pointer for the stored value. static auto vptr(const std::any& arg) -> const vptr_type& { - detail::assert_std_rtti_std_any(); - (void)&detail::use_any_classes; + using namespace detail; + + assert_std_rtti_std_any(); + (void)&use_any_classes; + return Registry::vptr::vptr(&arg.type()); } @@ -259,6 +270,7 @@ struct virtual_traits { return std::move(arg); } else { (void)&detail::use_any_classes>; + return std::any_cast(std::move(arg)); } } diff --git a/include/boost/openmethod/interop/std_unique_ptr.hpp b/include/boost/openmethod/interop/std_unique_ptr.hpp index 30f21571..58c82b7a 100644 --- a/include/boost/openmethod/interop/std_unique_ptr.hpp +++ b/include/boost/openmethod/interop/std_unique_ptr.hpp @@ -50,11 +50,13 @@ struct virtual_traits, Registry> { typename Derived::element_type&>(*ptr); // coverity[alloc_fn] ptr.release(); + return Derived(p); } else { auto p = &static_cast(*ptr); // coverity[alloc_fn] ptr.release(); + return Derived(p); } } diff --git a/include/boost/openmethod/interop/std_weak_ptr.hpp b/include/boost/openmethod/interop/std_weak_ptr.hpp index 9e95a499..778202c5 100644 --- a/include/boost/openmethod/interop/std_weak_ptr.hpp +++ b/include/boost/openmethod/interop/std_weak_ptr.hpp @@ -260,7 +260,7 @@ class weak_virtual_ptr { template< class Other, typename = std::enable_if_t>, + IsPolymorphic>, typename = std::enable_if_t, const std::shared_ptr&>>> weak_virtual_ptr(const std::shared_ptr& other) : @@ -283,7 +283,7 @@ class weak_virtual_ptr { template< class Other, typename = std::enable_if_t>, + IsPolymorphic>, typename = std::enable_if_t, const std::weak_ptr&>>> weak_virtual_ptr(const std::weak_ptr& other) { @@ -297,15 +297,18 @@ class weak_virtual_ptr { //! @param value A `nullptr`. weak_virtual_ptr& operator=(std::nullptr_t) noexcept { reset(); + return *this; } weak_virtual_ptr& operator=(const weak_virtual_ptr& other) = default; weak_virtual_ptr& operator=(weak_virtual_ptr&& other) noexcept { - vp = std::exchange( - other.vp, detail::box_vptr(detail::null_vptr)); + using namespace detail; + + vp = std::exchange(other.vp, box_vptr(null_vptr)); obj = std::move(other.obj); + return *this; } @@ -331,6 +334,7 @@ class weak_virtual_ptr { const virtual_ptr, Registry>& other) { vp = vptr_of(other); obj = other.pointer(); + return *this; } @@ -352,6 +356,7 @@ class weak_virtual_ptr { const weak_virtual_ptr& other) { vp = other.vp; obj = other.obj; + return *this; } @@ -375,6 +380,7 @@ class weak_virtual_ptr { vp = std::exchange( other.vp, detail::box_vptr(detail::null_vptr)); obj = std::move(other.obj); + return *this; } @@ -393,12 +399,13 @@ class weak_virtual_ptr { template< class Other, typename = std::enable_if_t>, + IsPolymorphic>, typename = std::enable_if_t&, const std::shared_ptr&>>> weak_virtual_ptr& operator=(const std::shared_ptr& other) { vp = vptr_of(other); obj = other; + return *this; } @@ -418,11 +425,12 @@ class weak_virtual_ptr { template< class Other, typename = std::enable_if_t>, + IsPolymorphic>, typename = std::enable_if_t&, const std::weak_ptr&>>> weak_virtual_ptr& operator=(const std::weak_ptr& other) { assign(other); + return *this; } @@ -497,8 +505,10 @@ class weak_virtual_ptr { //! //! Reset the `std::weak_ptr`. Set the v-table pointer to `nullptr`. void reset() noexcept { + using namespace detail; + obj.reset(); - vp = detail::box_vptr(detail::null_vptr); + vp = box_vptr(null_vptr); } //! Swap with another `weak_virtual_ptr` diff --git a/include/boost/openmethod/interop/virtual_any.hpp b/include/boost/openmethod/interop/virtual_any.hpp index af05d0a6..763661be 100644 --- a/include/boost/openmethod/interop/virtual_any.hpp +++ b/include/boost/openmethod/interop/virtual_any.hpp @@ -189,9 +189,11 @@ class virtual_any { obj(std::forward(value)), vp(detail::box_vptr( Registry::template static_vptr>)) { - (void)&detail::use_any_classes>; + using namespace detail; + + (void)&use_any_classes>; Registry::require_initialized(); - BOOST_ASSERT(detail::unbox_vptr(vp) != nullptr); + BOOST_ASSERT(unbox_vptr(vp) != nullptr); } //! Copy constructor. @@ -203,7 +205,9 @@ class virtual_any { //! //! @param other A `virtual_any`. virtual_any(virtual_any&& other) : obj(std::move(other.obj)), vp(other.vp) { - other.vp = detail::box_vptr(detail::null_vptr); + using namespace detail; + + other.vp = box_vptr(null_vptr); } //! Copy assignment operator. @@ -215,9 +219,12 @@ class virtual_any { //! //! @param other A `virtual_any`. auto operator=(virtual_any&& other) -> virtual_any& { + using namespace detail; + obj = std::move(other.obj); vp = other.vp; - other.vp = detail::box_vptr(detail::null_vptr); + other.vp = box_vptr(null_vptr); + return *this; } @@ -228,9 +235,11 @@ class virtual_any { //! //! @param other An `any`. auto operator=(const Any& other) -> virtual_any& { + using namespace detail; + obj = other; - vp = detail::box_vptr( - detail::acquire_vptr(obj)); + vp = box_vptr(acquire_vptr(obj)); + return *this; } @@ -241,9 +250,11 @@ class virtual_any { //! //! @param other An `any`. auto operator=(Any&& other) -> virtual_any& { + using namespace detail; + obj = std::move(other); - vp = detail::box_vptr( - detail::acquire_vptr(obj)); + vp = box_vptr(acquire_vptr(obj)); + return *this; } @@ -266,12 +277,15 @@ class virtual_any { !std::is_same_v, Any> && std::is_constructible_v>> auto operator=(T&& value) -> virtual_any& { - (void)&detail::use_any_classes>; + using namespace detail; + + (void)&use_any_classes>; obj = std::forward(value); Registry::require_initialized(); - vp = detail::box_vptr( + vp = box_vptr( Registry::template static_vptr>); - BOOST_ASSERT(detail::unbox_vptr(vp) != nullptr); + BOOST_ASSERT(unbox_vptr(vp) != nullptr); + return *this; } @@ -339,6 +353,7 @@ struct virtual_traits&, Registry> { static auto vptr(const virtual_any& arg) -> const vptr_type& { (void)&detail::use_any_classes; + return arg.vptr_ref(); } @@ -363,6 +378,7 @@ struct virtual_traits&, Registry> { return (arg); } else { (void)&detail::use_any_classes>; + return virtual_traits::template cast( arg.obj); } @@ -399,6 +415,7 @@ struct virtual_traits&, Registry> { static auto vptr(const virtual_any& arg) -> const vptr_type& { (void)&detail::use_any_classes; + return arg.vptr_ref(); } @@ -425,6 +442,7 @@ struct virtual_traits&, Registry> { return (arg); } else { (void)&detail::use_any_classes>; + return virtual_traits::template cast(arg.obj); } } @@ -460,6 +478,7 @@ struct virtual_traits&&, Registry> { static auto vptr(const virtual_any& arg) -> const vptr_type& { (void)&detail::use_any_classes; + return arg.vptr_ref(); } @@ -484,6 +503,7 @@ struct virtual_traits&&, Registry> { return std::move(arg); } else { (void)&detail::use_any_classes>; + return virtual_traits::template cast( std::move(arg.obj)); } @@ -506,7 +526,7 @@ template class virtual_ptr< Class, Registry, std::enable_if_t>>> { + IsVirtualAny>>> { static_assert( detail::false_t, "do not wrap a virtual_any in a virtual_ptr: it already carries the " diff --git a/include/boost/openmethod/policies/default_error_handler.hpp b/include/boost/openmethod/policies/default_error_handler.hpp index aa41a6a5..b9706e0c 100644 --- a/include/boost/openmethod/policies/default_error_handler.hpp +++ b/include/boost/openmethod/policies/default_error_handler.hpp @@ -118,6 +118,7 @@ struct default_error_handler : error_handler { // coverity[auto_causes_copy] static auto set(function_type new_handler) -> function_type { auto prev = std::exchange(st().handler, std::move(new_handler)); + return prev ? prev : default_handler; } diff --git a/include/boost/openmethod/policies/fast_perfect_hash.hpp b/include/boost/openmethod/policies/fast_perfect_hash.hpp index 5d8b4387..2cf2b2e0 100644 --- a/include/boost/openmethod/policies/fast_perfect_hash.hpp +++ b/include/boost/openmethod/policies/fast_perfect_hash.hpp @@ -242,10 +242,12 @@ void fast_perfect_hash::fn::initialize_aux( st().fn.min_value = (std::numeric_limits::max)(); st().fn.max_value = (std::numeric_limits::min)(); - for (auto iter = ctx.classes_begin(); iter != ctx.classes_end(); - ++iter) { - for (auto type_iter = iter->type_id_begin(); - type_iter != iter->type_id_end(); ++type_iter) { + for ( + auto iter = ctx.classes_begin(); iter != ctx.classes_end(); + ++iter) { + for ( + auto type_iter = iter->type_id_begin(); + type_iter != iter->type_id_end(); ++type_iter) { auto type = *type_iter; auto index = st().fn(type); diff --git a/include/boost/openmethod/policies/minimal_cover_hash.hpp b/include/boost/openmethod/policies/minimal_cover_hash.hpp index f11366aa..7c19b9e3 100644 --- a/include/boost/openmethod/policies/minimal_cover_hash.hpp +++ b/include/boost/openmethod/policies/minimal_cover_hash.hpp @@ -103,6 +103,7 @@ inline constexpr bool has_pext = BOOST_OPENMETHOD_HAS_PEXT != 0; // quite enough. inline auto popcount64(std::uint64_t bits) -> std::size_t { #if defined(__GNUC__) || defined(__clang__) + return std::size_t(__builtin_popcountll(bits)); #else bits = bits - ((bits >> 1) & 0x5555555555555555ull); @@ -119,6 +120,7 @@ inline auto popcount64(std::uint64_t bits) -> std::size_t { // registry static_asserts first. inline auto pext64(std::uint64_t value, std::uint64_t mask) -> std::uint64_t { #if BOOST_OPENMETHOD_HAS_PEXT + return _pext_u64(value, mask); #else (void)value; @@ -272,11 +274,11 @@ struct minimal_cover_hash : type_hash { //! @return The index BOOST_FORCEINLINE static auto hash(type_id type) -> std::size_t { - auto index = std::size_t( - detail::pext64( - static_cast( - reinterpret_cast(type)), - st().mask)); + using namespace detail; + + auto index = std::size_t(pext64( + static_cast(reinterpret_cast(type)), + st().mask)); if constexpr (Registry::has_runtime_checks) { check(index, type); @@ -440,8 +442,9 @@ auto minimal_cover_hash::fn::initialize( std::vector ids; for (auto iter = ctx.classes_begin(); iter != ctx.classes_end(); ++iter) { - for (auto type_iter = iter->type_id_begin(); - type_iter != iter->type_id_end(); ++type_iter) { + for ( + auto type_iter = iter->type_id_begin(); + type_iter != iter->type_id_end(); ++type_iter) { ids.push_back( static_cast( reinterpret_cast(*type_iter))); diff --git a/include/boost/openmethod/policies/minimal_perfect_hash.hpp b/include/boost/openmethod/policies/minimal_perfect_hash.hpp index b9096928..df24d088 100644 --- a/include/boost/openmethod/policies/minimal_perfect_hash.hpp +++ b/include/boost/openmethod/policies/minimal_perfect_hash.hpp @@ -169,8 +169,10 @@ struct minimal_perfect_hash : type_hash { // The top half of a 64x64 product. static auto mulhi(std::uint64_t a, std::uint64_t b) -> std::uint64_t { #if defined(__SIZEOF_INT128__) + return std::uint64_t((static_cast<__uint128_t>(a) * b) >> 64); #elif defined(_MSC_VER) && defined(_M_X64) + return __umulh(a, b); #else auto lo = [](std::uint64_t v) { return v & 0xffffffffull; }; @@ -218,7 +220,8 @@ struct minimal_perfect_hash : type_hash { //! Returns the hash range: `[0, slots - 1]`. static auto hash_range() -> std::pair { return std::pair{ - std::size_t(0), std::size_t(st().size ? st().size - 1 : 0)}; + std::size_t(0), std::size_t(st().size ? st().size - 1 : 0) + }; } //! Map a type id to an index @@ -369,8 +372,9 @@ auto minimal_perfect_hash::fn:: std::vector ids; for (auto iter = ctx.classes_begin(); iter != ctx.classes_end(); ++iter) { - for (auto type_iter = iter->type_id_begin(); - type_iter != iter->type_id_end(); ++type_iter) { + for ( + auto type_iter = iter->type_id_begin(); + type_iter != iter->type_id_end(); ++type_iter) { ids.push_back( std::uint64_t(reinterpret_cast(*type_iter))); } diff --git a/include/boost/openmethod/policies/static_rtti.hpp b/include/boost/openmethod/policies/static_rtti.hpp index d907818c..248bca6a 100644 --- a/include/boost/openmethod/policies/static_rtti.hpp +++ b/include/boost/openmethod/policies/static_rtti.hpp @@ -53,6 +53,7 @@ struct static_rtti : rtti { template static auto static_type() -> type_id { static char id; + return &id; } }; diff --git a/include/boost/openmethod/policies/two_level_hash.hpp b/include/boost/openmethod/policies/two_level_hash.hpp index 43d653b5..b5d09df9 100644 --- a/include/boost/openmethod/policies/two_level_hash.hpp +++ b/include/boost/openmethod/policies/two_level_hash.hpp @@ -325,8 +325,9 @@ auto two_level_hash::fn::initialize( std::vector ids; for (auto iter = ctx.classes_begin(); iter != ctx.classes_end(); ++iter) { - for (auto type_iter = iter->type_id_begin(); - type_iter != iter->type_id_end(); ++type_iter) { + for ( + auto type_iter = iter->type_id_begin(); + type_iter != iter->type_id_end(); ++type_iter) { ids.push_back( std::uint64_t(reinterpret_cast(*type_iter))); } diff --git a/include/boost/openmethod/policies/vptr_map.hpp b/include/boost/openmethod/policies/vptr_map.hpp index 0cbbcd5e..7685cb26 100644 --- a/include/boost/openmethod/policies/vptr_map.hpp +++ b/include/boost/openmethod/policies/vptr_map.hpp @@ -77,10 +77,12 @@ class vptr_map : public vptr { const Context& ctx, const std::tuple&) { decltype(st().vptrs) new_vptrs; - for (auto iter = ctx.classes_begin(); iter != ctx.classes_end(); - ++iter) { - for (auto type_iter = iter->type_id_begin(); - type_iter != iter->type_id_end(); ++type_iter) { + for ( + auto iter = ctx.classes_begin(); iter != ctx.classes_end(); + ++iter) { + for ( + auto type_iter = iter->type_id_begin(); + type_iter != iter->type_id_end(); ++type_iter) { if constexpr (Registry::has_indirect_vptr) { new_vptrs.emplace(*type_iter, iter->static_vptr()); diff --git a/include/boost/openmethod/policies/vptr_vector.hpp b/include/boost/openmethod/policies/vptr_vector.hpp index daabfebc..c6bfe6fd 100644 --- a/include/boost/openmethod/policies/vptr_vector.hpp +++ b/include/boost/openmethod/policies/vptr_vector.hpp @@ -115,10 +115,12 @@ struct vptr_vector : vptr { } else { size = 0; - for (auto iter = ctx.classes_begin(); iter != ctx.classes_end(); - ++iter) { - for (auto type_iter = iter->type_id_begin(); - type_iter != iter->type_id_end(); ++type_iter) { + for ( + auto iter = ctx.classes_begin(); iter != ctx.classes_end(); + ++iter) { + for ( + auto type_iter = iter->type_id_begin(); + type_iter != iter->type_id_end(); ++type_iter) { size = (std::max)(size, std::size_t(*type_iter)); } } @@ -134,10 +136,12 @@ struct vptr_vector : vptr { // below does not write is null instead. decltype(st().vptrs) new_vptrs(size); - for (auto iter = ctx.classes_begin(); iter != ctx.classes_end(); - ++iter) { - for (auto type_iter = iter->type_id_begin(); - type_iter != iter->type_id_end(); ++type_iter) { + for ( + auto iter = ctx.classes_begin(); iter != ctx.classes_end(); + ++iter) { + for ( + auto type_iter = iter->type_id_begin(); + type_iter != iter->type_id_end(); ++type_iter) { std::size_t index; if constexpr (has_type_hash) { diff --git a/include/boost/openmethod/preamble.hpp b/include/boost/openmethod/preamble.hpp index c1f6f24f..8528ee82 100644 --- a/include/boost/openmethod/preamble.hpp +++ b/include/boost/openmethod/preamble.hpp @@ -495,9 +495,11 @@ inline trace trace::from_env() { auto result = _dupenv_s(&env, &len, "BOOST_OPENMETHOD_TRACE") == 0 && env && len == 2 && *env == '1'; free(env); + return trace(result); #else auto env = getenv("BOOST_OPENMETHOD_TRACE"); + return trace(env && *env++ == '1' && *env++ == 0); #endif } diff --git a/test/compile_fail_adl_registry_not_a_registry.cpp b/test/compile_fail_adl_registry_not_a_registry.cpp index c31eeb47..1cf30aa5 100644 --- a/test/compile_fail_adl_registry_not_a_registry.cpp +++ b/test/compile_fail_adl_registry_not_a_registry.cpp @@ -17,5 +17,6 @@ struct Animal { int main() { (void)sizeof(virtual_ptr); + return 0; } diff --git a/test/compile_fail_boost_any_const_ref_to_mutable_ref.cpp b/test/compile_fail_boost_any_const_ref_to_mutable_ref.cpp index 4e5e17cf..a5a9480a 100644 --- a/test/compile_fail_boost_any_const_ref_to_mutable_ref.cpp +++ b/test/compile_fail_boost_any_const_ref_to_mutable_ref.cpp @@ -27,7 +27,7 @@ BOOST_OPENMETHOD(name, (virtual_), std::string); // The `any` is const, so boost::any_cast cannot produce a mutable reference to // the value it contains. Without the constraint on `cast`, this would fail // inside Boost.Any instead of at the trait. -BOOST_OPENMETHOD_OVERRIDE(name, (Dog & dog), std::string) { +BOOST_OPENMETHOD_OVERRIDE(name, (Dog& dog), std::string) { return dog.name; } diff --git a/test/compile_fail_final_virtual_ptr_std_any.cpp b/test/compile_fail_final_virtual_ptr_std_any.cpp index 2784b771..3207a863 100644 --- a/test/compile_fail_final_virtual_ptr_std_any.cpp +++ b/test/compile_fail_final_virtual_ptr_std_any.cpp @@ -26,5 +26,6 @@ int main() { // combination is deleted; use virtual_any instead. std::any spot(Dog{"Spot"}); final_virtual_ptr(spot); + return 0; } diff --git a/test/compile_fail_final_virtual_ptr_type_erasure.cpp b/test/compile_fail_final_virtual_ptr_type_erasure.cpp index b77c7e6e..200eff16 100644 --- a/test/compile_fail_final_virtual_ptr_type_erasure.cpp +++ b/test/compile_fail_final_virtual_ptr_type_erasure.cpp @@ -30,5 +30,6 @@ int main() { // combination is deleted; use virtual_any instead. erased spot(Dog{"Spot"}); final_virtual_ptr(spot); + return 0; } diff --git a/test/compile_fail_final_virtual_ptr_virtual_any.cpp b/test/compile_fail_final_virtual_ptr_virtual_any.cpp index 75a2140c..f59a064e 100644 --- a/test/compile_fail_final_virtual_ptr_virtual_any.cpp +++ b/test/compile_fail_final_virtual_ptr_virtual_any.cpp @@ -26,5 +26,6 @@ int main() { // virtual_ptr it returns, so the rejection catches this too. virtual_std_any spot = Dog{"Spot"}; final_virtual_ptr(spot); + return 0; } diff --git a/test/compile_fail_final_virtual_ptr_weak_ptr.cpp b/test/compile_fail_final_virtual_ptr_weak_ptr.cpp index de996e59..bb91a4b0 100644 --- a/test/compile_fail_final_virtual_ptr_weak_ptr.cpp +++ b/test/compile_fail_final_virtual_ptr_weak_ptr.cpp @@ -22,5 +22,6 @@ int main() { auto felix = std::make_shared(); std::weak_ptr weak = felix; auto p = final_virtual_ptr(weak); + return 0; } diff --git a/test/compile_fail_non_polymorphic_virtual_parameter.cpp b/test/compile_fail_non_polymorphic_virtual_parameter.cpp index 405bf3a5..a7b03e9f 100644 --- a/test/compile_fail_non_polymorphic_virtual_parameter.cpp +++ b/test/compile_fail_non_polymorphic_virtual_parameter.cpp @@ -16,5 +16,6 @@ BOOST_OPENMETHOD(poke, (virtual_), void); int main() { poke(Cat{}); + return 0; } diff --git a/test/compile_fail_policy_state_throwing_move.cpp b/test/compile_fail_policy_state_throwing_move.cpp index 7f9ab823..2dfbfaac 100644 --- a/test/compile_fail_policy_state_throwing_move.cpp +++ b/test/compile_fail_policy_state_throwing_move.cpp @@ -58,5 +58,6 @@ BOOST_OPENMETHOD_REGISTER(use_classes); int main() { initialize(); + return 0; } diff --git a/test/compile_fail_std_any_custom_rtti.cpp b/test/compile_fail_std_any_custom_rtti.cpp index 6a6e224b..4a9747b9 100644 --- a/test/compile_fail_std_any_custom_rtti.cpp +++ b/test/compile_fail_std_any_custom_rtti.cpp @@ -58,5 +58,6 @@ int main() { // Call the method: declaring it is not enough to instantiate it on // every compiler, and the guard lives in `virtual_traits::vptr`. std::any dog = Dog{"Snoopy"}; + return name(dog).size(); } diff --git a/test/compile_fail_type_erasure_by_value.cpp b/test/compile_fail_type_erasure_by_value.cpp index ce42a505..f8b465eb 100644 --- a/test/compile_fail_type_erasure_by_value.cpp +++ b/test/compile_fail_type_erasure_by_value.cpp @@ -33,5 +33,6 @@ int main() { // Call the method: declaring it is not enough to instantiate it on // every compiler, and the guard lives in the method's body. erased dog = Dog{"Snoopy"}; + return name(dog).size(); } diff --git a/test/compile_fail_type_erasure_const_ref_to_mutable_ref.cpp b/test/compile_fail_type_erasure_const_ref_to_mutable_ref.cpp index c3c909f4..f775741f 100644 --- a/test/compile_fail_type_erasure_const_ref_to_mutable_ref.cpp +++ b/test/compile_fail_type_erasure_const_ref_to_mutable_ref.cpp @@ -29,7 +29,7 @@ BOOST_OPENMETHOD(name, (virtual_), std::string); // The `any` is const and owns its value, so the overrider cannot take a // mutable reference to it; the `cast` overload is removed from the // overload set. -BOOST_OPENMETHOD_OVERRIDE(name, (Dog & dog), std::string) { +BOOST_OPENMETHOD_OVERRIDE(name, (Dog& dog), std::string) { return dog.name; } diff --git a/test/compile_fail_type_erasure_custom_rtti.cpp b/test/compile_fail_type_erasure_custom_rtti.cpp index e0ba45ab..732e8b57 100644 --- a/test/compile_fail_type_erasure_custom_rtti.cpp +++ b/test/compile_fail_type_erasure_custom_rtti.cpp @@ -65,5 +65,6 @@ int main() { // Call the method: declaring it is not enough to instantiate it on // every compiler, and the guard lives in `virtual_traits::vptr`. erased dog = Dog{"Snoopy"}; + return name(dog).size(); } diff --git a/test/compile_fail_virtual_any_by_value.cpp b/test/compile_fail_virtual_any_by_value.cpp index a592e391..8a7acd4e 100644 --- a/test/compile_fail_virtual_any_by_value.cpp +++ b/test/compile_fail_virtual_any_by_value.cpp @@ -24,5 +24,6 @@ BOOST_OPENMETHOD(name, (virtual_std_any), std::string); int main() { virtual_std_any dog = Dog{"Snoopy"}; + return name(dog).size(); } diff --git a/test/compile_fail_virtual_parameter_private_base_macros.cpp b/test/compile_fail_virtual_parameter_private_base_macros.cpp index 5fbf5ad2..de71be9f 100644 --- a/test/compile_fail_virtual_parameter_private_base_macros.cpp +++ b/test/compile_fail_virtual_parameter_private_base_macros.cpp @@ -30,5 +30,6 @@ BOOST_OPENMETHOD_OVERRIDE(poke, (virtual_ptr), void) { int main() { Cat felix; poke(felix.as_animal()); + return 0; } diff --git a/test/compile_fail_virtual_parameter_to_value.cpp b/test/compile_fail_virtual_parameter_to_value.cpp index 91dde3a0..2fb0d2f2 100644 --- a/test/compile_fail_virtual_parameter_to_value.cpp +++ b/test/compile_fail_virtual_parameter_to_value.cpp @@ -20,5 +20,6 @@ BOOST_OPENMETHOD(poke, (virtual_), void); int main() { Cat felix; poke(felix); + return 0; } diff --git a/test/compile_fail_virtual_ptr_different_registries.cpp b/test/compile_fail_virtual_ptr_different_registries.cpp index 728f9e0b..2d48110f 100644 --- a/test/compile_fail_virtual_ptr_different_registries.cpp +++ b/test/compile_fail_virtual_ptr_different_registries.cpp @@ -24,5 +24,6 @@ BOOST_OPENMETHOD(poke, (virtual_ptr), void, other_registry); int main() { Cat felix; poke(felix); + return 0; } diff --git a/test/compile_fail_virtual_ptr_inplace_vptr.cpp b/test/compile_fail_virtual_ptr_inplace_vptr.cpp index b9157bba..b64565c9 100644 --- a/test/compile_fail_virtual_ptr_inplace_vptr.cpp +++ b/test/compile_fail_virtual_ptr_inplace_vptr.cpp @@ -21,5 +21,6 @@ struct Animal : inplace_vptr_base { int main() { Animal animal; virtual_ptr p(animal); + return 0; } diff --git a/test/compile_fail_virtual_ptr_other.cpp b/test/compile_fail_virtual_ptr_other.cpp index 5d9ad2bd..f7cf85a0 100644 --- a/test/compile_fail_virtual_ptr_other.cpp +++ b/test/compile_fail_virtual_ptr_other.cpp @@ -24,5 +24,6 @@ BOOST_OPENMETHOD_OVERRIDE(poke, (Cat&), void) { int main() { Cat felix; poke(felix); + return 0; } diff --git a/test/compile_fail_virtual_ptr_ref_to_value.cpp b/test/compile_fail_virtual_ptr_ref_to_value.cpp index 054dd7db..382de0d9 100644 --- a/test/compile_fail_virtual_ptr_ref_to_value.cpp +++ b/test/compile_fail_virtual_ptr_ref_to_value.cpp @@ -24,5 +24,6 @@ BOOST_OPENMETHOD_OVERRIDE(poke, (virtual_ptr), void) { int main() { Cat felix; poke(felix); + return 0; } diff --git a/test/compile_fail_virtual_ptr_shared_not_const.cpp b/test/compile_fail_virtual_ptr_shared_not_const.cpp index 25231f64..71a0027b 100644 --- a/test/compile_fail_virtual_ptr_shared_not_const.cpp +++ b/test/compile_fail_virtual_ptr_shared_not_const.cpp @@ -25,5 +25,6 @@ BOOST_OPENMETHOD_OVERRIDE(poke, (shared_virtual_ptr&), void) { int main() { Cat felix; poke(felix); + return 0; } diff --git a/test/compile_fail_virtual_ptr_value_to_ref.cpp b/test/compile_fail_virtual_ptr_value_to_ref.cpp index 78484a98..5f9880de 100644 --- a/test/compile_fail_virtual_ptr_value_to_ref.cpp +++ b/test/compile_fail_virtual_ptr_value_to_ref.cpp @@ -24,5 +24,6 @@ BOOST_OPENMETHOD_OVERRIDE(poke, (const virtual_ptr&), void) { int main() { Cat felix; poke(felix); + return 0; } diff --git a/test/compile_fail_virtual_ptr_virtual_any.cpp b/test/compile_fail_virtual_ptr_virtual_any.cpp index 7af7e946..b474512c 100644 --- a/test/compile_fail_virtual_ptr_virtual_any.cpp +++ b/test/compile_fail_virtual_ptr_virtual_any.cpp @@ -25,5 +25,6 @@ int main() { // deliberately not a registered class. virtual_std_any spot = Dog{"Spot"}; virtual_ptr p = spot; + return 0; } diff --git a/test/compile_fail_weak_ptr_parameter.cpp b/test/compile_fail_weak_ptr_parameter.cpp index 69c79f9a..2ff9031a 100644 --- a/test/compile_fail_weak_ptr_parameter.cpp +++ b/test/compile_fail_weak_ptr_parameter.cpp @@ -26,5 +26,6 @@ BOOST_OPENMETHOD_OVERRIDE(poke, (std::weak_ptr), void) { int main() { auto felix = std::make_shared(); poke(std::weak_ptr(felix)); + return 0; } diff --git a/test/compile_fail_weak_virtual_ptr_parameter.cpp b/test/compile_fail_weak_virtual_ptr_parameter.cpp index 99cb2d3b..4fb6de6a 100644 --- a/test/compile_fail_weak_virtual_ptr_parameter.cpp +++ b/test/compile_fail_weak_virtual_ptr_parameter.cpp @@ -26,5 +26,6 @@ BOOST_OPENMETHOD_OVERRIDE(poke, (weak_virtual_ptr), void) { int main() { auto felix = std::make_shared(); poke(weak_virtual_ptr(felix)); + return 0; } diff --git a/test/dynamic_loading/method.hpp b/test/dynamic_loading/method.hpp index c11623e8..d2cadca0 100644 --- a/test/dynamic_loading/method.hpp +++ b/test/dynamic_loading/method.hpp @@ -24,7 +24,7 @@ BOOST_OPENMETHOD(speak, (boost::openmethod::virtual_ptr), const char*); BOOST_OPENMETHOD( meet, (boost::openmethod::virtual_ptr, - boost::openmethod::virtual_ptr), + boost::openmethod::virtual_ptr), greeting); inline auto call_speak(boost::openmethod::virtual_ptr animal) { diff --git a/test/dynamic_loading/overrider.cpp b/test/dynamic_loading/overrider.cpp index 23788cf3..d3ca07a3 100644 --- a/test/dynamic_loading/overrider.cpp +++ b/test/dynamic_loading/overrider.cpp @@ -27,6 +27,7 @@ BOOST_OPENMETHOD_OVERRIDE(speak, (virtual_ptr), const char*) { BOOST_OPENMETHOD_OVERRIDE( meet, (virtual_ptr a, virtual_ptr b), greeting) { std::string next_word = has_next() ? next(a, b).first : "n/a"; + return {"wag tails", next_word}; } diff --git a/test/implicit_shared_libraries/custom_registry/registry.hpp b/test/implicit_shared_libraries/custom_registry/registry.hpp index 1a3bcd9d..c8532465 100644 --- a/test/implicit_shared_libraries/custom_registry/registry.hpp +++ b/test/implicit_shared_libraries/custom_registry/registry.hpp @@ -25,20 +25,19 @@ struct custom_registry; // // std_rtti, vptr_map<>, default_error_handler, stderr_output struct custom_registry : - boost::openmethod::default_registry:: - with>::without< - boost::openmethod::policies::type_hash> {}; + boost::openmethod::default_registry::with>::without {}; // Both removals above happen implicitly, by category, so assert them. static_assert(boost::mp11::mp_contains< - custom_registry::policy_list, - boost::openmethod::policies::vptr_map<>>::value); + custom_registry::policy_list, + boost::openmethod::policies::vptr_map<>>::value); static_assert(!boost::mp11::mp_contains< - custom_registry::policy_list, - boost::openmethod::policies::vptr_vector>::value); + custom_registry::policy_list, + boost::openmethod::policies::vptr_vector>::value); static_assert(!boost::mp11::mp_contains< - custom_registry::policy_list, - boost::openmethod::policies::fast_perfect_hash>::value); + custom_registry::policy_list, + boost::openmethod::policies::fast_perfect_hash>::value); // Where each macro goes: // diff --git a/test/test_adl_registry.cpp b/test/test_adl_registry.cpp index 28da4755..ad20edb0 100644 --- a/test/test_adl_registry.cpp +++ b/test/test_adl_registry.cpp @@ -141,12 +141,11 @@ static_assert(std::is_same_v, kennel_registry>); BOOST_OPENMETHOD(speak, (virtual_), std::string); BOOST_OPENMETHOD(poke, (virtual_ptr), std::string); -static_assert( - std::is_same_v< - BOOST_OPENMETHOD_TYPE(speak, (virtual_), std::string), - method< - BOOST_OPENMETHOD_ID(speak), std::string(virtual_), - zoo_registry>>); +static_assert(std::is_same_v< + BOOST_OPENMETHOD_TYPE(speak, (virtual_), std::string), + method< + BOOST_OPENMETHOD_ID(speak), std::string(virtual_), + zoo_registry>>); BOOST_OPENMETHOD_OVERRIDE(speak, (const Dog&), std::string) { return "bark"; diff --git a/test/test_adl_registry_inplace.cpp b/test/test_adl_registry_inplace.cpp index 78b9f87d..479ccbcf 100644 --- a/test/test_adl_registry_inplace.cpp +++ b/test/test_adl_registry_inplace.cpp @@ -35,11 +35,10 @@ static_assert(std::is_same_v, zoo_registry>); BOOST_OPENMETHOD(speak, (bom::virtual_), std::string); static_assert(std::is_same_v< - BOOST_OPENMETHOD_TYPE( - speak, (bom::virtual_), std::string), - bom::method< - BOOST_OPENMETHOD_ID(speak), - std::string(bom::virtual_), zoo_registry>>); + BOOST_OPENMETHOD_TYPE(speak, (bom::virtual_), std::string), + bom::method< + BOOST_OPENMETHOD_ID(speak), std::string(bom::virtual_), + zoo_registry>>); BOOST_OPENMETHOD_OVERRIDE(speak, (const Dog&), std::string) { return "bark"; diff --git a/test/test_adl_registry_scan.cpp b/test/test_adl_registry_scan.cpp index 8779c425..f79b435e 100644 --- a/test/test_adl_registry_scan.cpp +++ b/test/test_adl_registry_scan.cpp @@ -60,31 +60,28 @@ static_assert(std::is_same_v, default_registry>); // Mixing a class that declares an affinity with one that does not: the latter // yields. This is what keeps a first affinity from cascading errors. static_assert(std::is_same_v< - scan, virtual_)>, - zoo_registry>); + scan, virtual_)>, + zoo_registry>); static_assert(std::is_same_v< - scan, virtual_)>, - zoo_registry>); + scan, virtual_)>, + zoo_registry>); // Mixed shapes agreeing. -static_assert( - std::is_same_v< - scan, virtual_)>, zoo_registry>); +static_assert(std::is_same_v< + scan, virtual_)>, zoo_registry>); // Non-virtual parameters are ignored. static_assert(std::is_same_v< - scan, char*)>, zoo_registry>); + scan, char*)>, zoo_registry>); // A registry spelled on a parameter is what that parameter carries, whatever // its class declares - so it decides the method's registry on its own. static_assert(std::is_same_v< - scan)>, other_registry>); -static_assert( - std::is_same_v< - scan)>, other_registry>); + scan)>, other_registry>); static_assert(std::is_same_v< - scan)>, - default_registry>); + scan)>, other_registry>); +static_assert(std::is_same_v< + scan)>, default_registry>); // Two carriers that disagree are an error; see // compile_fail_method_conflicting_carriers.cpp. @@ -100,9 +97,9 @@ static_assert( std::is_same_v)>, zoo_registry>); static_assert(std::is_same_v)>, zoo_registry>); static_assert(std::is_same_v< - scan)>, zoo_registry>); + scan)>, zoo_registry>); static_assert(std::is_same_v< - scan)>, zoo_registry>); + scan)>, zoo_registry>); static_assert( std::is_same_v)>, default_registry>); @@ -112,28 +109,24 @@ static_assert( // An adopter and a carrier: the carrier decides, whichever order. static_assert(std::is_same_v< - scan, virtual_ptr)>, - zoo_registry>); + scan, virtual_ptr)>, zoo_registry>); static_assert(std::is_same_v< - scan, virtual_)>, - zoo_registry>); + scan, virtual_)>, zoo_registry>); static_assert(std::is_same_v< - scan, virtual_ptr)>, - default_registry>); + scan, virtual_ptr)>, + default_registry>); // Two carriers that agree, in either shape. -static_assert( - std::is_same_v< - scan, virtual_ptr)>, zoo_registry>); -static_assert( - std::is_same_v< - scan, virtual_)>, - zoo_registry>); +static_assert(std::is_same_v< + scan, virtual_ptr)>, zoo_registry>); +static_assert(std::is_same_v< + scan, virtual_)>, + zoo_registry>); // Two adopters: still the macro default. static_assert(std::is_same_v< - scan, virtual_)>, - default_registry>); + scan, virtual_)>, + default_registry>); // An affinity declared for the default registry itself is declared all the // same: it constrains, see compile_fail_adl_registry_pinned_default.cpp. @@ -142,27 +135,26 @@ struct Pinned { friend auto boost_openmethod_registry(Pinned*) -> default_registry; }; -static_assert( - std::is_same_v< - detail::registry_affinity_aux::declared, default_registry>); +static_assert(std::is_same_v< + detail::registry_affinity_aux::declared, default_registry>); // A class that declares nothing carries nothing: `void`, the sentinel that // makes a `virtual_` parameter adopt the method's registry. static_assert( std::is_same_v::declared, void>); static_assert(std::is_same_v< - detail::param_registry>::type, void>); + detail::param_registry>::type, void>); // A registry named on the declaration wins, and the parameters are not // consulted at all - the form that predates this feature. BOOST_OPENMETHOD(ping, (virtual_), std::string, other_registry); static_assert(std::is_same_v< - BOOST_OPENMETHOD_TYPE( - ping, (virtual_), std::string, other_registry), - method< - BOOST_OPENMETHOD_ID(ping), - std::string(virtual_), other_registry>>); + BOOST_OPENMETHOD_TYPE( + ping, (virtual_), std::string, other_registry), + method< + BOOST_OPENMETHOD_ID(ping), std::string(virtual_), + other_registry>>); BOOST_AUTO_TEST_CASE(scan_is_compile_time_only) { BOOST_TEST(true); diff --git a/test/test_adl_registry_smart_ptr.cpp b/test/test_adl_registry_smart_ptr.cpp index b51d4454..35ab94c6 100644 --- a/test/test_adl_registry_smart_ptr.cpp +++ b/test/test_adl_registry_smart_ptr.cpp @@ -47,18 +47,16 @@ static_assert( static_assert( std::is_same_v>, zoo_registry>); static_assert(std::is_same_v< - registry_affinity&>, zoo_registry>); + registry_affinity&>, zoo_registry>); // so the alias and the type it stands for are the same type static_assert(std::is_same_v< - shared_virtual_ptr, - virtual_ptr, zoo_registry>>); + shared_virtual_ptr, virtual_ptr, zoo_registry>>); static_assert(std::is_same_v< - unique_virtual_ptr, - virtual_ptr, zoo_registry>>); + unique_virtual_ptr, virtual_ptr, zoo_registry>>); static_assert(std::is_same_v< - boost_intrusive_virtual_ptr, - virtual_ptr, zoo_registry>>); + boost_intrusive_virtual_ptr, + virtual_ptr, zoo_registry>>); // weak_virtual_ptr is not a virtual_ptr, but it defaults its registry the // same way, so it converts to and from the shared_virtual_ptr of its class diff --git a/test/test_adl_registry_two_registries.cpp b/test/test_adl_registry_two_registries.cpp index 66ffd276..3b8bc77f 100644 --- a/test/test_adl_registry_two_registries.cpp +++ b/test/test_adl_registry_two_registries.cpp @@ -49,19 +49,18 @@ BOOST_OPENMETHOD(describe, (virtual_), std::string); BOOST_OPENMETHOD(inspect, (virtual_), std::string); static_assert(std::is_same_v< - BOOST_OPENMETHOD_TYPE( - describe, (virtual_), std::string), - method< - BOOST_OPENMETHOD_ID(describe), - std::string(virtual_), zoo_registry>>); - -static_assert( - std::is_same_v< - BOOST_OPENMETHOD_TYPE( - inspect, (virtual_), std::string), - method< - BOOST_OPENMETHOD_ID(inspect), - std::string(virtual_), garage_registry>>); + BOOST_OPENMETHOD_TYPE( + describe, (virtual_), std::string), + method< + BOOST_OPENMETHOD_ID(describe), + std::string(virtual_), zoo_registry>>); + +static_assert(std::is_same_v< + BOOST_OPENMETHOD_TYPE( + inspect, (virtual_), std::string), + method< + BOOST_OPENMETHOD_ID(inspect), + std::string(virtual_), garage_registry>>); BOOST_OPENMETHOD_OVERRIDE(describe, (const zoo::Dog&), std::string) { return "a dog"; diff --git a/test/test_core.cpp b/test/test_core.cpp index 7f6c8408..0a639bb4 100644 --- a/test/test_core.cpp +++ b/test/test_core.cpp @@ -34,95 +34,85 @@ struct e : base {}; struct f : base {}; static_assert(std::is_same_v< - virtual_traits::virtual_type, base>); + virtual_traits::virtual_type, base>); -static_assert( - std::is_same_v< - virtual_traits::virtual_type, base>); +static_assert(std::is_same_v< + virtual_traits::virtual_type, base>); static_assert(std::is_same_v< - virtual_traits::virtual_type, base>); + virtual_traits::virtual_type, base>); static_assert(std::is_same_v< - mp11::mp_filter< - is_virtual, mp11::mp_list, b, virtual_>>, - mp11::mp_list, virtual_>>); + mp11::mp_filter, b, virtual_>>, + mp11::mp_list, virtual_>>); static_assert(std::is_same_v>, a&>); static_assert(std::is_same_v, a>); -static_assert( - std::is_same_v< - virtual_types>, b, virtual_>>>, - mp11::mp_list, std::shared_ptr>>); +static_assert(std::is_same_v< + virtual_types>, b, virtual_>>>, + mp11::mp_list, std::shared_ptr>>); static_assert(std::is_same_v< - overrider_virtual_types< - mp11::mp_list, b, virtual_>, - mp11::mp_list, default_registry>, - mp11::mp_list>); + overrider_virtual_types< + mp11::mp_list, b, virtual_>, mp11::mp_list, + default_registry>, + mp11::mp_list>); static_assert( std::is_same_v, default_registry>, a>); -static_assert( - std::is_same_v< - virtual_traits, default_registry>::virtual_type, a>); +static_assert(std::is_same_v< + virtual_traits, default_registry>::virtual_type, a>); static_assert(std::is_same_v< - select_overrider_virtual_type_aux< - virtual_ptr, virtual_ptr, default_registry>::type, - a>); + select_overrider_virtual_type_aux< + virtual_ptr, virtual_ptr, default_registry>::type, + a>); -static_assert( - std::is_same_v< - overrider_virtual_types< - mp11::mp_list, b, virtual_ptr>, - mp11::mp_list, e, virtual_ptr>, default_registry>, - mp11::mp_list>); +static_assert(std::is_same_v< + overrider_virtual_types< + mp11::mp_list, b, virtual_ptr>, + mp11::mp_list, e, virtual_ptr>, default_registry>, + mp11::mp_list>); -static_assert( - std::is_same_v< - overrider_virtual_types< - mp11::mp_list< - const virtual_ptr&, b, const virtual_ptr&>, - mp11::mp_list&, e, const virtual_ptr&>, - default_registry>, - mp11::mp_list>); +static_assert(std::is_same_v< + overrider_virtual_types< + mp11::mp_list&, b, const virtual_ptr&>, + mp11::mp_list&, e, const virtual_ptr&>, + default_registry>, + mp11::mp_list>); -static_assert( - std::is_same_v< - overrider_virtual_types< - mp11::mp_list< - virtual_>, b, virtual_>>, - mp11::mp_list, e, std::shared_ptr>, - default_registry>, - mp11::mp_list>); +static_assert(std::is_same_v< + overrider_virtual_types< + mp11::mp_list< + virtual_>, b, virtual_>>, + mp11::mp_list, e, std::shared_ptr>, + default_registry>, + mp11::mp_list>); static_assert(std::is_same_v< - mp11::mp_transform< - remove_virtual_, mp11::mp_list, virtual_>>, - mp11::mp_list>); + mp11::mp_transform< + remove_virtual_, mp11::mp_list, virtual_>>, + mp11::mp_list>); -static_assert( - std::is_same_v< - mp11::mp_transform_q< - mp11::mp_bind_back, - mp11::mp_transform< - remove_virtual_, mp11::mp_list, virtual_>>>, - mp11::mp_list>); +static_assert(std::is_same_v< + mp11::mp_transform_q< + mp11::mp_bind_back, + mp11::mp_transform< + remove_virtual_, mp11::mp_list, virtual_>>>, + mp11::mp_list>); -static_assert( - std::is_same_v< - mp11::mp_transform_q< - mp11::mp_bind_back, - mp11::mp_transform< - remove_virtual_, - mp11::mp_filter< - is_virtual, mp11::mp_list, b, virtual_>>>>, - mp11::mp_list>); +static_assert(std::is_same_v< + mp11::mp_transform_q< + mp11::mp_bind_back, + mp11::mp_transform< + remove_virtual_, + mp11::mp_filter< + is_virtual, mp11::mp_list, b, virtual_>>>>, + mp11::mp_list>); using registry1 = test_registry_<__COUNTER__>; using registry2 = test_registry_<__COUNTER__>; @@ -135,8 +125,8 @@ auto boost_openmethod_vptr(const non_polymorphic_inplace_vptr&, void*) // clang-format on static_assert(std::is_same_v< - virtual_types, b, virtual_>>, - mp11::mp_list>); + virtual_types, b, virtual_>>, + mp11::mp_list>); static_assert(detail::is_registry); @@ -205,28 +195,28 @@ BOOST_AUTO_TEST_CASE(casts) { BOOST_TEST( (&virtual_traits::cast( - animal) - .m) == &dog.m); + animal) + .m) == &dog.m); BOOST_TEST( (&virtual_traits::cast< - const Carnivore&>(animal) - .c) == &dog.c); + const Carnivore&>(animal) + .c) == &dog.c); BOOST_TEST( (&virtual_traits::cast( - animal) - .m) == &dog.m); + animal) + .m) == &dog.m); BOOST_TEST( (&virtual_traits::cast( - animal) - .d) == &dog.d); + animal) + .d) == &dog.d); BOOST_TEST( (&virtual_traits::cast( - mammal) - .d) == &dog.d); + mammal) + .d) == &dog.d); BOOST_TEST( (&virtual_traits::cast( - carnivore) - .c) == &dog.c); + carnivore) + .c) == &dog.c); using virtual_animal_t = virtual_type; static_assert(std::is_same_v, "animal"); @@ -244,26 +234,24 @@ struct Bulldog : public Dog {}; struct Cat : public Animal {}; struct Dolphin : public Animal {}; -static_assert( - std::is_same_v< - inheritance_map, - mp11::mp_list< - mp11::mp_list, mp11::mp_list, - mp11::mp_list, - mp11::mp_list, - mp11::mp_list>>); +static_assert(std::is_same_v< + inheritance_map, + mp11::mp_list< + mp11::mp_list, mp11::mp_list, + mp11::mp_list, + mp11::mp_list, + mp11::mp_list>>); -static_assert( - std::is_same_v< - detail::use_classes_tuple_type, - detail::tuple< - use_class_aux>, - use_class_aux>, - use_class_aux< - default_registry, mp11::mp_list>, - use_class_aux>, - use_class_aux< - default_registry, mp11::mp_list>>>); +static_assert(std::is_same_v< + detail::use_classes_tuple_type, + detail::tuple< + use_class_aux>, + use_class_aux>, + use_class_aux< + default_registry, mp11::mp_list>, + use_class_aux>, + use_class_aux< + default_registry, mp11::mp_list>>>); } // namespace test_use_classes diff --git a/test/test_custom_rtti_deferred.cpp b/test/test_custom_rtti_deferred.cpp index 6ba8a4fd..1d52087f 100644 --- a/test/test_custom_rtti_deferred.cpp +++ b/test/test_custom_rtti_deferred.cpp @@ -19,12 +19,14 @@ constexpr std::size_t non_polymorphic_high_bit = std::size_t(1) inline std::size_t next_non_polymorphic_id() { static std::size_t counter = 0; + return non_polymorphic_high_bit | ++counter; } template inline std::size_t non_polymorphic_static_type() { static std::size_t value = next_non_polymorphic_id(); + return value; } } // anonymous namespace @@ -49,6 +51,7 @@ struct Animal { template auto custom_dynamic_cast(Base& obj) -> Derived { using derived_type = std::remove_cv_t>; + return *reinterpret_cast( const_cast&>(obj).cast_aux( derived_type::static_type)); @@ -129,8 +132,9 @@ struct custom_rtti : boost::openmethod::policies::deferred_static_rtti { template static void type_name(boost::openmethod::type_id type, Stream& stream) { - static const char* name[] = {"?", "Animal", "Dog", - "Cat", "Bat", "Owl"}; + static const char* name[] = { + "?", "Animal", "Dog", "Cat", "Bat", "Owl" + }; auto idx = reinterpret_cast(type); stream << (idx >= 1 && idx <= 5 ? name[idx] : "?"); } @@ -160,11 +164,11 @@ BOOST_OPENMETHOD_TEST_CLASSES(Animal, Dog, Cat, Bat, Owl); BOOST_OPENMETHOD(poke, (virtual_, std::ostream&), void); -BOOST_OPENMETHOD_OVERRIDE(poke, (Dog & dog, std::ostream& os), void) { +BOOST_OPENMETHOD_OVERRIDE(poke, (Dog& dog, std::ostream& os), void) { os << dog.name << " barks."; } -BOOST_OPENMETHOD_OVERRIDE(poke, (Cat & cat, std::ostream& os), void) { +BOOST_OPENMETHOD_OVERRIDE(poke, (Cat& cat, std::ostream& os), void) { os << cat.name << " hisses."; } @@ -179,11 +183,11 @@ BOOST_OPENMETHOD_OVERRIDE(meet, (Dog&, Dog&, std::ostream& os), void) { // `dynamic_cast_ref` rather than a static_cast - with type ids that are only // assigned during static construction. -BOOST_OPENMETHOD_OVERRIDE(poke, (Bat & bat, std::ostream& os), void) { +BOOST_OPENMETHOD_OVERRIDE(poke, (Bat& bat, std::ostream& os), void) { os << bat.name << " screeches."; } -BOOST_OPENMETHOD_OVERRIDE(poke, (Owl & owl, std::ostream& os), void) { +BOOST_OPENMETHOD_OVERRIDE(poke, (Owl& owl, std::ostream& os), void) { os << owl.name << " hoots."; } diff --git a/test/test_custom_rtti_simple.cpp b/test/test_custom_rtti_simple.cpp index 75c8f4d0..712ab871 100644 --- a/test/test_custom_rtti_simple.cpp +++ b/test/test_custom_rtti_simple.cpp @@ -19,12 +19,14 @@ constexpr std::size_t non_polymorphic_high_bit = std::size_t(1) inline std::size_t next_non_polymorphic_id() { static std::size_t counter = 0; + return non_polymorphic_high_bit | ++counter; } template inline std::size_t non_polymorphic_static_type() { static std::size_t value = next_non_polymorphic_id(); + return value; } } // anonymous namespace @@ -106,11 +108,11 @@ BOOST_OPENMETHOD_TEST_CLASSES(Animal, Dog, Cat); BOOST_OPENMETHOD(poke, (virtual_, std::ostream&), void); -BOOST_OPENMETHOD_OVERRIDE(poke, (Dog & dog, std::ostream& os), void) { +BOOST_OPENMETHOD_OVERRIDE(poke, (Dog& dog, std::ostream& os), void) { os << dog.name << " barks."; } -BOOST_OPENMETHOD_OVERRIDE(poke, (Cat & cat, std::ostream& os), void) { +BOOST_OPENMETHOD_OVERRIDE(poke, (Cat& cat, std::ostream& os), void) { os << cat.name << " hisses."; } diff --git a/test/test_custom_rtti_simple_projection.cpp b/test/test_custom_rtti_simple_projection.cpp index e8fcd358..45a30da9 100644 --- a/test/test_custom_rtti_simple_projection.cpp +++ b/test/test_custom_rtti_simple_projection.cpp @@ -92,11 +92,11 @@ BOOST_OPENMETHOD_TEST_CLASSES(Animal, Dog, Cat); BOOST_OPENMETHOD(poke, (virtual_, std::ostream&), void); -BOOST_OPENMETHOD_OVERRIDE(poke, (Dog & dog, std::ostream& os), void) { +BOOST_OPENMETHOD_OVERRIDE(poke, (Dog& dog, std::ostream& os), void) { os << dog.name << " barks."; } -BOOST_OPENMETHOD_OVERRIDE(poke, (Cat & cat, std::ostream& os), void) { +BOOST_OPENMETHOD_OVERRIDE(poke, (Cat& cat, std::ostream& os), void) { os << cat.name << " hisses."; } diff --git a/test/test_custom_rtti_virtual_base.cpp b/test/test_custom_rtti_virtual_base.cpp index dd337048..23a1afc3 100644 --- a/test/test_custom_rtti_virtual_base.cpp +++ b/test/test_custom_rtti_virtual_base.cpp @@ -19,12 +19,14 @@ constexpr std::size_t non_polymorphic_high_bit = std::size_t(1) inline std::size_t next_non_polymorphic_id() { static std::size_t counter = 0; + return non_polymorphic_high_bit | ++counter; } template inline std::size_t non_polymorphic_static_type() { static std::size_t value = next_non_polymorphic_id(); + return value; } } // anonymous namespace @@ -46,6 +48,7 @@ struct Animal { template auto custom_dynamic_cast(Base& obj) -> Derived { using derived_type = std::remove_cv_t>; + return *reinterpret_cast( const_cast&>(obj).cast_aux( derived_type::static_type)); @@ -131,11 +134,11 @@ BOOST_OPENMETHOD_TEST_CLASSES(Animal, Dog, Cat); BOOST_OPENMETHOD(poke, (virtual_, std::ostream&), void); -BOOST_OPENMETHOD_OVERRIDE(poke, (Dog & dog, std::ostream& os), void) { +BOOST_OPENMETHOD_OVERRIDE(poke, (Dog& dog, std::ostream& os), void) { os << dog.name << " barks."; } -BOOST_OPENMETHOD_OVERRIDE(poke, (Cat & cat, std::ostream& os), void) { +BOOST_OPENMETHOD_OVERRIDE(poke, (Cat& cat, std::ostream& os), void) { os << cat.name << " hisses."; } diff --git a/test/test_dispatch_boost_any.cpp b/test/test_dispatch_boost_any.cpp index 6f0d40de..e79cf8ef 100644 --- a/test/test_dispatch_boost_any.cpp +++ b/test/test_dispatch_boost_any.cpp @@ -29,20 +29,17 @@ namespace BOOST_OPENMETHOD_GENSYM { // pass virtual args as const boost::any& (const ref) static_assert(detail::has_vptr< - virtual_traits, - const boost::any&>); + virtual_traits, const boost::any&>); // A registry spelled on the parameter names the same parameter as the default // one, in each of the three forms. static_assert(detail::validate_method_parameter< - virtual_, default_registry, - void>::value); + virtual_, default_registry, + void>::value); static_assert(detail::validate_method_parameter< - virtual_, default_registry, - void>::value); + virtual_, default_registry, void>::value); static_assert(detail::validate_method_parameter< - virtual_, default_registry, - void>::value); + virtual_, default_registry, void>::value); MAKE_CLASSES(); @@ -59,6 +56,7 @@ BOOST_OPENMETHOD_OVERRIDE(name, (const std::string& name), std::string) { BOOST_OPENMETHOD_OVERRIDE(name, (const int& value), std::string) { std::ostringstream os; os << value << " the integer"; + return os.str(); } @@ -101,9 +99,8 @@ namespace BOOST_OPENMETHOD_GENSYM { // ----------------------------------------------------------------------------- // pass virtual args as boost::any& (mutable ref) -static_assert( - detail::has_vptr< - virtual_traits, const boost::any&>); +static_assert(detail::has_vptr< + virtual_traits, const boost::any&>); MAKE_CLASSES(); @@ -123,11 +120,13 @@ using bump_method = auto bump_dog(Dog& dog) -> std::string { dog.name += " Jr."; + return dog.name + " the dog"; } auto bump_string(std::string& name) -> std::string { name += "!"; + return name; } @@ -135,6 +134,7 @@ auto bump_int(int& value) -> std::string { ++value; std::ostringstream os; os << value << " the integer"; + return os.str(); } @@ -165,27 +165,29 @@ namespace BOOST_OPENMETHOD_GENSYM { // ----------------------------------------------------------------------------- // pass virtual args as boost::any&& (xvalue ref) -static_assert( - detail::has_vptr< - virtual_traits, const boost::any&>); +static_assert(detail::has_vptr< + virtual_traits, const boost::any&>); MAKE_CLASSES(); BOOST_OPENMETHOD(steal, (virtual_), std::string); -BOOST_OPENMETHOD_OVERRIDE(steal, (Dog && dog), std::string) { +BOOST_OPENMETHOD_OVERRIDE(steal, (Dog&& dog), std::string) { Dog stolen(std::move(dog)); + return stolen.name + " the dog"; } -BOOST_OPENMETHOD_OVERRIDE(steal, (std::string && name), std::string) { +BOOST_OPENMETHOD_OVERRIDE(steal, (std::string&& name), std::string) { std::string stolen(std::move(name)); + return stolen; } BOOST_OPENMETHOD_OVERRIDE(steal, (int&& value), std::string) { std::ostringstream os; os << value << " the integer"; + return os.str(); } @@ -252,6 +254,7 @@ using bump_method = auto bump_dog(Dog& dog) -> std::string { dog.name += " Jr."; + return dog.name + " the dog"; } @@ -264,8 +267,9 @@ BOOST_OPENMETHOD_REGISTER(bump_method::override); BOOST_OPENMETHOD(steal, (virtual_), std::string); -BOOST_OPENMETHOD_OVERRIDE(steal, (Dog && dog), std::string) { +BOOST_OPENMETHOD_OVERRIDE(steal, (Dog&& dog), std::string) { Dog stolen(std::move(dog)); + return stolen.name + " the dog"; } diff --git a/test/test_dispatch_minimal_cover_hash.cpp b/test/test_dispatch_minimal_cover_hash.cpp index 5fd79dd4..1cbcb9c3 100644 --- a/test/test_dispatch_minimal_cover_hash.cpp +++ b/test/test_dispatch_minimal_cover_hash.cpp @@ -64,29 +64,37 @@ struct Ghost : Animal {}; // and do not call BOOST_OPENMETHOD_REGISTER_CLASSES - see test_classes.hpp. BOOST_OPENMETHOD_CLASSES(Animal, Dog, Cat, Bulldog, Tiger); -BOOST_OPENMETHOD(name, (virtual_), std::string); -BOOST_OPENMETHOD_OVERRIDE(name, (const Animal&), std::string) { +BOOST_OPENMETHOD( +name,(virtual_), std::string); +BOOST_OPENMETHOD_OVERRIDE( +name,(const Animal&), std::string) { return "animal"; } -BOOST_OPENMETHOD_OVERRIDE(name, (const Dog&), std::string) { +BOOST_OPENMETHOD_OVERRIDE( +name,(const Dog&), std::string) { return "dog"; } -BOOST_OPENMETHOD_OVERRIDE(name, (const Cat&), std::string) { +BOOST_OPENMETHOD_OVERRIDE( +name,(const Cat&), std::string) { return "cat"; } -BOOST_OPENMETHOD_OVERRIDE(name, (const Bulldog&), std::string) { +BOOST_OPENMETHOD_OVERRIDE( +name,(const Bulldog&), std::string) { return "bulldog"; } BOOST_OPENMETHOD( - meet, (virtual_, virtual_), std::string); -BOOST_OPENMETHOD_OVERRIDE(meet, (const Animal&, const Animal&), std::string) { +meet,(virtual_, virtual_), std::string); +BOOST_OPENMETHOD_OVERRIDE( +meet,(const Animal&, const Animal&), std::string) { return "ignore"; } -BOOST_OPENMETHOD_OVERRIDE(meet, (const Dog&, const Cat&), std::string) { +BOOST_OPENMETHOD_OVERRIDE( +meet,(const Dog&, const Cat&), std::string) { return "chase"; } -BOOST_OPENMETHOD_OVERRIDE(meet, (const Cat&, const Dog&), std::string) { +BOOST_OPENMETHOD_OVERRIDE( +meet,(const Cat&, const Dog&), std::string) { return "hiss"; } @@ -121,9 +129,10 @@ BOOST_AUTO_TEST_CASE(hash_is_injective) { std::set seen; - for (auto type : - {&typeid(Animal), &typeid(Dog), &typeid(Cat), &typeid(Bulldog), - &typeid(Tiger)}) { + for ( + auto type : + {&typeid(Animal), &typeid(Dog), &typeid(Cat), &typeid(Bulldog), + &typeid(Tiger)}) { auto index = type_hash::hash(type); BOOST_TEST(index >= low); BOOST_TEST(index <= high); diff --git a/test/test_dispatch_minimal_perfect_hash.cpp b/test/test_dispatch_minimal_perfect_hash.cpp index 25cdb92c..c107c599 100644 --- a/test/test_dispatch_minimal_perfect_hash.cpp +++ b/test/test_dispatch_minimal_perfect_hash.cpp @@ -106,9 +106,10 @@ BOOST_AUTO_TEST_CASE(hash_is_injective_and_minimal) { std::set seen; - for (auto type : - {&typeid(Animal), &typeid(Dog), &typeid(Cat), &typeid(Bulldog), - &typeid(Tiger)}) { + for ( + auto type : + {&typeid(Animal), &typeid(Dog), &typeid(Cat), &typeid(Bulldog), + &typeid(Tiger)}) { auto index = type_hash::hash(type); BOOST_TEST(index >= low); BOOST_TEST(index <= high); diff --git a/test/test_dispatch_rvalue_refs.cpp b/test/test_dispatch_rvalue_refs.cpp index 7ce3cefd..8a1255cb 100644 --- a/test/test_dispatch_rvalue_refs.cpp +++ b/test/test_dispatch_rvalue_refs.cpp @@ -20,11 +20,11 @@ BOOST_OPENMETHOD_TEST_CLASSES(Animal, Dog, Cat); BOOST_OPENMETHOD(teleport, (virtual_), std::unique_ptr); -BOOST_OPENMETHOD_OVERRIDE(teleport, (Cat && cat), std::unique_ptr) { +BOOST_OPENMETHOD_OVERRIDE(teleport, (Cat&& cat), std::unique_ptr) { return std::make_unique(std::move(cat)); } -BOOST_OPENMETHOD_OVERRIDE(teleport, (Dog && dog), std::unique_ptr) { +BOOST_OPENMETHOD_OVERRIDE(teleport, (Dog&& dog), std::unique_ptr) { return std::make_unique(std::move(dog)); } diff --git a/test/test_dispatch_std_any.cpp b/test/test_dispatch_std_any.cpp index b35c805e..0b6545af 100644 --- a/test/test_dispatch_std_any.cpp +++ b/test/test_dispatch_std_any.cpp @@ -28,21 +28,18 @@ namespace BOOST_OPENMETHOD_GENSYM { // ----------------------------------------------------------------------------- // pass virtual args as const std::any& (const ref) -static_assert( - detail::has_vptr< - virtual_traits, const std::any&>); +static_assert(detail::has_vptr< + virtual_traits, const std::any&>); // A registry spelled on the parameter names the same parameter as the default // one, in each of the three forms. static_assert(detail::validate_method_parameter< - virtual_, default_registry, - void>::value); -static_assert( - detail::validate_method_parameter< - virtual_, default_registry, void>::value); -static_assert( - detail::validate_method_parameter< - virtual_, default_registry, void>::value); + virtual_, default_registry, + void>::value); +static_assert(detail::validate_method_parameter< + virtual_, default_registry, void>::value); +static_assert(detail::validate_method_parameter< + virtual_, default_registry, void>::value); MAKE_CLASSES(); @@ -59,6 +56,7 @@ BOOST_OPENMETHOD_OVERRIDE(name, (const std::string& name), std::string) { BOOST_OPENMETHOD_OVERRIDE(name, (const int& value), std::string) { std::ostringstream os; os << value << " the integer"; + return os.str(); } @@ -102,7 +100,7 @@ namespace BOOST_OPENMETHOD_GENSYM { // pass virtual args as std::any& (mutable ref) static_assert(detail::has_vptr< - virtual_traits, const std::any&>); + virtual_traits, const std::any&>); MAKE_CLASSES(); @@ -122,11 +120,13 @@ using bump_method = auto bump_dog(Dog& dog) -> std::string { dog.name += " Jr."; + return dog.name + " the dog"; } auto bump_string(std::string& name) -> std::string { name += "!"; + return name; } @@ -134,6 +134,7 @@ auto bump_int(int& value) -> std::string { ++value; std::ostringstream os; os << value << " the integer"; + return os.str(); } @@ -165,25 +166,28 @@ namespace BOOST_OPENMETHOD_GENSYM { // pass virtual args as std::any&& (xvalue ref) static_assert(detail::has_vptr< - virtual_traits, const std::any&>); + virtual_traits, const std::any&>); MAKE_CLASSES(); BOOST_OPENMETHOD(steal, (virtual_), std::string); -BOOST_OPENMETHOD_OVERRIDE(steal, (Dog && dog), std::string) { +BOOST_OPENMETHOD_OVERRIDE(steal, (Dog&& dog), std::string) { Dog stolen(std::move(dog)); + return stolen.name + " the dog"; } -BOOST_OPENMETHOD_OVERRIDE(steal, (std::string && name), std::string) { +BOOST_OPENMETHOD_OVERRIDE(steal, (std::string&& name), std::string) { std::string stolen(std::move(name)); + return stolen; } BOOST_OPENMETHOD_OVERRIDE(steal, (int&& value), std::string) { std::ostringstream os; os << value << " the integer"; + return os.str(); } @@ -250,6 +254,7 @@ using bump_method = auto bump_dog(Dog& dog) -> std::string { dog.name += " Jr."; + return dog.name + " the dog"; } @@ -262,8 +267,9 @@ BOOST_OPENMETHOD_REGISTER(bump_method::override); BOOST_OPENMETHOD(steal, (virtual_), std::string); -BOOST_OPENMETHOD_OVERRIDE(steal, (Dog && dog), std::string) { +BOOST_OPENMETHOD_OVERRIDE(steal, (Dog&& dog), std::string) { Dog stolen(std::move(dog)); + return stolen.name + " the dog"; } diff --git a/test/test_dispatch_two_level_hash.cpp b/test/test_dispatch_two_level_hash.cpp index 5a3343e5..759653fd 100644 --- a/test/test_dispatch_two_level_hash.cpp +++ b/test/test_dispatch_two_level_hash.cpp @@ -106,9 +106,10 @@ BOOST_AUTO_TEST_CASE(hash_is_injective_and_minimal) { std::set seen; - for (auto type : - {&typeid(Animal), &typeid(Dog), &typeid(Cat), &typeid(Bulldog), - &typeid(Tiger)}) { + for ( + auto type : + {&typeid(Animal), &typeid(Dog), &typeid(Cat), &typeid(Bulldog), + &typeid(Tiger)}) { auto index = type_hash::hash(type); BOOST_TEST(index >= low); BOOST_TEST(index <= high); diff --git a/test/test_dispatch_type_erasure.cpp b/test/test_dispatch_type_erasure.cpp index 9554aa24..7da956d8 100644 --- a/test/test_dispatch_type_erasure.cpp +++ b/test/test_dispatch_type_erasure.cpp @@ -28,25 +28,20 @@ using erased_ref = te::any; using erased_cref = te::any; static_assert(detail::has_vptr< - virtual_traits, const erased&>); + virtual_traits, const erased&>); // A registry spelled on the parameter names the same parameter as the default // one, for the owning any by reference and for the any references. static_assert(detail::validate_method_parameter< - virtual_, default_registry, - void>::value); -static_assert( - detail::validate_method_parameter< - virtual_, default_registry, void>::value); -static_assert( - detail::validate_method_parameter< - virtual_, default_registry, void>::value); -static_assert( - detail::validate_method_parameter< - virtual_, default_registry, void>::value); + virtual_, default_registry, void>::value); static_assert(detail::validate_method_parameter< - virtual_, default_registry, - void>::value); + virtual_, default_registry, void>::value); +static_assert(detail::validate_method_parameter< + virtual_, default_registry, void>::value); +static_assert(detail::validate_method_parameter< + virtual_, default_registry, void>::value); +static_assert(detail::validate_method_parameter< + virtual_, default_registry, void>::value); #define MAKE_CLASSES() \ struct Dog { \ @@ -121,11 +116,13 @@ using bump_method = auto bump_dog(Dog& dog) -> std::string { dog.name += " Jr."; + return dog.name + " the dog"; } auto bump_int(int& value) -> std::string { ++value; + return "bumped"; } @@ -158,13 +155,15 @@ BOOST_OPENMETHOD(steal, (virtual_), std::string); // boost::type_erasure::any_cast has no rvalue overload; the trait moves // the result of a mutable-reference cast, because the `any` owns its // value. -BOOST_OPENMETHOD_OVERRIDE(steal, (Dog && dog), std::string) { +BOOST_OPENMETHOD_OVERRIDE(steal, (Dog&& dog), std::string) { Dog stolen(std::move(dog)); + return stolen.name + " the dog"; } -BOOST_OPENMETHOD_OVERRIDE(steal, (std::string && name), std::string) { +BOOST_OPENMETHOD_OVERRIDE(steal, (std::string&& name), std::string) { std::string stolen(std::move(name)); + return stolen; } @@ -193,13 +192,15 @@ MAKE_CLASSES(); BOOST_OPENMETHOD(poke, (virtual_), std::string); -BOOST_OPENMETHOD_OVERRIDE(poke, (Dog & dog), std::string) { +BOOST_OPENMETHOD_OVERRIDE(poke, (Dog& dog), std::string) { dog.name += "!"; + return dog.name; } BOOST_OPENMETHOD_OVERRIDE(poke, (int& value), std::string) { ++value; + return "poked"; } @@ -328,8 +329,9 @@ BOOST_OPENMETHOD_OVERRIDE(name, (const dispatchable& value), std::string) { BOOST_OPENMETHOD(poke, (virtual_), std::string); -BOOST_OPENMETHOD_OVERRIDE(poke, (Dog & dog), std::string) { +BOOST_OPENMETHOD_OVERRIDE(poke, (Dog& dog), std::string) { dog.name += "!"; + return dog.name; } diff --git a/test/test_hash_policies.cpp b/test/test_hash_policies.cpp index 215509cc..c2886fd3 100644 --- a/test/test_hash_policies.cpp +++ b/test/test_hash_policies.cpp @@ -216,11 +216,12 @@ struct mch_registry : // every injectivity count below come out short, for no fault of the policies. BOOST_AUTO_TEST_CASE(generators_produce_distinct_ids) { for (auto n : {std::size_t(1), std::size_t(17), std::size_t(1000)}) { - for (auto&& named : - {std::pair{"packed", ids_packed(n)}, - std::pair{"diluted", ids_diluted(n)}, - std::pair{"multi_module", ids_multi_module(n)}, - std::pair{"dlopened", ids_dlopened(n)}}) { + for ( + auto&& named : + {std::pair{"packed", ids_packed(n)}, + std::pair{"diluted", ids_diluted(n)}, + std::pair{"multi_module", ids_multi_module(n)}, + std::pair{"dlopened", ids_dlopened(n)}}) { BOOST_TEST_CONTEXT(named.first << ", n = " << n) { std::set distinct( named.second.begin(), named.second.end()); @@ -231,14 +232,16 @@ BOOST_AUTO_TEST_CASE(generators_produce_distinct_ids) { } BOOST_AUTO_TEST_CASE(injective_on_every_distribution) { - for (auto n : - {std::size_t(1), std::size_t(2), std::size_t(17), std::size_t(256), - std::size_t(1000)}) { - for (auto&& named : - {std::pair{"packed", ids_packed(n)}, - std::pair{"diluted", ids_diluted(n)}, - std::pair{"multi_module", ids_multi_module(n)}, - std::pair{"dlopened", ids_dlopened(n)}}) { + for ( + auto n : + {std::size_t(1), std::size_t(2), std::size_t(17), std::size_t(256), + std::size_t(1000)}) { + for ( + auto&& named : + {std::pair{"packed", ids_packed(n)}, + std::pair{"diluted", ids_diluted(n)}, + std::pair{"multi_module", ids_multi_module(n)}, + std::pair{"dlopened", ids_dlopened(n)}}) { BOOST_TEST_CONTEXT(named.first << ", n = " << n) { check_injective_over>( named.second); diff --git a/test/test_initialize_context.cpp b/test/test_initialize_context.cpp index f6980860..6a3dcd59 100644 --- a/test/test_initialize_context.cpp +++ b/test/test_initialize_context.cpp @@ -47,14 +47,12 @@ struct context_checks { using traits = std::iterator_traits; static_assert(std::is_same_v< - typename traits::iterator_category, - std::input_iterator_tag>); + typename traits::iterator_category, std::input_iterator_tag>); // Why it cannot be a forward iterator: `reference` is the value // type, so there is nothing for a second pass to refer back to. - static_assert( - std::is_same_v< - typename traits::reference, typename traits::value_type>); + static_assert(std::is_same_v< + typename traits::reference, typename traits::value_type>); auto& st = Registry::template state(); diff --git a/test/test_initialize_dropped_class.cpp b/test/test_initialize_dropped_class.cpp index 3ef579ad..4a61c4ed 100644 --- a/test/test_initialize_dropped_class.cpp +++ b/test/test_initialize_dropped_class.cpp @@ -75,12 +75,14 @@ namespace { // so they cannot inflate the vector. inline auto next_other_id() -> std::size_t { static std::size_t counter = 100; + return ++counter; } template inline auto other_static_type() -> std::size_t { static std::size_t value = next_other_id(); + return value; } diff --git a/test/test_initialize_transaction.cpp b/test/test_initialize_transaction.cpp index 29b8b078..188c2dd7 100644 --- a/test/test_initialize_transaction.cpp +++ b/test/test_initialize_transaction.cpp @@ -152,6 +152,7 @@ struct snapshot { BOOST_AUTO_TEST_CASE_TEMPLATE( failed_reinitialize_keeps_previous_state, Registry, registries<__COUNTER__>) { + using namespace detail; using explosive = typename explosive_policy::template fn< typename Registry::registry_type>; using vptr_state = typename snapshot::vptr_state; @@ -212,14 +213,13 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( (poke::template next> == before.next)); // Parenthesized for the same reason: Boost.Test cannot print hash factors // or vectors of type ids. - auto& hash = - detail::get::hash_state>(st.policies); + auto& hash = get::hash_state>(st.policies); BOOST_TEST((hash.fn.mult == before.hash().fn.mult)); BOOST_TEST((hash.fn.shift == before.hash().fn.shift)); BOOST_TEST((hash.fn.min_value == before.hash().fn.min_value)); BOOST_TEST((hash.fn.max_value == before.hash().fn.max_value)); BOOST_TEST((hash.control == before.hash().control)); - BOOST_TEST((detail::get(st.policies).vptrs == before.vptrs())); + BOOST_TEST((get(st.policies).vptrs == before.vptrs())); // ...including the state of the policy that threw, after writing to it. BOOST_TEST(Registry::template state().generation == 1); @@ -301,6 +301,7 @@ struct trapping_stream { inline auto operator<<(trapping_stream& os, const char* str) -> trapping_stream& { os.write(str); + return os; } @@ -419,6 +420,7 @@ BOOST_AUTO_TEST_CASE(a_throwing_report_does_not_commit) { BOOST_AUTO_TEST_CASE_TEMPLATE( failed_initialize_after_finalize_restores_what_it_found, Registry, registries<__COUNTER__>) { + using namespace detail; using explosive = typename explosive_policy::template fn< typename Registry::registry_type>; using vptr_state = typename snapshot::vptr_state; @@ -438,7 +440,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( finalize(); BOOST_TEST(!st.initialized); BOOST_TEST(st.dispatch_data.empty()); - BOOST_TEST(detail::get(st.policies).vptrs.empty()); + BOOST_TEST(get(st.policies).vptrs.empty()); // Not cleared by finalize, and so still set here. auto dog_vptr_after_finalize = Registry::template static_vptr; BOOST_TEST(dog_vptr_after_finalize != nullptr); @@ -451,7 +453,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( // consistent. BOOST_TEST(!st.initialized); BOOST_TEST(st.dispatch_data.empty()); - BOOST_TEST(detail::get(st.policies).vptrs.empty()); + BOOST_TEST(get(st.policies).vptrs.empty()); BOOST_TEST(Registry::template static_vptr == dog_vptr_after_finalize); // And a successful call still recovers from it. diff --git a/test/test_inplace_vptr.cpp b/test/test_inplace_vptr.cpp index d5dd37a5..a20facfd 100644 --- a/test/test_inplace_vptr.cpp +++ b/test/test_inplace_vptr.cpp @@ -59,7 +59,7 @@ BOOST_OPENMETHOD(describe, (virtual_ pet, std::ostream& os), void); BOOST_OPENMETHOD( meet, (virtual_>, - virtual_&>, std::ostream& os), + virtual_&>, std::ostream& os), void); BOOST_OPENMETHOD_OVERRIDE( diff --git a/test/test_n2216_covariant_return_type.cpp b/test/test_n2216_covariant_return_type.cpp index a1271d66..0e66fcd8 100644 --- a/test/test_n2216_covariant_return_type.cpp +++ b/test/test_n2216_covariant_return_type.cpp @@ -35,8 +35,7 @@ BOOST_OPENMETHOD_OVERRIDE( } static_assert(std::is_same_v< - detail::virtual_type, default_registry>, - matrix>); + detail::virtual_type, default_registry>, matrix>); BOOST_AUTO_TEST_CASE(covariant_return_type) { auto compiler = boost::openmethod::initialize(n2216()); diff --git a/test/test_namespaces.cpp b/test/test_namespaces.cpp index a7a6ad2a..38a328ca 100644 --- a/test/test_namespaces.cpp +++ b/test/test_namespaces.cpp @@ -50,7 +50,7 @@ BOOST_OPENMETHOD_OVERRIDE(poke, (Dog&), std::string) { } // implement 'poke' for bulldogs -BOOST_OPENMETHOD_OVERRIDE(poke, (Bulldog & dog), std::string) { +BOOST_OPENMETHOD_OVERRIDE(poke, (Bulldog& dog), std::string) { return next(dog) + " and bite"; } } // namespace canis diff --git a/test/test_policies.cpp b/test/test_policies.cpp index 2392de05..46ed8962 100644 --- a/test/test_policies.cpp +++ b/test/test_policies.cpp @@ -32,7 +32,7 @@ struct derived : base { }; static_assert(std::is_same_v< - registry::policy, derived::fn>>); + registry::policy, derived::fn>>); static_assert(detail::is_registry); @@ -59,9 +59,9 @@ struct bar2 : bar {}; static_assert(std::is_same_v::with, registry>); static_assert(std::is_same_v::with, registry>); static_assert(std::is_same_v< - registry::with, registry>); + registry::with, registry>); static_assert(std::is_same_v< - registry::with, registry>); + registry::with, registry>); static_assert( std::is_same_v::without, registry>); @@ -75,28 +75,27 @@ BOOST_AUTO_TEST_CASE(test_registry) { } static_assert(has_initialize< - vptr_vector::fn, registry1::compiler>, - std::tuple<>>); + vptr_vector::fn, registry1::compiler>, + std::tuple<>>); static_assert(!has_initialize< - std_rtti::fn, registry1::compiler>, - std::tuple<>>); + std_rtti::fn, registry1::compiler>, std::tuple<>>); static_assert(has_initialize< - fast_perfect_hash::fn, - registry1::compiler>, std::tuple<>>); + fast_perfect_hash::fn, registry1::compiler>, + std::tuple<>>); // The alternative `type_hash` policies conform to the same blueprint. Each is a // class template, so name a specialization; the defaults are what a user who // does not tune them gets. static_assert(has_initialize< - minimal_perfect_hash<>::fn, - registry1::compiler>, std::tuple<>>); + minimal_perfect_hash<>::fn, registry1::compiler>, + std::tuple<>>); static_assert(has_initialize< - two_level_hash<>::fn, - registry1::compiler>, std::tuple<>>); + two_level_hash<>::fn, registry1::compiler>, + std::tuple<>>); #if BOOST_OPENMETHOD_HAS_PEXT static_assert(has_initialize< - minimal_cover_hash<>::fn, - registry1::compiler>, std::tuple<>>); + minimal_cover_hash<>::fn, registry1::compiler>, + std::tuple<>>); #endif // All four are interchangeable: each derives from the `type_hash` category, so @@ -107,9 +106,9 @@ static_assert(std::is_base_of_v>); static_assert(std::is_base_of_v>); static_assert(std::is_base_of_v>); static_assert(std::is_same_v< - default_registry::with>::policy, - minimal_perfect_hash<>::fn< - default_registry::with>>>); + default_registry::with>::policy, + minimal_perfect_hash<>::fn< + default_registry::with>>>); static_assert( mp11::mp_size::value == mp11::mp_size< diff --git a/test/test_reflection.cpp b/test/test_reflection.cpp index 0b1e50d6..429db115 100644 --- a/test/test_reflection.cpp +++ b/test/test_reflection.cpp @@ -936,8 +936,8 @@ struct Dog : Animal {}; // No registry group, so the classes go to the default registry; no namespace // group either, so the global namespace is scanned, as always. BOOST_OPENMETHOD_REGISTER( - register_classes<{ - ^^default_registry_target::Animal, ^^default_registry_target::Dog}>); + register_classes< + {^^default_registry_target::Animal, ^^default_registry_target::Dog}>); } // namespace default_registry_target @@ -1216,12 +1216,13 @@ BOOST_OPENMETHOD(stream, (virtual_), std::ostream&, test_registry); BOOST_OPENMETHOD_OVERRIDE(stream, (Dog&), std::ostringstream&) { static std::ostringstream os; + return os; } BOOST_OPENMETHOD(clone, (virtual_), Animal*, test_registry); -BOOST_OPENMETHOD_OVERRIDE(clone, (Dog & dog), Dog*) { +BOOST_OPENMETHOD_OVERRIDE(clone, (Dog& dog), Dog*) { return &dog; } diff --git a/test/test_runtime_errors_no_initialization.cpp b/test/test_runtime_errors_no_initialization.cpp index 2c257dc9..48abf921 100644 --- a/test/test_runtime_errors_no_initialization.cpp +++ b/test/test_runtime_errors_no_initialization.cpp @@ -31,7 +31,8 @@ BOOST_AUTO_TEST_CASE(no_initialization) { capture capture; BOOST_CHECK_THROW( (shared_virtual_ptr{ - std::make_shared()}), + std::make_shared() + }), not_initialized); BOOST_TEST(capture() == "not initialized\n"); } diff --git a/test/test_shared_virtual_ptr_value_semantics.cpp b/test/test_shared_virtual_ptr_value_semantics.cpp index aef426e5..e79eaf6d 100644 --- a/test/test_shared_virtual_ptr_value_semantics.cpp +++ b/test/test_shared_virtual_ptr_value_semantics.cpp @@ -15,30 +15,27 @@ #include static_assert(SameSmartPtr< - std::shared_ptr, std::shared_ptr, default_registry>); + std::shared_ptr, std::shared_ptr, default_registry>); static_assert(!SameSmartPtr< - std::shared_ptr, std::unique_ptr, default_registry>); + std::shared_ptr, std::unique_ptr, default_registry>); static_assert(!SameSmartPtr< - std::shared_ptr, shared_virtual_ptr>, - default_registry>); + std::shared_ptr, shared_virtual_ptr>, + default_registry>); BOOST_AUTO_TEST_CASE_TEMPLATE( shared_virtual_ptr_value, Registry, test_policies) { static_assert(std::is_same_v< - typename shared_virtual_ptr::element_type, - Animal>); + typename shared_virtual_ptr::element_type, Animal>); static_assert(std::is_same_v< - decltype(std::declval>() - .get()), - Animal*>); + decltype(std::declval>().get()), + Animal*>); static_assert(IsSmartPtr, Registry>); static_assert(IsSmartPtr, Registry>); - static_assert( - std::is_same_v< - decltype(*std::declval>()), - Animal&>); + static_assert(std::is_same_v< + decltype(*std::declval>()), + Animal&>); init_test(); @@ -368,22 +365,22 @@ template struct check_illegal_smart_ops< // Cannot construct or assign a virtual_ptr from a non-polymorphic object. static_assert(!construct_assign_ok< - virtual_ptr>, - const std::shared_ptr&>); + virtual_ptr>, + const std::shared_ptr&>); static_assert(!construct_assign_ok< - virtual_ptr>, - std::shared_ptr&>); + virtual_ptr>, + std::shared_ptr&>); static_assert(!construct_assign_ok< - virtual_ptr>, - std::shared_ptr&&>); + virtual_ptr>, + std::shared_ptr&&>); // OK from another virtual_ptr though, because it can be constructed using // 'final'. static_assert(std::is_assignable_v< - virtual_ptr>, - const virtual_ptr>&>); + virtual_ptr>, + const virtual_ptr>&>); static_assert(construct_assign_ok< - virtual_ptr>, - virtual_ptr>&>); + virtual_ptr>, + virtual_ptr>&>); static_assert(construct_assign_ok< - virtual_ptr>, - virtual_ptr>&&>); + virtual_ptr>, + virtual_ptr>&&>); diff --git a/test/test_slot_allocator.cpp b/test/test_slot_allocator.cpp index e8c8cbc7..55feef8f 100644 --- a/test/test_slot_allocator.cpp +++ b/test/test_slot_allocator.cpp @@ -383,6 +383,7 @@ auto records_of(boost::mp11::mp_list) if (Registry::rtti::type_index(record.type) == Registry::rtti::type_index(type)) { records.push_back(&record); + return; } } @@ -505,14 +506,14 @@ void expect_total(const allocation_stats& stats, std::size_t total) { // The slot chooser on its own. BOOST_AUTO_TEST_CASE(test_pick_slot) { + using namespace detail; using boost::dynamic_bitset; - using detail::generic_compiler; auto bits = [](std::initializer_list slots) { dynamic_bitset<> result; for (auto slot : slots) { - detail::set_bit(result, slot); + set_bit(result, slot); } return result; @@ -526,7 +527,7 @@ BOOST_AUTO_TEST_CASE(test_pick_slot) { for (std::size_t i = 0; i < used.size(); ++i) { classes[i].used_slots = used[i]; cone.push_back(&classes[i]); - detail::merge_into(used[i], unavailable); + merge_into(used[i], unavailable); } return generic_compiler::pick_slot(cone, unavailable); @@ -1701,7 +1702,7 @@ BOOST_AUTO_TEST_CASE(test_finalize_clears_vptr_vector) { // The vptr policy provides a finalize() (portable across MSVC/non-MSVC). static_assert(detail::has_finalize< - test_registry::policy, const std::tuple<>&>); + test_registry::policy, const std::tuple<>&>); finalize(); BOOST_TEST(vptrs.empty()); // finalize cleared the vector diff --git a/test/test_smart_virtual_ptr_value_semantics.cpp b/test/test_smart_virtual_ptr_value_semantics.cpp index 1105c7b5..47b6333d 100644 --- a/test/test_smart_virtual_ptr_value_semantics.cpp +++ b/test/test_smart_virtual_ptr_value_semantics.cpp @@ -105,7 +105,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( static_assert( std::is_same_v); static_assert(std::is_same_v< - decltype(std::declval().get()), Animal*>); + decltype(std::declval().get()), Animal*>); static_assert(IsSmartPtr); static_assert(IsSmartPtr); static_assert( diff --git a/test/test_unique_virtual_ptr_value_semantics.cpp b/test/test_unique_virtual_ptr_value_semantics.cpp index aaa68c10..d3a1a4b3 100644 --- a/test/test_unique_virtual_ptr_value_semantics.cpp +++ b/test/test_unique_virtual_ptr_value_semantics.cpp @@ -19,18 +19,15 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( init_test(); static_assert(std::is_same_v< - typename unique_virtual_ptr::element_type, - Animal>); + typename unique_virtual_ptr::element_type, Animal>); static_assert(std::is_same_v< - decltype(std::declval>() - .get()), - Animal*>); + decltype(std::declval>().get()), + Animal*>); static_assert(IsSmartPtr, Registry>); static_assert(IsSmartPtr, Registry>); - static_assert( - std::is_same_v< - decltype(*std::declval>()), - Animal&>); + static_assert(std::is_same_v< + decltype(*std::declval>()), + Animal&>); { // unique_virtual_ptr(nullptr) @@ -48,21 +45,19 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( !construct_assign_ok, Dog*>); static_assert(!construct_assign_ok< - unique_virtual_ptr, std::unique_ptr&>); + unique_virtual_ptr, std::unique_ptr&>); - static_assert( - !construct_assign_ok< - unique_virtual_ptr, const std::unique_ptr&>); + static_assert(!construct_assign_ok< + unique_virtual_ptr, const std::unique_ptr&>); static_assert(!construct_assign_ok< - unique_virtual_ptr, unique_virtual_ptr>); + unique_virtual_ptr, unique_virtual_ptr>); static_assert(!construct_assign_ok< - unique_virtual_ptr, unique_virtual_ptr&>); + unique_virtual_ptr, unique_virtual_ptr&>); - static_assert( - !construct_assign_ok< - unique_virtual_ptr, const unique_virtual_ptr&>); + static_assert(!construct_assign_ok< + unique_virtual_ptr, const unique_virtual_ptr&>); { // construct from unique_ptr temporary @@ -76,24 +71,21 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( BOOST_TEST(p.vptr() == Registry::template static_vptr); } - static_assert( - !construct_assign_ok< - unique_virtual_ptr, const std::unique_ptr&>); + static_assert(!construct_assign_ok< + unique_virtual_ptr, const std::unique_ptr&>); static_assert(!construct_assign_ok< - unique_virtual_ptr, std::unique_ptr&>); + unique_virtual_ptr, std::unique_ptr&>); static_assert(!construct_assign_ok< - unique_virtual_ptr, - const unique_virtual_ptr&>); + unique_virtual_ptr, + const unique_virtual_ptr&>); static_assert(!construct_assign_ok< - unique_virtual_ptr, - unique_virtual_ptr&>); + unique_virtual_ptr, unique_virtual_ptr&>); static_assert(!construct_assign_ok< - unique_virtual_ptr, - unique_virtual_ptr&>); + unique_virtual_ptr, unique_virtual_ptr&>); { // assign from smart ptr temporary @@ -280,16 +272,16 @@ template struct check_illegal_smart_ops< // Cannot construct or assign a virtual_ptr from a non-polymorphic object. static_assert(!construct_assign_ok< - virtual_ptr>, - const std::unique_ptr&>); + virtual_ptr>, + const std::unique_ptr&>); static_assert(!construct_assign_ok< - virtual_ptr>, - std::unique_ptr&>); + virtual_ptr>, + std::unique_ptr&>); static_assert(!construct_assign_ok< - virtual_ptr>, - std::unique_ptr&&>); + virtual_ptr>, + std::unique_ptr&&>); // OK to move from another virtual_ptr though, because it can be constructed // using 'final'. static_assert(construct_assign_ok< - virtual_ptr>, - virtual_ptr>&&>); + virtual_ptr>, + virtual_ptr>&&>); diff --git a/test/test_virtual_any_boost.cpp b/test/test_virtual_any_boost.cpp index 69c4e299..d6c37b7a 100644 --- a/test/test_virtual_any_boost.cpp +++ b/test/test_virtual_any_boost.cpp @@ -32,14 +32,14 @@ namespace BOOST_OPENMETHOD_GENSYM { // A virtual_any hands out the v-table pointer it cached, through its // virtual_traits, for all three reference categories. static_assert(detail::has_vptr< - virtual_traits, - const virtual_boost_any&>); + virtual_traits, + const virtual_boost_any&>); static_assert(detail::has_vptr< - virtual_traits, - const virtual_boost_any&>); + virtual_traits, + const virtual_boost_any&>); static_assert(detail::has_vptr< - virtual_traits, - const virtual_boost_any&>); + virtual_traits, + const virtual_boost_any&>); MAKE_CLASSES(); @@ -111,11 +111,13 @@ using bump_method = auto bump_dog(Dog& dog) -> std::string { dog.name += " Jr."; + return dog.name + " the dog"; } auto bump_int(int& value) -> std::string { ++value; + return "bumped"; } @@ -145,13 +147,15 @@ MAKE_CLASSES(); BOOST_OPENMETHOD(steal, (virtual_boost_any&&), std::string); -BOOST_OPENMETHOD_OVERRIDE(steal, (Dog && dog), std::string) { +BOOST_OPENMETHOD_OVERRIDE(steal, (Dog&& dog), std::string) { Dog stolen(std::move(dog)); + return stolen.name + " the dog"; } -BOOST_OPENMETHOD_OVERRIDE(steal, (std::string && name), std::string) { +BOOST_OPENMETHOD_OVERRIDE(steal, (std::string&& name), std::string) { std::string stolen(std::move(name)); + return stolen; } diff --git a/test/test_virtual_any_std.cpp b/test/test_virtual_any_std.cpp index 2ae2be5e..2543cd3d 100644 --- a/test/test_virtual_any_std.cpp +++ b/test/test_virtual_any_std.cpp @@ -32,14 +32,14 @@ namespace BOOST_OPENMETHOD_GENSYM { // A virtual_any hands out the v-table pointer it cached, through its // virtual_traits, for all three reference categories. static_assert(detail::has_vptr< - virtual_traits, - const virtual_std_any&>); + virtual_traits, + const virtual_std_any&>); static_assert(detail::has_vptr< - virtual_traits, - const virtual_std_any&>); + virtual_traits, + const virtual_std_any&>); static_assert(detail::has_vptr< - virtual_traits, - const virtual_std_any&>); + virtual_traits, + const virtual_std_any&>); MAKE_CLASSES(); @@ -111,11 +111,13 @@ using bump_method = auto bump_dog(Dog& dog) -> std::string { dog.name += " Jr."; + return dog.name + " the dog"; } auto bump_int(int& value) -> std::string { ++value; + return "bumped"; } @@ -145,13 +147,15 @@ MAKE_CLASSES(); BOOST_OPENMETHOD(steal, (virtual_std_any&&), std::string); -BOOST_OPENMETHOD_OVERRIDE(steal, (Dog && dog), std::string) { +BOOST_OPENMETHOD_OVERRIDE(steal, (Dog&& dog), std::string) { Dog stolen(std::move(dog)); + return stolen.name + " the dog"; } -BOOST_OPENMETHOD_OVERRIDE(steal, (std::string && name), std::string) { +BOOST_OPENMETHOD_OVERRIDE(steal, (std::string&& name), std::string) { std::string stolen(std::move(name)); + return stolen; } diff --git a/test/test_virtual_any_type_erasure.cpp b/test/test_virtual_any_type_erasure.cpp index af27e480..fb8916c1 100644 --- a/test/test_virtual_any_type_erasure.cpp +++ b/test/test_virtual_any_type_erasure.cpp @@ -107,11 +107,13 @@ using bump_method = BOOST_OPENMETHOD_TYPE(bump, (virtual_erased&), std::string); auto bump_dog(Dog& dog) -> std::string { dog.name += " Jr."; + return dog.name + " the dog"; } auto bump_int(int& value) -> std::string { ++value; + return "bumped"; } @@ -144,13 +146,15 @@ BOOST_OPENMETHOD(steal, (virtual_erased&&), std::string); // boost::type_erasure::any_cast has no rvalue overload; the trait moves // the result of a mutable-reference cast, because the `any` owns its // value. -BOOST_OPENMETHOD_OVERRIDE(steal, (Dog && dog), std::string) { +BOOST_OPENMETHOD_OVERRIDE(steal, (Dog&& dog), std::string) { Dog stolen(std::move(dog)); + return stolen.name + " the dog"; } -BOOST_OPENMETHOD_OVERRIDE(steal, (std::string && name), std::string) { +BOOST_OPENMETHOD_OVERRIDE(steal, (std::string&& name), std::string) { std::string stolen(std::move(name)); + return stolen; } diff --git a/test/test_virtual_ptr_value_semantics.cpp b/test/test_virtual_ptr_value_semantics.cpp index 1eb6269e..c5e716f0 100644 --- a/test/test_virtual_ptr_value_semantics.cpp +++ b/test/test_virtual_ptr_value_semantics.cpp @@ -10,20 +10,18 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( plain_virtual_ptr_value, Registry, test_policies) { - static_assert( - std::is_same_v< - typename virtual_ptr::element_type, Animal>); static_assert(std::is_same_v< - typename virtual_ptr::element_type, - const Animal>); + typename virtual_ptr::element_type, Animal>); static_assert(std::is_same_v< - decltype(std::declval>().get()), - Animal*>); + typename virtual_ptr::element_type, + const Animal>); + static_assert(std::is_same_v< + decltype(std::declval>().get()), + Animal*>); static_assert(!IsSmartPtr); static_assert(!IsSmartPtr); - static_assert( - std::is_same_v< - decltype(*std::declval>()), Animal&>); + static_assert(std::is_same_v< + decltype(*std::declval>()), Animal&>); init_test(); @@ -317,6 +315,7 @@ BOOST_AUTO_TEST_CASE(virtual_ptr_final_error) { } catch (...) { default_registry::error_handler::set(prev_handler); BOOST_FAIL("wrong exception"); + return; } @@ -345,4 +344,4 @@ static_assert( // OK from another virtual_ptr though, because it can be constructed using // 'final'. static_assert(construct_assign_ok< - virtual_ptr, virtual_ptr>); + virtual_ptr, virtual_ptr>); diff --git a/test/test_virtual_ptr_value_semantics.hpp b/test/test_virtual_ptr_value_semantics.hpp index b6bf1818..a484a1da 100644 --- a/test/test_virtual_ptr_value_semantics.hpp +++ b/test/test_virtual_ptr_value_semantics.hpp @@ -82,27 +82,26 @@ struct check_illegal_smart_ops { // a virtual_ptr cannot be constructed from a smart_ptr to a different class static_assert(!std::is_constructible_v< - virtual_ptr, Registry>, smart_ptr>); + virtual_ptr, Registry>, smart_ptr>); // a virtual_ptr cannot be constructed from const smart_ptr - static_assert( - !std::is_constructible_v< - virtual_ptr, Registry>, smart_ptr>); + static_assert(!std::is_constructible_v< + virtual_ptr, Registry>, smart_ptr>); // a smart virtual_ptr cannot be constructed from a plain reference or // pointer static_assert(!std::is_constructible_v< - virtual_ptr, Registry>, Animal&>); + virtual_ptr, Registry>, Animal&>); static_assert(!std::is_constructible_v< - virtual_ptr, Registry>, Animal*>); + virtual_ptr, Registry>, Animal*>); static_assert(!std::is_constructible_v< - smart_ptr, const other_smart_ptr&>); + smart_ptr, const other_smart_ptr&>); // smart_ptr p{other_smart_ptr()}; static_assert(!std::is_constructible_v< - virtual_ptr, Registry>, - virtual_ptr>); + virtual_ptr, Registry>, + virtual_ptr>); // --------------------- // test other properties @@ -110,32 +109,27 @@ struct check_illegal_smart_ops { static_assert(IsSmartPtr, Registry>); static_assert(IsSmartPtr, Registry>); - static_assert( - std::is_same_v< - typename virtual_ptr, Registry>::element_type, - Animal>); - - static_assert( - std::is_same_v< - decltype(std::declval, Registry>>() - .get()), - Animal*>); - - static_assert( - std::is_same_v< - decltype(*std::declval, Registry>>()), - Animal&>); - - static_assert( - std::is_same_v< - decltype(std::declval, Registry>>() - .pointer()), - const smart_ptr&>); - - static_assert( - std::is_same_v< - decltype(*std::declval, Registry>>()), - Animal&>); + static_assert(std::is_same_v< + typename virtual_ptr, Registry>::element_type, + Animal>); + + static_assert(std::is_same_v< + decltype(std::declval, Registry>>() + .get()), + Animal*>); + + static_assert(std::is_same_v< + decltype(*std::declval, Registry>>()), + Animal&>); + + static_assert(std::is_same_v< + decltype(std::declval, Registry>>() + .pointer()), + const smart_ptr&>); + + static_assert(std::is_same_v< + decltype(*std::declval, Registry>>()), + Animal&>); }; #endif // TEST_VIRTUAL_PTR_VALUE_SEMANTICS_HPP diff --git a/test/test_weak_virtual_ptr.cpp b/test/test_weak_virtual_ptr.cpp index 2ebe7a70..29e413ac 100644 --- a/test/test_weak_virtual_ptr.cpp +++ b/test/test_weak_virtual_ptr.cpp @@ -26,15 +26,15 @@ static_assert(std::is_nothrow_move_assignable_v>); static_assert(std::is_same_v::element_type, Animal>); static_assert(std::is_same_v< - decltype(std::declval>().lock()), - shared_virtual_ptr>); + decltype(std::declval>().lock()), + shared_virtual_ptr>); static_assert(std::is_same_v< - decltype(std::declval>().pointer()), - const std::weak_ptr&>); + decltype(std::declval>().pointer()), + const std::weak_ptr&>); // Construction is allowed from shared and weak pointers, virtual or not... static_assert(std::is_constructible_v< - weak_virtual_ptr, shared_virtual_ptr>); + weak_virtual_ptr, shared_virtual_ptr>); static_assert( std::is_constructible_v, shared_virtual_ptr>); static_assert( @@ -44,7 +44,7 @@ static_assert( static_assert( std::is_constructible_v, std::weak_ptr>); static_assert(std::is_constructible_v< - weak_virtual_ptr, shared_virtual_ptr>); + weak_virtual_ptr, shared_virtual_ptr>); // ...but not from a plain pointer, reference or virtual_ptr, nor from a // different class or a const object... @@ -55,12 +55,11 @@ static_assert( static_assert( !std::is_constructible_v, shared_virtual_ptr>); static_assert(!std::is_constructible_v< - weak_virtual_ptr, shared_virtual_ptr>); -static_assert( - !std::is_constructible_v< - weak_virtual_ptr, std::shared_ptr>); + weak_virtual_ptr, shared_virtual_ptr>); +static_assert(!std::is_constructible_v< + weak_virtual_ptr, std::shared_ptr>); static_assert(!std::is_constructible_v< - weak_virtual_ptr, std::weak_ptr>); + weak_virtual_ptr, std::weak_ptr>); // ...and a weak virtual_ptr converts to nothing but another weak virtual_ptr. static_assert( @@ -68,11 +67,11 @@ static_assert( static_assert( !std::is_assignable_v&, weak_virtual_ptr>); static_assert(!std::is_constructible_v< - shared_virtual_ptr, weak_virtual_ptr>); + shared_virtual_ptr, weak_virtual_ptr>); static_assert(!std::is_assignable_v< - shared_virtual_ptr&, weak_virtual_ptr>); + shared_virtual_ptr&, weak_virtual_ptr>); static_assert(!std::is_constructible_v< - std::shared_ptr, weak_virtual_ptr>); + std::shared_ptr, weak_virtual_ptr>); BOOST_AUTO_TEST_CASE_TEMPLATE( weak_virtual_ptr_from_shared_virtual_ptr, Registry, test_policies) { @@ -90,7 +89,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( { auto locked = weak.lock(); static_assert(std::is_same_v< - decltype(locked), shared_virtual_ptr>); + decltype(locked), shared_virtual_ptr>); BOOST_TEST(locked.get() == snoopy.get()); BOOST_TEST(locked.vptr() == Registry::template static_vptr); BOOST_TEST(weak.use_count() == 3);