Skip to content

Commit c6d4fbb

Browse files
committed
Add tests for const dynamic cast
1 parent 54a8f8e commit c6d4fbb

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

.github/workflows/test-linux-mac.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ jobs:
2020
- "nightly"
2121
os:
2222
- ubuntu-latest
23-
- macos-13
23+
- macos-15-intel
2424
arch:
2525
- x64
2626
include:
27-
- os: macos-14
27+
- os: macos-latest
2828
arch: aarch64
2929
version: "1.10"
30-
- os: macos-14
30+
- os: macos-latest
3131
arch: aarch64
3232
version: "nightly"
3333
steps:
@@ -50,7 +50,7 @@ jobs:
5050
CXXFLAGS=-ftemplate-backtrace-limit=0 cmake -DCMAKE_INSTALL_PREFIX=$HOME/install -DAPPEND_OVERRIDES_TOML=ON -DCMAKE_BUILD_TYPE=Debug ..
5151
VERBOSE=ON cmake --build . --config Debug --target install
5252
wget https://github.com/JuliaRegistries/General/raw/refs/heads/master/jll/L/libcxxwrap_julia_jll/Versions.toml
53-
jllversion=0.14.2 #$(grep '\["' Versions.toml | tail -n 1 | sed -E 's/\["([0-9]+\.[0-9]+\.[0-9]+)\+[^"]*"\]/\1/g')
53+
jllversion=$(grep '\["' Versions.toml | tail -n 1 | sed -E 's/\["([0-9]+\.[0-9]+\.[0-9]+)\+[^"]*"\]/\1/g')
5454
cd lib
5555
if [ ! -f libcxxwrap_julia.${jllversion}.dylib ]; then
5656
ln -s libcxxwrap_julia.*.*.*.* libcxxwrap_julia.${jllversion}.dylib

examples/inheritance.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,25 @@ namespace virtualsolver
180180
};
181181
}
182182

183+
struct Parent {
184+
virtual std::string name() const { return "Parent"; }
185+
virtual ~Parent() = default;
186+
};
187+
188+
struct DerivedA : public Parent {
189+
std::string name() const override { return "DerivedA"; }
190+
};
191+
192+
struct DerivedB : public Parent {
193+
std::string name() const override { return "DerivedB"; }
194+
};
195+
196+
197+
Parent* make_a() { return new DerivedA(); }
198+
Parent* make_b() { return new DerivedB(); }
199+
const Parent* make_const_a() { return new const DerivedA(); }
200+
const Parent* make_const_b() { return new const DerivedB(); }
201+
183202
namespace jlcxx
184203
{
185204
// Needed for upcasting
@@ -196,6 +215,9 @@ namespace jlcxx
196215
template<> struct IsMirroredType<StaticBase> : std::false_type { };
197216
template<> struct IsMirroredType<StaticDerived> : std::false_type { };
198217
template<> struct SuperType<StaticDerived> { typedef StaticBase type; };
218+
219+
template<> struct SuperType<DerivedA> { typedef Parent type; };
220+
template<> struct SuperType<DerivedB> { typedef Parent type; };
199221
}
200222

201223
JLCXX_MODULE define_types_module(jlcxx::Module& types)
@@ -230,6 +252,20 @@ JLCXX_MODULE define_types_module(jlcxx::Module& types)
230252
.constructor<int, double>()
231253
.method("getData", &VirtualCfunctionExtended::getData)
232254
.method("set_callback", &VirtualCfunctionExtended::set_callback);
255+
256+
types.add_type<Parent>("Parent")
257+
.method("name", &Parent::name);
258+
259+
types.add_type<DerivedA>("DerivedA", jlcxx::julia_base_type<Parent>())
260+
.method("name", &DerivedA::name);
261+
262+
types.add_type<DerivedB>("DerivedB", jlcxx::julia_base_type<Parent>())
263+
.method("name", &DerivedB::name);
264+
265+
types.method("make_a", &make_a);
266+
types.method("make_b", &make_b);
267+
types.method("make_const_a", &make_const_a);
268+
types.method("make_const_b", &make_const_b);
233269
}
234270

235271
JLCXX_MODULE define_vsolver_module(jlcxx::Module& vsolver_mod)

0 commit comments

Comments
 (0)