Skip to content

Commit efbc135

Browse files
committed
fix type_ids of virtual_ptr args in bad_call
1 parent 830c3ce commit efbc135

2 files changed

Lines changed: 36 additions & 10 deletions

File tree

include/boost/openmethod/core.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,10 +1938,10 @@ struct init_bad_call {
19381938

19391939
type_id arg_type_id;
19401940

1941-
if constexpr (Rtti::template is_polymorphic<Arg>) {
1942-
arg_type_id = Rtti::template dynamic_type<Arg>(arg);
1941+
if constexpr (is_virtual_ptr<Arg>) {
1942+
arg_type_id = Rtti::template dynamic_type(*arg);
19431943
} else {
1944-
arg_type_id = Rtti::template static_type<Arg>();
1944+
arg_type_id = Rtti::template dynamic_type(arg);
19451945
}
19461946

19471947
error.types[Index] = arg_type_id;

test/test_runtime_errors.cpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE(no_initialization) {
8989
try {
9090
registry::require_initialized();
9191
} catch (not_initialized&) {
92-
BOOST_TEST_FAIL("should have not thrown in release variant");
92+
BOOST_TEST_FAIL("should not have thrown in release variant");
9393
}
9494
}
9595
}
@@ -155,14 +155,22 @@ using registry = errors_<__COUNTER__>;
155155
BOOST_OPENMETHOD_CLASSES(matrix, dense_matrix, diagonal_matrix, registry);
156156

157157
BOOST_OPENMETHOD(
158-
times, (virtual_<const matrix&>, virtual_<const matrix&>), void, registry);
158+
times,
159+
(virtual_ptr<const matrix, registry>, virtual_ptr<const matrix, registry>),
160+
void, registry);
159161

160162
BOOST_OPENMETHOD_OVERRIDE(
161-
times, (const matrix&, const diagonal_matrix&), void) {
163+
times,
164+
(virtual_ptr<const matrix, registry>,
165+
virtual_ptr<const diagonal_matrix, registry>),
166+
void) {
162167
}
163168

164169
BOOST_OPENMETHOD_OVERRIDE(
165-
times, (const diagonal_matrix&, const matrix&), void) {
170+
times,
171+
(virtual_ptr<const diagonal_matrix, registry>,
172+
virtual_ptr<const matrix, registry>),
173+
void) {
166174
}
167175

168176
BOOST_AUTO_TEST_CASE(bad_call) {
@@ -172,18 +180,36 @@ BOOST_AUTO_TEST_CASE(bad_call) {
172180

173181
{
174182
registry::capture capture;
175-
BOOST_CHECK_THROW(times(matrix(), matrix()), no_overrider);
183+
matrix a, b;
184+
BOOST_CHECK_THROW(times(a, b), no_overrider);
176185
BOOST_TEST(capture().find("not implemented") != std::string::npos);
177186
}
178187

179188
{
180189
registry::capture capture;
181-
BOOST_CHECK_THROW(
182-
times(diagonal_matrix(), diagonal_matrix()), ambiguous_call);
190+
diagonal_matrix a, b;
191+
BOOST_CHECK_THROW(times(a, b), ambiguous_call);
183192
BOOST_TEST(capture().find("ambiguous") != std::string::npos);
184193
}
185194
}
186195

196+
BOOST_AUTO_TEST_CASE(bad_call_type_ids) {
197+
auto report = initialize<registry>().report;
198+
registry::capture capture;
199+
200+
try {
201+
diagonal_matrix a, b;
202+
times(a, b);
203+
BOOST_FAIL("should have thrown");
204+
} catch (const ambiguous_call& error) {
205+
BOOST_TEST(error.arity == 2u);
206+
BOOST_TEST(error.types[0] == &typeid(diagonal_matrix));
207+
BOOST_TEST(error.types[1] == &typeid(diagonal_matrix));
208+
} catch (...) {
209+
BOOST_FAIL("wrong exception");
210+
}
211+
}
212+
187213
} // namespace TEST_NS
188214

189215
namespace TEST_NS {

0 commit comments

Comments
 (0)