From 354f5b684bf73feeea429740600b051ded3c9a92 Mon Sep 17 00:00:00 2001 From: Roy Stogner Date: Fri, 11 Oct 2024 15:07:37 -0500 Subject: [PATCH] Workaround gcc 13 -Wdangling-reference warning I don't see how this could be an actual dangling reference, and gcc has bug reports specifically related to dangling reference false positives from lambda functions, but the test case in bug report https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111607 doesn't actually trigger my gcc version. This template metafunction workaround is much uglier code than the if constexpr, but it should compile to the same binary and it doesn't trigger any warnings. Closes #28835 --- .../include/auxkernels/MaterialAuxBase.h | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/framework/include/auxkernels/MaterialAuxBase.h b/framework/include/auxkernels/MaterialAuxBase.h index 1e4565188bcb..28fb1bf950f7 100644 --- a/framework/include/auxkernels/MaterialAuxBase.h +++ b/framework/include/auxkernels/MaterialAuxBase.h @@ -13,6 +13,10 @@ #include "AuxKernel.h" #include "Assembly.h" +// Forward declarations +template +struct PropSetter; + /** * A base class for the various Material related AuxKernal objects. * \p RT is short for return type @@ -61,6 +65,9 @@ class MaterialAuxBaseTempl : public AuxKernelTempl /// ID of the subdomain currently being iterated over const SubdomainID & _current_subdomain_id; + + /// Hack to avoid "dangling reference" warnings from gcc 13 + friend struct PropSetter; }; template @@ -90,16 +97,31 @@ MaterialAuxBaseTempl::validParams() return params; } +template +struct PropSetter +{ + static const Moose::Functor> & + prop(MaterialAuxBaseTempl & mabt) + { + return mabt.template getFunctor>("functor"); + } +}; + +template +struct PropSetter +{ + static const GenericMaterialProperty & + prop(MaterialAuxBaseTempl & mabt) + { + return mabt.template getGenericMaterialProperty("property"); + } +}; + template MaterialAuxBaseTempl::MaterialAuxBaseTempl( const InputParameters & parameters) : AuxKernelTempl(parameters), - _prop([this]() -> const auto & { - if constexpr (is_functor) - return this->template getFunctor>("functor"); - else - return this->template getGenericMaterialProperty("property"); - }()), + _prop(PropSetter::prop(*this)), _selected_qp(this->isParamValid("selected_qp") ? this->template getParam("selected_qp") : libMesh::invalid_uint),