[PATCH v2] android: camera_capabilities: Fix GCC 14 warning
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Mon May 27 18:24:16 CEST 2024
On Mon, May 27, 2024 at 02:34:19PM +0100, Kieran Bingham wrote:
> Quoting Barnabás Pőcze (2024-05-27 14:24:29)
> > GCC 14 thinks `rects` is a "possibly dangling reference to a temporary":
> >
> > /libcamera/src/android/camera_capabilities.cpp: In member function ‘int CameraCapabilities::initializeStaticMetadata()’:
> > /libcamera/src/android/camera_capabilities.cpp:1084:46: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
> > 1084 | const Span<const Rectangle>& rects =
> > | ^~~~~
> > /libcamera/src/android/camera_capabilities.cpp:1085:83: note: the temporary was destroyed at the end of the full expression ‘(& properties)->libcamera::ControlList::get<libcamera::Span<const libcamera::Rectangle> >(libcamera::properties::PixelArrayActiveAreas).std::optional<libcamera::Span<const libcamera::Rectangle> >::value_or<libcamera::Span<const libcamera::Rectangle> >(libcamera::Span<const libcamera::Rectangle>())’
> > 1085 | properties.get(properties::PixelArrayActiveAreas).value_or(Span<const Rectangle>{});
> > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > The return value of `value_or()` is indeed a temporary, but
> > binding it to a reference extends its lifetime. Avoid the
> > warning by not using a reference; this does not make much
> > difference since `value_or()` does not return a reference.
>
> Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
I'm working on adding gcc 14 tests in our CI.
> > Signed-off-by: Barnabás Pőcze <pobrn at protonmail.com>
> > ---
> > src/android/camera_capabilities.cpp | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp
> > index 6f4d48de..71043e12 100644
> > --- a/src/android/camera_capabilities.cpp
> > +++ b/src/android/camera_capabilities.cpp
> > @@ -1081,7 +1081,7 @@ int CameraCapabilities::initializeStaticMetadata()
> > }
> >
> > {
> > - const Span<const Rectangle> &rects =
> > + const Span<const Rectangle> rects =
> > properties.get(properties::PixelArrayActiveAreas).value_or(Span<const Rectangle>{});
> > std::vector<int32_t> data{
> > static_cast<int32_t>(rects[0].x),
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list