the compiler notices that the Function object is immediately destroyed, and the chain of functions called on it are returning references. So it assumes (incorrectly??) that the final returned reference is dangling. (I'm not sure how the analysis works, and if it actually knows what it's doing when it makes an error phrasing this assertive).
/home/martijn/zec/3rd/Halide/src/Derivative.cpp: In lambda function:
/home/martijn/zec/3rd/Halide/src/Derivative.cpp:1819:42: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
1819 | const vector<ReductionVariable> &rvars =
| ^~~~~
/home/martijn/zec/3rd/Halide/src/Derivative.cpp:1820:73: note: the temporary was destroyed at the end of the full expression ‘(&(& Halide::Func::function() const().Halide::Internal::Function::update(update_id))->Halide::Internal::Definition::schedule())->Halide::Internal::StageSchedule::rvars()’
1820 | func_to_update.function().update(update_id).schedule().rvars();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
Cast doesn't use copy-constructor
The cast is nasty and reinterprets the datatype template argument
T
. Simply casting that no longer works without a warning.https://github.com/halide/Halide/blob/e55bd6f42bcfc0420adc393c29bf052a7609e041/src/runtime/HalideBuffer.h#L1432-L1454
Being explicit about this silences the compiler.
Dangling reference
While probably not true, for the line here:
https://github.com/halide/Halide/blob/e55bd6f42bcfc0420adc393c29bf052a7609e041/src/Derivative.cpp#L1819-L1820
the compiler notices that the Function object is immediately destroyed, and the chain of functions called on it are returning references. So it assumes (incorrectly??) that the final returned reference is dangling. (I'm not sure how the analysis works, and if it actually knows what it's doing when it makes an error phrasing this assertive).