diff --git a/library/modules/Job.cpp b/library/modules/Job.cpp index 1976d2e12..869a6b329 100644 --- a/library/modules/Job.cpp +++ b/library/modules/Job.cpp @@ -387,7 +387,14 @@ bool DFHack::Job::removeJob(df::job* job) { // call the job cancel vmethod graciously provided by The Toady One. // job_handler::cancel_job calls job::~job, and then deletes job (this has // been confirmed by disassembly). - world->jobs.cancel_job(job); + + // HACK: GCC (starting around GCC 10 targeting C++20 as of v50.09) optimizes + // out the vmethod call here regardless of optimization level, so we need to + // invoke the vmethod manually through a pointer, as the Lua wrapper does. + // `volatile` does not seem to be necessary but is included for good + // measure. + volatile auto cancel_job_method = &df::job_handler::cancel_job; + (world->jobs.*cancel_job_method)(job); return true; }