fraunhoferhhi / vvenc

VVenC, the Fraunhofer Versatile Video Encoder
https://www.hhi.fraunhofer.de/en/departments/vca/technologies-and-solutions/h266-vvc.html
BSD 3-Clause Clear License
966 stars 173 forks source link

Fix added this local variables by value #437

Closed Jamaika1 closed 1 month ago

Jamaika1 commented 1 month ago
NoMallocThreadPool.h: In lambda function:
NoMallocThreadPool.h:220:31: warning: implicit capture of 'this' via '[=]' is deprecated in C++20 [-Wdeprecated]
  220 |     nonconst->m_cond.wait( l, [=] { return m_count == 0; } );
      |                               ^
NoMallocThreadPool.h:220:31: note: add explicit 'this' or '*this' capture
jakubjelinek commented 1 month ago

Explicit capture of this is only valid in C++20 and later. See the C++20 https://wg21.link/p0409r2 paper.

adamjw24 commented 1 month ago

Explicit capture of this is only valid in C++20 and later. See the C++20 https://wg21.link/p0409r2 paper.

So there as is a new feature that is syntax incompatible with previous versions but not using it breaks the code as well? Great design philosophy/s.

adamjw24 commented 1 month ago

@Jamaika1 our code is written using C++14 (set( CMAKE_CXX_STANDARD 14 )), so your guard is guaranteed to be false, is thus unnecessary. I don't know why and how this is overwritten, but the fact that it is is your actual bug. Closing.

jwakely commented 1 month ago

Explicit capture of this is only valid in C++20 and later. See the C++20 https://wg21.link/p0409r2 paper.

So there as is a new feature that is syntax incompatible with previous versions but not using it breaks the code as well? Great design philosophy/s.

Jakub's comment is a bit misleading.

There's a new feature that is only valid in C++20, i.e. [=, this].

But the previous behaviour of [=] can just be replaced with [this] in your code, because the only thing you're trying to capture is this. That is perfectly valid in all versions of C++ from C++11 upwards.

So the correct fix here is to replace [=] with [this] and not have any #if conditional code.

jwakely commented 1 month ago

(and it was only a warning anyway, so the old syntax is still compatible in C++20)

K-os commented 1 month ago

@jwakely : Thank you very much for the clarification. I didn't know [=, this] was disallowed pre c++17. I thought it was just redundant.