[RFC,v2,2/7] meson: Ignore `Wredundant-move` with GCC 11 and above
diff mbox series

Message ID 20260323102724.1385487-3-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • C++20 migration
Related show

Commit Message

Barnabás Pőcze March 23, 2026, 10:27 a.m. UTC
In C++20 mode, object slicing in a return statement triggers automatic move
since GCC 11, and using `std::move()` emits `-Wredundant-move` in those
same GCC versions. So disable the warning in those as well.

This is relevant for `valueOrTuple()` in `py_helpers.cpp`, which
returns a `py::tuple` as `py::object`.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 meson.build | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

Comments

Kieran Bingham March 23, 2026, 5:03 p.m. UTC | #1
Quoting Barnabás Pőcze (2026-03-23 10:27:19)
> In C++20 mode, object slicing in a return statement triggers automatic move
> since GCC 11, and using `std::move()` emits `-Wredundant-move` in those
> same GCC versions. So disable the warning in those as well.
> 
> This is relevant for `valueOrTuple()` in `py_helpers.cpp`, which
> returns a `py::tuple` as `py::object`.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

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

> ---
>  meson.build | 21 +++++++++++----------
>  1 file changed, 11 insertions(+), 10 deletions(-)
> 
> diff --git a/meson.build b/meson.build
> index 82867f82b..fa38fa2c0 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -159,16 +159,17 @@ if cc.get_id() == 'gcc'
>          error('gcc version is too old, libcamera requires 9.0 or newer')
>      endif
>  
> -    # gcc 13 implements the C++23 version of automatic move from local
> -    # variables in return statements (see
> -    # https://en.cppreference.com/w/cpp/language/return). As a result, some
> -    # previously required explicit std::move() in return statements generate
> -    # warnings. Those moves can't be removed as older compiler versions could
> -    # use copy constructors instead of move constructors. The easiest fix is to
> -    # disable the warning. With -Wpessimizing-move enabled, the compiler will
> -    # still warn of pessimizing moves, only the redundant but not pessimizing
> -    # moves will be ignored.
> -    if cc.version().version_compare('>=13')
> +    # In C++20 mode, prior to gcc 11, object slicing in a return statement didn't
> +    # perform automatic move. It required explicit std::move() usage, which now
> +    # generate warnings. Those moves can't be removed as older compiler versions
> +    # could use copy constructors instead of move constructors. The easiest fix
> +    # is to disable the warning. With -Wpessimizing-move enabled, the compiler
> +    # will still warn of pessimizing moves, only the redundant but not
> +    # pessimizing moves will be ignored.
> +    #
> +    # \todo When dropping support for compilers older than gcc 11, drop the
> +    # argument and remove the unneeded std::move() calls.
> +    if cc.version().version_compare('>=11')
>          cpp_arguments += [
>              '-Wno-redundant-move',
>          ]
> -- 
> 2.53.0
>

Patch
diff mbox series

diff --git a/meson.build b/meson.build
index 82867f82b..fa38fa2c0 100644
--- a/meson.build
+++ b/meson.build
@@ -159,16 +159,17 @@  if cc.get_id() == 'gcc'
         error('gcc version is too old, libcamera requires 9.0 or newer')
     endif
 
-    # gcc 13 implements the C++23 version of automatic move from local
-    # variables in return statements (see
-    # https://en.cppreference.com/w/cpp/language/return). As a result, some
-    # previously required explicit std::move() in return statements generate
-    # warnings. Those moves can't be removed as older compiler versions could
-    # use copy constructors instead of move constructors. The easiest fix is to
-    # disable the warning. With -Wpessimizing-move enabled, the compiler will
-    # still warn of pessimizing moves, only the redundant but not pessimizing
-    # moves will be ignored.
-    if cc.version().version_compare('>=13')
+    # In C++20 mode, prior to gcc 11, object slicing in a return statement didn't
+    # perform automatic move. It required explicit std::move() usage, which now
+    # generate warnings. Those moves can't be removed as older compiler versions
+    # could use copy constructors instead of move constructors. The easiest fix
+    # is to disable the warning. With -Wpessimizing-move enabled, the compiler
+    # will still warn of pessimizing moves, only the redundant but not
+    # pessimizing moves will be ignored.
+    #
+    # \todo When dropping support for compilers older than gcc 11, drop the
+    # argument and remove the unneeded std::move() calls.
+    if cc.version().version_compare('>=11')
         cpp_arguments += [
             '-Wno-redundant-move',
         ]