| Message ID | 20260107193607.2168539-3-barnabas.pocze@ideasonboard.com |
|---|---|
| State | New |
| Headers | show |
| Series |
|
| Related | show |
Hi Barnabás, Thank you for the patch. On Wed, Jan 07, 2026 at 08:36:04PM +0100, Barnabás Pőcze wrote: > 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. Reading https://en.cppreference.com/w/cpp/language/return.html, do I understand correctly that in C++20 the following clause stops applying, and that's what causes the difference in behaviour due to the "formally" part ? or it succeeded, but did not select the move constructor (formally, the first parameter of the selected constructor was not an rvalue reference to the (possibly cv-qualified) type of expression) > 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> > --- > meson.build | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/meson.build b/meson.build > index 4aa7ecc96..1d8e1d994 100644 > --- a/meson.build > +++ b/meson.build > @@ -168,7 +168,7 @@ if cc.get_id() == 'gcc' > # 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. Expanding the context: # 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. This would look odd compared to the version check below. We can't just s/13/11/ as that wouldn't be correct, so we probably need to list both versions with their corresponding behaviour. > - if cc.version().version_compare('>=13') > + if cc.version().version_compare('>=11') > cpp_arguments += [ > '-Wno-redundant-move', > ]
2026. 01. 07. 21:25 keltezéssel, Laurent Pinchart írta: > Hi Barnabás, > > Thank you for the patch. > > On Wed, Jan 07, 2026 at 08:36:04PM +0100, Barnabás Pőcze wrote: >> 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. > > Reading https://en.cppreference.com/w/cpp/language/return.html, do I > understand correctly that in C++20 the following clause stops applying, > and that's what causes the difference in behaviour due to the "formally" > part ? > > or it succeeded, but did not select the move constructor (formally, > the first parameter of the selected constructor was not an rvalue > reference to the (possibly cv-qualified) type of expression) I believe the relevant document is https://wg21.link/p1155r3#slicing > >> 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> >> --- >> meson.build | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/meson.build b/meson.build >> index 4aa7ecc96..1d8e1d994 100644 >> --- a/meson.build >> +++ b/meson.build >> @@ -168,7 +168,7 @@ if cc.get_id() == 'gcc' >> # 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. > > Expanding the context: > > # 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. > > This would look odd compared to the version check below. We can't just > s/13/11/ as that wouldn't be correct, so we probably need to list both > versions with their corresponding behaviour. This is the behaviour of when object slicing in the return statement: -std=c++17 -std=c++20 8: move move 9: copy copy 10: copy copy 11: copy move 12: copy move 13: move move 14: move move 15: move move Since GCC 8 is not supported. I think it is enough to just state that since GCC 11 automatic move happens when the object is sliced, which is I think the problematic case for libcamera. > >> - if cc.version().version_compare('>=13') >> + if cc.version().version_compare('>=11') >> cpp_arguments += [ >> '-Wno-redundant-move', >> ] >
diff --git a/meson.build b/meson.build index 4aa7ecc96..1d8e1d994 100644 --- a/meson.build +++ b/meson.build @@ -168,7 +168,7 @@ if cc.get_id() == 'gcc' # 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') + if cc.version().version_compare('>=11') cpp_arguments += [ '-Wno-redundant-move', ]
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> --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)