Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround gcc 13 -Wdangling-reference warning #28837

Draft
wants to merge 1 commit into
base: next
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions framework/include/auxkernels/MaterialAuxBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include "AuxKernel.h"
#include "Assembly.h"

// Forward declarations
template <typename T, bool is_ad, bool is_functor, typename RT>
struct PropSetter;

/**
* A base class for the various Material related AuxKernal objects.
* \p RT is short for return type
Expand Down Expand Up @@ -61,6 +65,9 @@ class MaterialAuxBaseTempl : public AuxKernelTempl<RT>

/// 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<T, is_ad, is_functor, RT>;
};

template <typename T, bool is_ad, bool is_functor, typename RT>
Expand Down Expand Up @@ -90,16 +97,31 @@ MaterialAuxBaseTempl<T, is_ad, is_functor, RT>::validParams()
return params;
}

template <typename T, bool is_ad, bool is_functor, typename RT>
struct PropSetter
{
static const Moose::Functor<Moose::GenericType<T, is_ad>> &
prop(MaterialAuxBaseTempl<T, is_ad, is_functor, RT> & mabt)
{
return mabt.template getFunctor<Moose::GenericType<T, is_ad>>("functor");
}
};

template <typename T, bool is_ad, typename RT>
struct PropSetter<T, is_ad, false, RT>
{
static const GenericMaterialProperty<T, is_ad> &
prop(MaterialAuxBaseTempl<T, is_ad, false, RT> & mabt)
{
return mabt.template getGenericMaterialProperty<T, is_ad>("property");
}
};

template <typename T, bool is_ad, bool is_functor, typename RT>
MaterialAuxBaseTempl<T, is_ad, is_functor, RT>::MaterialAuxBaseTempl(
const InputParameters & parameters)
: AuxKernelTempl<RT>(parameters),
_prop([this]() -> const auto & {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤮

if constexpr (is_functor)
return this->template getFunctor<Moose::GenericType<T, is_ad>>("functor");
else
return this->template getGenericMaterialProperty<T, is_ad>("property");
}()),
_prop(PropSetter<T, is_ad, is_functor, RT>::prop(*this)),
_selected_qp(this->isParamValid("selected_qp")
? this->template getParam<unsigned int>("selected_qp")
: libMesh::invalid_uint),
Expand Down