On 1/25/24 20:37, Marek Polacek wrote:
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
-- >8 --
Since -Wdangling-reference has false positives that can't be
prevented, we should offer an easy way to suppress the warning.
Currently, that is only possible by using a #pragma, either around the
enclosing class or around the call site. But #pragma GCC diagnostic tend
to be onerous. A better solution would be to have an attribute. Such
an attribute should not be tied to this particular warning though. [*]
The warning bogusly triggers for classes that are like std::span,
std::reference_wrapper, and std::ranges::ref_view. The common property
seems to be that these classes are only wrappers around some data. So
I chose the name non_owning, but I'm not attached to it. I hope that
in the future the attribute can be used for something other than this
diagnostic.
You decided not to pursue Barry's request for a bool argument to the
attribute?
Might it be more useful for the attribute to make reference_like_class_p
return true, so that we still warn about a temporary of another type
passing through it?
Jason