[v1] android: camera_capabilities: Fix GCC 14 warning
diff mbox series

Message ID 20240525165053.46330-1-pobrn@protonmail.com
State Accepted
Commit c79fa47aac9b38865dab5e9f29030903bf460c46
Headers show
Series
  • [v1] android: camera_capabilities: Fix GCC 14 warning
Related show

Commit Message

Barnabás Pőcze May 25, 2024, 4:50 p.m. UTC
GCC 14 thinks `rects` is a "possibly dangling reference to a temporary",
which causes the compilation to fail due to the use of `-Werror`.

Fix this by not using a reference.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
---
 src/android/camera_capabilities.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Kieran Bingham May 27, 2024, 10:29 a.m. UTC | #1
Quoting Barnabás Pőcze (2024-05-25 17:50:55)
> GCC 14 thinks `rects` is a "possibly dangling reference to a temporary",
> which causes the compilation to fail due to the use of `-Werror`.

The error message from GCC might be more useful. The fact it fails due
to the use of -Werror is just a side effect of the warning, and that we
aim to be warning free.

> 
> Fix this by not using a reference.
> 
> Signed-off-by: Barnabás Pőcze <pobrn@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>{});

Presumably this means it will make a copy of the Span. But that's
incredible cheap so not an issue?

I don't object to it - and with the compiler warning clarified (which is
the underlying justification for the change):

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

>                 std::vector<int32_t> data{
>                         static_cast<int32_t>(rects[0].x),
> -- 
> 2.45.1
> 
>
Laurent Pinchart May 27, 2024, 11:01 a.m. UTC | #2
On Mon, May 27, 2024 at 11:29:57AM +0100, Kieran Bingham wrote:
> Quoting Barnabás Pőcze (2024-05-25 17:50:55)
> > GCC 14 thinks `rects` is a "possibly dangling reference to a temporary",
> > which causes the compilation to fail due to the use of `-Werror`.
> 
> The error message from GCC might be more useful. The fact it fails due
> to the use of -Werror is just a side effect of the warning, and that we
> aim to be warning free.
> 
> > 
> > Fix this by not using a reference.
> > 
> > Signed-off-by: Barnabás Pőcze <pobrn@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>{});
> 
> Presumably this means it will make a copy of the Span. But that's
> incredible cheap so not an issue?

Correct, it's cheap. It seems to be a false positive from gcc though.
I'm curious to see the exact error message.

> I don't object to it - and with the compiler warning clarified (which is
> the underlying justification for the change):
> 
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>
> >                 std::vector<int32_t> data{
> >                         static_cast<int32_t>(rects[0].x),

Patch
diff mbox series

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),