mirror of
https://github.com/boostorg/openmethod.git
synced 2026-01-19 04:22:12 +00:00
fix warnings
This commit is contained in:
@@ -44,35 +44,31 @@ BOOST_OPENMETHOD(
|
||||
std::string);
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
fight,
|
||||
(virtual_ptr<Character> x, virtual_ptr<Creature> y, virtual_ptr<Banana> z),
|
||||
fight, (virtual_ptr<Character>, virtual_ptr<Creature>, virtual_ptr<Banana>),
|
||||
std::string) {
|
||||
return "are you insane?";
|
||||
}
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
fight,
|
||||
(virtual_ptr<Character> x, virtual_ptr<Creature> y, virtual_ptr<Axe> z),
|
||||
fight, (virtual_ptr<Character>, virtual_ptr<Creature>, virtual_ptr<Axe>),
|
||||
std::string) {
|
||||
return "not agile enough to wield";
|
||||
}
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
fight,
|
||||
(virtual_ptr<Warrior> x, virtual_ptr<Creature> y, virtual_ptr<Axe> z),
|
||||
fight, (virtual_ptr<Warrior>, virtual_ptr<Creature>, virtual_ptr<Axe>),
|
||||
std::string) {
|
||||
return "and cuts it into pieces";
|
||||
}
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
fight, (virtual_ptr<Warrior> x, virtual_ptr<Dragon> y, virtual_ptr<Axe> z),
|
||||
fight, (virtual_ptr<Warrior>, virtual_ptr<Dragon>, virtual_ptr<Axe>),
|
||||
std::string) {
|
||||
return "and dies a honorable death";
|
||||
}
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
fight,
|
||||
(virtual_ptr<Character> x, virtual_ptr<Dragon> y, virtual_ptr<Hands> z),
|
||||
fight, (virtual_ptr<Character>, virtual_ptr<Dragon>, virtual_ptr<Hands>),
|
||||
std::string) {
|
||||
return "Congratulations! You have just vainquished a dragon with your bare "
|
||||
"hands"
|
||||
|
||||
@@ -26,31 +26,32 @@ BOOST_OPENMETHOD_CLASSES(Thing, Spaceship, Asteroid);
|
||||
BOOST_OPENMETHOD(collideWith, (virtual_ptr<Thing>, virtual_ptr<Thing>), void);
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
collideWith, (virtual_ptr<Thing> left, virtual_ptr<Thing> right), void) {
|
||||
collideWith, (virtual_ptr<Thing> /*left*/, virtual_ptr<Thing> /*right*/),
|
||||
void) {
|
||||
// default collision handling
|
||||
}
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
collideWith, (virtual_ptr<Asteroid> left, virtual_ptr<Asteroid> right),
|
||||
void) {
|
||||
collideWith,
|
||||
(virtual_ptr<Asteroid> /*left*/, virtual_ptr<Asteroid> /*right*/), void) {
|
||||
// handle Asteroid-Asteroid collision
|
||||
}
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
collideWith, (virtual_ptr<Asteroid> left, virtual_ptr<Spaceship> right),
|
||||
void) {
|
||||
collideWith,
|
||||
(virtual_ptr<Asteroid> /*left*/, virtual_ptr<Spaceship> /*right*/), void) {
|
||||
// handle Asteroid-Spaceship collision
|
||||
}
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
collideWith, (virtual_ptr<Spaceship> left, virtual_ptr<Asteroid> right),
|
||||
void) {
|
||||
collideWith,
|
||||
(virtual_ptr<Spaceship> /*left*/, virtual_ptr<Asteroid> /*right*/), void) {
|
||||
// handle Spaceship-Asteroid collision
|
||||
}
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
collideWith, (virtual_ptr<Spaceship> left, virtual_ptr<Spaceship> right),
|
||||
void) {
|
||||
collideWith,
|
||||
(virtual_ptr<Spaceship> /*left*/, virtual_ptr<Spaceship> /*right*/), void) {
|
||||
// handle Spaceship-Spaceship collision
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ using poke = method<
|
||||
// end::method[]
|
||||
|
||||
// tag::poke_cat[]
|
||||
auto poke_cat(std::ostream& os, virtual_ptr<Cat> cat) {
|
||||
auto poke_cat(std::ostream& os, virtual_ptr<Cat> /*cat*/) {
|
||||
os << "hiss";
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ static poke::override<poke_cat> override_poke_cat;
|
||||
// tag::poke_dog[]
|
||||
#include <boost/openmethod/macros.hpp>
|
||||
|
||||
auto poke_dog(std::ostream& os, virtual_ptr<Dog> dog) {
|
||||
auto poke_dog(std::ostream& os, virtual_ptr<Dog> /*dog*/) {
|
||||
os << "bark";
|
||||
}
|
||||
|
||||
@@ -60,11 +60,11 @@ BOOST_OPENMETHOD_REGISTER(poke::override<poke_bulldog>);
|
||||
|
||||
class BOOST_OPENMETHOD_NAME(pet);
|
||||
|
||||
auto pet_cat(std::ostream& os, virtual_ptr<Cat> cat) {
|
||||
auto pet_cat(std::ostream& os, virtual_ptr<Cat> /*cat*/) {
|
||||
os << "purr";
|
||||
}
|
||||
|
||||
auto pet_dog(std::ostream& os, virtual_ptr<Dog> dog) {
|
||||
auto pet_dog(std::ostream& os, virtual_ptr<Dog> /*dog*/) {
|
||||
os << "wag tail";
|
||||
}
|
||||
|
||||
|
||||
@@ -82,12 +82,12 @@ using boost::openmethod::virtual_ptr;
|
||||
BOOST_OPENMETHOD(poke, (std::ostream&, virtual_ptr<Animal>), void);
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
poke, (std::ostream & os, virtual_ptr<Cat> cat), void) {
|
||||
poke, (std::ostream & os, virtual_ptr<Cat> /*cat*/), void) {
|
||||
os << "hiss";
|
||||
}
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
poke, (std::ostream & os, virtual_ptr<Dog> dog), void) {
|
||||
poke, (std::ostream & os, virtual_ptr<Dog> /*dog*/), void) {
|
||||
os << "bark";
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ BOOST_OPENMETHOD_CLASSES(Animal, Cat, Dog);
|
||||
BOOST_OPENMETHOD(trick, (std::ostream&, virtual_ptr<Animal>), void);
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
trick, (std::ostream & os, virtual_ptr<Dog> dog), void) {
|
||||
trick, (std::ostream & os, virtual_ptr<Dog> /*dog*/), void) {
|
||||
os << "spin\n";
|
||||
}
|
||||
|
||||
|
||||
@@ -136,12 +136,12 @@ using boost::openmethod::virtual_ptr;
|
||||
BOOST_OPENMETHOD(poke, (std::ostream&, virtual_ptr<Animal>), void);
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
poke, (std::ostream & os, virtual_ptr<Cat> cat), void) {
|
||||
poke, (std::ostream & os, virtual_ptr<Cat> /*cat*/), void) {
|
||||
os << "hiss";
|
||||
}
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
poke, (std::ostream & os, virtual_ptr<Dog> dog), void) {
|
||||
poke, (std::ostream & os, virtual_ptr<Dog> /*dog*/), void) {
|
||||
os << "bark";
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ BOOST_OPENMETHOD_OVERRIDE(
|
||||
// Add definitions for specific pairs of animals.
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
encounter,
|
||||
(std::ostream & os, virtual_ptr<Dog> dog1, virtual_ptr<Dog> dog2), void) {
|
||||
(std::ostream & os, virtual_ptr<Dog> /*dog1*/, virtual_ptr<Dog> /*dog2*/), void) {
|
||||
os << "Both wag tails";
|
||||
}
|
||||
|
||||
|
||||
@@ -28,13 +28,13 @@ struct matrix {
|
||||
};
|
||||
|
||||
struct dense_matrix : matrix {
|
||||
virtual auto at(int row, int col) const -> double {
|
||||
virtual auto at(int /*row*/, int /*col*/) const -> double {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct diagonal_matrix : matrix {
|
||||
virtual auto at(int row, int col) const -> double {
|
||||
virtual auto at(int /*row*/, int /*col*/) const -> double {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
@@ -43,13 +43,12 @@ BOOST_OPENMETHOD_CLASSES(matrix, dense_matrix, diagonal_matrix);
|
||||
|
||||
BOOST_OPENMETHOD(to_json, (virtual_ptr<const matrix>), string);
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
to_json, (virtual_ptr<const dense_matrix> m), string) {
|
||||
BOOST_OPENMETHOD_OVERRIDE(to_json, (virtual_ptr<const dense_matrix>), string) {
|
||||
return "json for dense matrix...";
|
||||
}
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
to_json, (virtual_ptr<const diagonal_matrix> m), string) {
|
||||
to_json, (virtual_ptr<const diagonal_matrix>), string) {
|
||||
return "json for diagonal matrix...";
|
||||
}
|
||||
|
||||
@@ -63,7 +62,8 @@ BOOST_OPENMETHOD(
|
||||
// catch-all matrix * matrix -> dense_matrix
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
times,
|
||||
(shared_virtual_ptr<const matrix> a, shared_virtual_ptr<const matrix> b),
|
||||
(shared_virtual_ptr<const matrix> /*a*/,
|
||||
shared_virtual_ptr<const matrix> /*b*/),
|
||||
shared_virtual_ptr<const dense_matrix>) {
|
||||
return make_shared<const dense_matrix>();
|
||||
}
|
||||
@@ -71,8 +71,8 @@ BOOST_OPENMETHOD_OVERRIDE(
|
||||
// diagonal_matrix * diagonal_matrix -> diagonal_matrix
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
times,
|
||||
(shared_virtual_ptr<const diagonal_matrix> a,
|
||||
shared_virtual_ptr<const diagonal_matrix> b),
|
||||
(shared_virtual_ptr<const diagonal_matrix> /*a*/,
|
||||
shared_virtual_ptr<const diagonal_matrix> /*b*/),
|
||||
shared_virtual_ptr<const diagonal_matrix>) {
|
||||
return make_shared_virtual<diagonal_matrix>();
|
||||
}
|
||||
@@ -91,13 +91,13 @@ BOOST_OPENMETHOD(
|
||||
|
||||
// catch-all matrix * scalar -> dense_matrix
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
times, (double a, shared_virtual_ptr<const matrix> b),
|
||||
times, (double /*a*/, shared_virtual_ptr<const matrix> /*b*/),
|
||||
shared_virtual_ptr<const dense_matrix>) {
|
||||
return make_shared_virtual<dense_matrix>();
|
||||
}
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
times, (double a, shared_virtual_ptr<const diagonal_matrix> b),
|
||||
times, (double /*a*/, shared_virtual_ptr<const diagonal_matrix> /*b*/),
|
||||
shared_virtual_ptr<const diagonal_matrix>) {
|
||||
return make_shared_virtual<diagonal_matrix>();
|
||||
}
|
||||
@@ -131,7 +131,7 @@ auto main() -> int {
|
||||
shared_ptr<const matrix> b = make_shared<diagonal_matrix>();
|
||||
double s = 1;
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#ifdef BOOST_CLANG
|
||||
#pragma clang diagnostic ignored "-Wpotentially-evaluated-expression"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -39,8 +39,7 @@ BOOST_OPENMETHOD(
|
||||
inspect, (virtual_ptr<const Vehicle>, virtual_ptr<const Inspector>), void);
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
inspect, (virtual_ptr<const Vehicle> v, virtual_ptr<const Inspector> i),
|
||||
void) {
|
||||
inspect, (virtual_ptr<const Vehicle>, virtual_ptr<const Inspector>), void) {
|
||||
cout << "Inspect vehicle.\n";
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
// See accompanying file LICENSE_1_0.txt
|
||||
// or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// clang-format off
|
||||
|
||||
// NOTE: No actual animals were hurt while designing, coding, compiling and
|
||||
// running this example.
|
||||
|
||||
@@ -43,35 +41,48 @@ BOOST_OPENMETHOD_CLASSES(Dog, Bulldog);
|
||||
BOOST_OPENMETHOD(poke, (virtual_ptr<Animal>, std::ostream&), void);
|
||||
|
||||
// Implement 'poke' for dogs.
|
||||
BOOST_OPENMETHOD_OVERRIDE(poke, (virtual_ptr<Dog> dog, std::ostream& os), void) {
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
poke, (virtual_ptr<Dog> /*dog*/, std::ostream& os), void) {
|
||||
os << "bark";
|
||||
}
|
||||
|
||||
// Implement 'poke' for bulldogs. They behave like Dogs, but, in addition, they
|
||||
// fight back.
|
||||
BOOST_OPENMETHOD_OVERRIDE(poke, (virtual_ptr<Bulldog> dog, std::ostream& os), void) {
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
poke, (virtual_ptr<Bulldog> dog, std::ostream& os), void) {
|
||||
next(dog, os); // calls "base" method, i.e. definition for Dog
|
||||
os << " and bite";
|
||||
}
|
||||
|
||||
// A multi-method with two virtual arguments...
|
||||
BOOST_OPENMETHOD(meet, (virtual_ptr<Animal>, virtual_ptr<Animal>, std::ostream&), void);
|
||||
BOOST_OPENMETHOD(
|
||||
meet, (virtual_ptr<Animal>, virtual_ptr<Animal>, std::ostream&), void);
|
||||
|
||||
// 'meet' catch-all implementation.
|
||||
BOOST_OPENMETHOD_OVERRIDE(meet, (virtual_ptr<Animal>, virtual_ptr<Animal>, std::ostream& os), void) {
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
meet, (virtual_ptr<Animal>, virtual_ptr<Animal>, std::ostream& os), void) {
|
||||
os << "ignore";
|
||||
}
|
||||
|
||||
// Add definitions for specific pairs of animals.
|
||||
BOOST_OPENMETHOD_OVERRIDE(meet, (virtual_ptr<Dog> dog1, virtual_ptr<Dog> dog2, std::ostream& os), void) {
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
meet,
|
||||
(virtual_ptr<Dog> /*dog1*/, virtual_ptr<Dog> /*dog2*/, std::ostream& os),
|
||||
void) {
|
||||
os << "wag tail";
|
||||
}
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(meet, (virtual_ptr<Dog> dog, virtual_ptr<Cat> cat, std::ostream& os), void) {
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
meet,
|
||||
(virtual_ptr<Dog> /*dog*/, virtual_ptr<Cat> /*cat*/, std::ostream& os),
|
||||
void) {
|
||||
os << "chase";
|
||||
}
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(meet, (virtual_ptr<Cat> cat, virtual_ptr<Dog> dog, std::ostream& os), void) {
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
meet,
|
||||
(virtual_ptr<Cat> /*cat*/, virtual_ptr<Dog> /*dog*/, std::ostream& os),
|
||||
void) {
|
||||
os << "run";
|
||||
}
|
||||
|
||||
@@ -88,11 +99,10 @@ auto main() -> int {
|
||||
|
||||
// Create a few objects.
|
||||
// Note that the actual classes are type-erased to base class Animal!
|
||||
std::unique_ptr<Animal>
|
||||
hector = std::make_unique<Bulldog>(),
|
||||
snoopy = std::make_unique<Dog>(),
|
||||
sylvester = std::make_unique<Cat>(),
|
||||
flipper = std::make_unique<Dolphin>();
|
||||
std::unique_ptr<Animal> hector = std::make_unique<Bulldog>(),
|
||||
snoopy = std::make_unique<Dog>(),
|
||||
sylvester = std::make_unique<Cat>(),
|
||||
flipper = std::make_unique<Dolphin>();
|
||||
|
||||
// Call 'poke'.
|
||||
std::cout << "poke snoopy: ";
|
||||
@@ -129,23 +139,23 @@ void call_poke(Animal& a, std::ostream& os) {
|
||||
// Instructions in the same paragraph are independent, thus they can be
|
||||
// executed in parallel.
|
||||
|
||||
// mov rax, qword ptr [rdi] ; read vptr
|
||||
// mov rdx, qword ptr [rip + global+24] ; M hash factor (multiply)
|
||||
// mov rax, qword ptr [rdi] ; read vptr
|
||||
// mov rdx, qword ptr [rip + global+24] ; M hash factor (multiply)
|
||||
|
||||
// imul rdx, qword ptr [rax - 8] ; multiply vptr[-1] (&typeid(a)) by M
|
||||
// mov cl, byte ptr [rip + global+32] ; S hash factor (shift)
|
||||
// imul rdx, qword ptr [rax - 8] ; multiply vptr[-1] (&typeid(a)) by M
|
||||
// mov cl, byte ptr [rip + global+32] ; S hash factor (shift)
|
||||
|
||||
// shr rdx, cl ; shift by S: this is the position of
|
||||
// shr rdx, cl ; shift by S: this is the position of
|
||||
// ; the method table for the dynamic class of 'a'
|
||||
// ; in the global hash table
|
||||
// mov rax, qword ptr [rip + global+40] ; address of global hash table
|
||||
// mov rax, qword ptr [rip + global+40] ; address of global hash table
|
||||
|
||||
// mov rax, qword ptr [rax + 8*rdx] ; method table for the class
|
||||
// mov rcx, qword ptr [rip + method+96] ; offset of the 'poke' in method table
|
||||
// mov rax, qword ptr [rax + 8*rdx] ; method table for the class
|
||||
// mov rcx, qword ptr [rip + method+96] ; offset of the 'poke' in method table
|
||||
|
||||
// mov rax, qword ptr [rax + 8*rcx] ; read function pointer at offset
|
||||
// mov rax, qword ptr [rax + 8*rcx] ; read function pointer at offset
|
||||
|
||||
// jmp rax ; tail call
|
||||
// jmp rax ; tail call
|
||||
}
|
||||
|
||||
void call_meet(Animal& a, Animal& b, std::ostream& os) {
|
||||
@@ -154,33 +164,33 @@ void call_meet(Animal& a, Animal& b, std::ostream& os) {
|
||||
// Instructions in the same paragraph are independent, thus they can be
|
||||
// executed in parallel.
|
||||
|
||||
// mov r8, qword ptr [rdi] ; vptr of 'a'
|
||||
// mov r9, qword ptr [rip + global+24] ; M hash factor (multiply)
|
||||
// mov cl, byte ptr [rip + global+32] ; S hash factor (shift)
|
||||
// mov r8, qword ptr [rdi] ; vptr of 'a'
|
||||
// mov r9, qword ptr [rip + global+24] ; M hash factor (multiply)
|
||||
// mov cl, byte ptr [rip + global+32] ; S hash factor (shift)
|
||||
|
||||
// mov r10, qword ptr [r8 - 8] ; read a.vptr[-1] (&a)
|
||||
// mov r10, qword ptr [r8 - 8] ; read a.vptr[-1] (&a)
|
||||
|
||||
// imul r10, r9 ; multiply by M
|
||||
// imul r10, r9 ; multiply by M
|
||||
|
||||
// shr r10, cl ; index of method table for 'a'
|
||||
// mov r8, qword ptr [rip + global+40] ; address of global hash table
|
||||
// mov rax, qword ptr [rsi] ; read vptr of 'b'
|
||||
// imul r9, qword ptr [rax - 8] ; multiply b.vptr[-1] (&typeid(b)) by M
|
||||
// shr r10, cl ; index of method table for 'a'
|
||||
// mov r8, qword ptr [rip + global+40] ; address of global hash table
|
||||
// mov rax, qword ptr [rsi] ; read vptr of 'b'
|
||||
// imul r9, qword ptr [rax - 8] ; multiply b.vptr[-1] (&typeid(b)) by M
|
||||
|
||||
// mov rax, qword ptr [r8 + 8*r10] ; method table for 'a'
|
||||
// shr r9, cl ; index of method table for 'b'
|
||||
// mov rax, qword ptr [r8 + 8*r10] ; method table for 'a'
|
||||
// shr r9, cl ; index of method table for 'b'
|
||||
|
||||
// mov rcx, qword ptr [rip + method+96] ; offset of 'meet' in method table for 'a'
|
||||
// mov rcx, qword ptr [rip + method+96] ; offset of 'meet' in method table for 'a'
|
||||
|
||||
// mov r10, qword ptr [rax + 8*rcx] ; pointer to row for 'a' in dispatch table
|
||||
// mov rcx, qword ptr [r8 + 8*r9] ; method table for 'b'
|
||||
// mov rax, qword ptr [rip + method+104] ; offset of 'meet' in method table for 'b'
|
||||
// mov r10, qword ptr [rax + 8*rcx] ; pointer to row for 'a' in dispatch table
|
||||
// mov rcx, qword ptr [r8 + 8*r9] ; method table for 'b'
|
||||
// mov rax, qword ptr [rip + method+104] ; offset of 'meet' in method table for 'b'
|
||||
|
||||
// mov rax, qword ptr [rcx + 8*rax] ; column of 'b' in dispatch table
|
||||
// mov rax, qword ptr [rcx + 8*rax] ; column of 'b' in dispatch table
|
||||
|
||||
// imul rax, qword ptr [rip + method+112] ; multiply by # of lines in dispatch table
|
||||
// imul rax, qword ptr [rip + method+112] ; multiply by # of lines in dispatch table
|
||||
|
||||
// mov rax, qword ptr [r10 + 8*rax] ; pointer to function, at dispatch[a][b]
|
||||
// mov rax, qword ptr [r10 + 8*rax] ; pointer to function, at dispatch[a][b]
|
||||
|
||||
// jmp rax ; tail call
|
||||
// jmp rax ; tail call
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ BOOST_OPENMETHOD_CLASSES(Animal, Cat, Dog);
|
||||
BOOST_OPENMETHOD(trick, (std::ostream&, virtual_ptr<Animal>), void);
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
trick, (std::ostream & os, virtual_ptr<Dog> dog), void) {
|
||||
trick, (std::ostream & os, virtual_ptr<Dog> /*dog*/), void) {
|
||||
os << "spin\n";
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ auto main() -> int {
|
||||
for (auto animal : animals) {
|
||||
try {
|
||||
trick(std::cout, *animal);
|
||||
} catch (bom::not_implemented_error) {
|
||||
} catch (bom::not_implemented_error&) {
|
||||
std::cout << "not implemented\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ using boost::openmethod::virtual_;
|
||||
|
||||
BOOST_OPENMETHOD(poke, (std::ostream&, virtual_<Animal&>), void);
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(poke, (std::ostream & os, Cat& cat), void) {
|
||||
BOOST_OPENMETHOD_OVERRIDE(poke, (std::ostream & os, Cat& /*cat*/), void) {
|
||||
os << "hiss";
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class Cat : public Animal {
|
||||
|
||||
BOOST_OPENMETHOD(poke, (std::ostream&, virtual_<Animal&>), void);
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(poke, (std::ostream & os, Cat& cat), void) {
|
||||
BOOST_OPENMETHOD_OVERRIDE(poke, (std::ostream & os, Cat& /*cat*/), void) {
|
||||
os << "hiss\n";
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ class Cat : public Animal, public boost::openmethod::with_vptr<Cat, Animal> {
|
||||
|
||||
BOOST_OPENMETHOD(poke, (std::ostream&, virtual_<Animal&>), void);
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(poke, (std::ostream & os, Cat& cat), void) {
|
||||
BOOST_OPENMETHOD_OVERRIDE(poke, (std::ostream & os, Cat& /*cat*/), void) {
|
||||
os << "hiss\n";
|
||||
}
|
||||
// end::with_vptr[]
|
||||
|
||||
@@ -22,12 +22,12 @@ BOOST_OPENMETHOD_CLASSES(Animal, Cat, Dog);
|
||||
BOOST_OPENMETHOD(yell, (std::ostream&, virtual_ptr<Animal>), void);
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
yell, (std::ostream & os, virtual_ptr<Cat> cat), void) {
|
||||
yell, (std::ostream & os, virtual_ptr<Cat> /*cat*/), void) {
|
||||
os << "hiss";
|
||||
}
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
yell, (std::ostream & os, virtual_ptr<Dog> dog), void) {
|
||||
yell, (std::ostream & os, virtual_ptr<Dog> /*dog*/), void) {
|
||||
os << "bark";
|
||||
}
|
||||
|
||||
@@ -35,15 +35,15 @@ BOOST_OPENMETHOD(
|
||||
encounter, (std::ostream&, virtual_ptr<Animal>, virtual_ptr<Animal>), void);
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
encounter, (std::ostream & os, virtual_ptr<Dog> dog, virtual_ptr<Cat> cat),
|
||||
void) {
|
||||
encounter,
|
||||
(std::ostream & os, virtual_ptr<Dog> dog, virtual_ptr<Cat> /*cat*/), void) {
|
||||
yell(os, dog);
|
||||
os << " and chase";
|
||||
}
|
||||
|
||||
BOOST_OPENMETHOD_OVERRIDE(
|
||||
encounter, (std::ostream & os, virtual_ptr<Cat> cat, virtual_ptr<Dog> dog),
|
||||
void) {
|
||||
encounter,
|
||||
(std::ostream & os, virtual_ptr<Cat> cat, virtual_ptr<Dog> /*dog*/), void) {
|
||||
yell(os, cat);
|
||||
os << " and run";
|
||||
}
|
||||
|
||||
@@ -1150,12 +1150,6 @@ void compiler<Registry>::write_global_data() {
|
||||
++trace << "Initializing v-tables at " << gv_iter << "\n";
|
||||
|
||||
for (auto& cls : classes) {
|
||||
if (cls.first_slot == -1) {
|
||||
// corner case: no methods for this class
|
||||
*cls.static_vptr = gv_iter;
|
||||
continue;
|
||||
}
|
||||
|
||||
*cls.static_vptr = gv_iter - cls.first_slot;
|
||||
|
||||
++trace << rflush(4, gv_iter - gv_first) << " " << gv_iter
|
||||
|
||||
@@ -1492,12 +1492,34 @@ method<Name, ReturnType(Parameters...), Registry>::override_impl<
|
||||
Function, FnReturnType>::override_impl(FunctionPointer* p_next) {
|
||||
using namespace detail;
|
||||
|
||||
if (this->method) {
|
||||
BOOST_ASSERT(this->method == &fn);
|
||||
// static variable this->method below is zero-initialized but gcc and clang
|
||||
// don't always see that.
|
||||
|
||||
#ifdef BOOST_CLANG
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wuninitialized"
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_GCC
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wuninitialized"
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif
|
||||
|
||||
if (overrider_info::method) {
|
||||
BOOST_ASSERT(overrider_info::method == &fn);
|
||||
return;
|
||||
}
|
||||
|
||||
this->method = &fn;
|
||||
#ifdef BOOST_CLANG
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_GCC
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
overrider_info::method = &fn;
|
||||
|
||||
if constexpr (!Registry::deferred_static_rtti) {
|
||||
resolve_type_ids();
|
||||
|
||||
@@ -149,7 +149,8 @@ class with_vptr<Class, Base1, Base2, MoreBases...> : detail::with_vptr_derived {
|
||||
-> detail::with_vptr_policy<Base1>;
|
||||
friend auto boost_openmethod_bases(Class*)
|
||||
-> mp11::mp_list<Base1, Base2, MoreBases...>;
|
||||
friend auto boost_openmethod_vptr(const Class& obj, void* registry) -> vptr_type {
|
||||
friend auto boost_openmethod_vptr(const Class& obj, void* registry)
|
||||
-> vptr_type {
|
||||
return boost_openmethod_vptr(static_cast<const Base1&>(obj), registry);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -418,6 +418,6 @@ BOOST_AUTO_TEST_CASE(test_assign_slots_a1_c1_b1) {
|
||||
|
||||
BOOST_TEST_REQUIRE(get_method(comp, m_B).slots.size() == 1u);
|
||||
BOOST_TEST(get_method(comp, m_B).slots[0] == 2u);
|
||||
BOOST_TEST(get_class<B>(comp)->first_slot == 2);
|
||||
BOOST_TEST(get_class<B>(comp)->first_slot == 2u);
|
||||
BOOST_TEST(get_class<B>(comp)->vtbl.size() == 1u);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ struct Jet : Expense {};
|
||||
BOOST_OPENMETHOD_CLASSES(
|
||||
Role, Employee, Manager, Founder, Expense, Public, Bus, Metro, Taxi, Jet);
|
||||
|
||||
//static_assert(!virtual_ptr<Role>::IsSmartPtr);
|
||||
BOOST_OPENMETHOD(pay, (virtual_ptr<Employee>), double);
|
||||
BOOST_OPENMETHOD(
|
||||
approve, (virtual_ptr<const Role>, virtual_ptr<const Expense>, double),
|
||||
|
||||
@@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE(not_initialized) {
|
||||
} else {
|
||||
try {
|
||||
registry::check_initialized();
|
||||
} catch (not_initialized_error) {
|
||||
} catch (not_initialized_error&) {
|
||||
BOOST_TEST_FAIL("should have not thrown in release variant");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user