[{"id":36789,"web_url":"https://patchwork.libcamera.org/comment/36789/","msgid":"<176303540741.567526.12694728534244247378@ping.linuxembedded.co.uk>","date":"2025-11-13T12:03:27","subject":"Re: [RFC PATCH v1 1/1] treewide: Update to the C++20 standard","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Naush,\n\nQuoting Naushir Patuck (2025-11-13 11:05:31)\n> Switch to using the C++20 standard when compiling libcamera. This causes\n> a build error due to the deprecation of the following specialisation [1]\n> \n> std::shared_ptr<T> atomic_load(const std::shared_ptr<T>* p)\n> \n> ../src/libcamera/base/log.cpp: In member function 'void libcamera::Logger::write(const libcamera::LogMessage&)':\n> ../src/libcamera/base/log.cpp:468:61: error: 'std::shared_ptr<_Tp> std::atomic_load(const shared_ptr<_Tp>*) [with _Tp = libcamera::LogOutput]' is deprecated: use 'std::atomic<std::shared_ptr<T>>' instead [-Werror=deprecated-declarations]\n>   468 |         std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n>       |                                             ~~~~~~~~~~~~~~~~^~~~~~~~~~\n> \n> This error is fixed by switching to the std::atomic<std::shared_ptr<T>>\n> specialisation instead. Unfortunately, this is not backward compatible\n> with C++17, so the fix must be included in this commit.\n\nThank you for this,\n\nI think I'm in favour of updating here when we can.\n\nWe'll have to do a bit of a check to see if this impacts any projects\nusing libcamera but I think it's workable.\n\nFirst part though will be CI:\n\n https://gitlab.freedesktop.org/camera/libcamera/-/pipelines/1546400\n\nQuite a few breakages to tackle and that may be the hard part.\n\nWith a large matrix of compilers and differing support that might be the\ntricky part. We'll have to identify if this will restict us to any\nspecific compiler version minimum.\n\n--\nKieran\n\n\n> \n> [1]: https://en.cppreference.com/w/cpp/memory/shared_ptr/atomic.html\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> ---\n>  meson.build                | 2 +-\n>  src/libcamera/base/log.cpp | 6 +++---\n>  2 files changed, 4 insertions(+), 4 deletions(-)\n> \n> diff --git a/meson.build b/meson.build\n> index fd508fd7f6b5..74153e1e6ce9 100644\n> --- a/meson.build\n> +++ b/meson.build\n> @@ -6,7 +6,7 @@ project('libcamera', 'c', 'cpp',\n>      default_options : [\n>          'werror=true',\n>          'warning_level=2',\n> -        'cpp_std=c++17',\n> +        'cpp_std=c++20',\n>      ],\n>      license : 'LGPL 2.1+')\n>  \n> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\n> index 81b550e21402..e65d83739315 100644\n> --- a/src/libcamera/base/log.cpp\n> +++ b/src/libcamera/base/log.cpp\n> @@ -325,7 +325,7 @@ private:\n>         std::vector<std::unique_ptr<LogCategory>> categories_ LIBCAMERA_TSA_GUARDED_BY(mutex_);\n>         std::list<std::pair<std::string, LogSeverity>> levels_;\n>  \n> -       std::shared_ptr<LogOutput> output_;\n> +       std::atomic<std::shared_ptr<LogOutput>> output_;\n>  };\n>  \n>  bool Logger::destroyed_ = false;\n> @@ -465,7 +465,7 @@ Logger *Logger::instance()\n>   */\n>  void Logger::write(const LogMessage &msg)\n>  {\n> -       std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n> +       std::shared_ptr<LogOutput> output = output_.load();\n>         if (!output)\n>                 return;\n>  \n> @@ -477,7 +477,7 @@ void Logger::write(const LogMessage &msg)\n>   */\n>  void Logger::backtrace()\n>  {\n> -       std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n> +       std::shared_ptr<LogOutput> output = output_.load();\n>         if (!output)\n>                 return;\n>  \n> -- \n> 2.51.0\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 49764C3263\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 13 Nov 2025 12:03:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 74517609D8;\n\tThu, 13 Nov 2025 13:03:32 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0C8B160805\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Nov 2025 13:03:31 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9E85F446;\n\tThu, 13 Nov 2025 13:01:30 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"cbLujg9c\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763035290;\n\tbh=izK8NWYr8zcoRkmyZI4al75lRUsaoRdFbVVgu4LoRe4=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=cbLujg9cn5ZD0kmweBL65CQmINognNdZyj/d6JxThEn8mz2P5Kr3+9IsVxQisXxqg\n\t1KUnGC8sd9wbwDrYqOkPuHKl7ctF72yiFrc/f/vguc0ERUizG5VjcO60+G73jP52dX\n\tU1LDj7WDW5B0UDFLF8XNDREgLvRLIqXKPg9kKqlg=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251113110958.1117065-2-naush@raspberrypi.com>","References":"<20251113110958.1117065-1-naush@raspberrypi.com>\n\t<20251113110958.1117065-2-naush@raspberrypi.com>","Subject":"Re: [RFC PATCH v1 1/1] treewide: Update to the C++20 standard","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Naushir Patuck <naush@raspberrypi.com>","To":"Naushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 13 Nov 2025 12:03:27 +0000","Message-ID":"<176303540741.567526.12694728534244247378@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":36790,"web_url":"https://patchwork.libcamera.org/comment/36790/","msgid":"<a6edb8dc-e0ac-469b-9993-0ffaaa6d3fc6@ideasonboard.com>","date":"2025-11-13T12:24:18","subject":"Re: [RFC PATCH v1 1/1] treewide: Update to the C++20 standard","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"2025. 11. 13. 13:03 keltezéssel, Kieran Bingham írta:\n> Hi Naush,\n> \n> Quoting Naushir Patuck (2025-11-13 11:05:31)\n>> Switch to using the C++20 standard when compiling libcamera. This causes\n>> a build error due to the deprecation of the following specialisation [1]\n>>\n>> std::shared_ptr<T> atomic_load(const std::shared_ptr<T>* p)\n>>\n>> ../src/libcamera/base/log.cpp: In member function 'void libcamera::Logger::write(const libcamera::LogMessage&)':\n>> ../src/libcamera/base/log.cpp:468:61: error: 'std::shared_ptr<_Tp> std::atomic_load(const shared_ptr<_Tp>*) [with _Tp = libcamera::LogOutput]' is deprecated: use 'std::atomic<std::shared_ptr<T>>' instead [-Werror=deprecated-declarations]\n>>    468 |         std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n>>        |                                             ~~~~~~~~~~~~~~~~^~~~~~~~~~\n>>\n>> This error is fixed by switching to the std::atomic<std::shared_ptr<T>>\n>> specialisation instead. Unfortunately, this is not backward compatible\n>> with C++17, so the fix must be included in this commit.\n> \n> Thank you for this,\n> \n> I think I'm in favour of updating here when we can.\n> \n> We'll have to do a bit of a check to see if this impacts any projects\n> using libcamera but I think it's workable.\n> \n> First part though will be CI:\n> \n>   https://gitlab.freedesktop.org/camera/libcamera/-/pipelines/1546400\n> \n> Quite a few breakages to tackle and that may be the hard part.\n\nI have been compiling libcamera as C++20 forever. Apart from the above\nchange, one needs to:\n\n  (1) disable -Wvolatile because of g_once_init() in glib\n  (2) disable -Wredundant-move in gcc 12 as well\n\n---\n\nAs far as I remember `std::atomic<std::shared_ptr<>>` is not supported\nin some versions, so I ended up using\n\n   #pragma GCC diagnostic ignored \"-Wdeprecated-declarations\"\n\n---\n\nAlso, libpisp did not compile without warnings in C++20 the last time I checked.\n\n---\n\nThere is also this peculiar issue: https://gitlab.freedesktop.org/camera/libcamera/-/issues/267\n\n---\n\nC++20 also triggers this error: https://gitlab.freedesktop.org/camera/libcamera/-/jobs/87812672#L364\n\n/usr/include/c++/12/bits/char_traits.h:431:56: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 9223372036854775810 or more bytes at offsets [2, 9223372036854775807] and 1 may overlap up to 9223372036854775813 bytes at offset -3 [-Werror=restrict]\n   431 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));\n\n\nAfter some time I have given up on trying to fix this.\n\n---\n\nActually, to address (1), it should be sufficient to use `std::call_once()`, e.g.\n\ndiff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp\nindex d4492d994b..3de6fc42a7 100644\n--- a/src/gstreamer/gstlibcameraallocator.cpp\n+++ b/src/gstreamer/gstlibcameraallocator.cpp\n@@ -8,6 +8,7 @@\n  \n  #include \"gstlibcameraallocator.h\"\n  \n+#include <mutex>\n  #include <utility>\n  \n  #include <libcamera/camera.h>\n@@ -77,11 +78,11 @@ FrameWrap::~FrameWrap()\n  GQuark FrameWrap::getQuark()\n  {\n         static gsize frame_quark = 0;\n+       static std::once_flag frame_quark_once;\n  \n-       if (g_once_init_enter(&frame_quark)) {\n-               GQuark quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n-               g_once_init_leave(&frame_quark, quark);\n-       }\n+       std::call_once(frame_quark_once, [&] {\n+               frame_quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n+       });\n  \n         return frame_quark;\n  }\n\n\nRegards,\nBarnabás Pőcze\n\n> \n> With a large matrix of compilers and differing support that might be the\n> tricky part. We'll have to identify if this will restict us to any\n> specific compiler version minimum.\n> \n> --\n> Kieran\n> \n> \n>>\n>> [1]: https://en.cppreference.com/w/cpp/memory/shared_ptr/atomic.html\n>> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n>> ---\n>>   meson.build                | 2 +-\n>>   src/libcamera/base/log.cpp | 6 +++---\n>>   2 files changed, 4 insertions(+), 4 deletions(-)\n>>\n>> diff --git a/meson.build b/meson.build\n>> index fd508fd7f6b5..74153e1e6ce9 100644\n>> --- a/meson.build\n>> +++ b/meson.build\n>> @@ -6,7 +6,7 @@ project('libcamera', 'c', 'cpp',\n>>       default_options : [\n>>           'werror=true',\n>>           'warning_level=2',\n>> -        'cpp_std=c++17',\n>> +        'cpp_std=c++20',\n>>       ],\n>>       license : 'LGPL 2.1+')\n>>   \n>> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\n>> index 81b550e21402..e65d83739315 100644\n>> --- a/src/libcamera/base/log.cpp\n>> +++ b/src/libcamera/base/log.cpp\n>> @@ -325,7 +325,7 @@ private:\n>>          std::vector<std::unique_ptr<LogCategory>> categories_ LIBCAMERA_TSA_GUARDED_BY(mutex_);\n>>          std::list<std::pair<std::string, LogSeverity>> levels_;\n>>   \n>> -       std::shared_ptr<LogOutput> output_;\n>> +       std::atomic<std::shared_ptr<LogOutput>> output_;\n>>   };\n>>   \n>>   bool Logger::destroyed_ = false;\n>> @@ -465,7 +465,7 @@ Logger *Logger::instance()\n>>    */\n>>   void Logger::write(const LogMessage &msg)\n>>   {\n>> -       std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n>> +       std::shared_ptr<LogOutput> output = output_.load();\n>>          if (!output)\n>>                  return;\n>>   \n>> @@ -477,7 +477,7 @@ void Logger::write(const LogMessage &msg)\n>>    */\n>>   void Logger::backtrace()\n>>   {\n>> -       std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n>> +       std::shared_ptr<LogOutput> output = output_.load();\n>>          if (!output)\n>>                  return;\n>>   \n>> -- \n>> 2.51.0\n>>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id AF296C3241\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 13 Nov 2025 12:24:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8937D60A80;\n\tThu, 13 Nov 2025 13:24:23 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 34EED60805\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Nov 2025 13:24:22 +0100 (CET)","from [192.168.33.32] (185.221.140.239.nat.pool.zt.hu\n\t[185.221.140.239])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CDB125B2;\n\tThu, 13 Nov 2025 13:22:21 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"bNmL3VWg\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763036542;\n\tbh=OrouLtPCYE6SviGfa+GYcvHlp5uI/JPA4TqinhbVy3o=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=bNmL3VWgDSYEV3bZyJso4G+IYMKN0kcOkMAquDCtAVwiwhDZbkfQ1FrEzW11ednZp\n\taZgmn+GAxGGkwDg0LfBNB6t09wp2x9oi3NSFlfnszvUO3p5v4c1P7Ytu3uG/voxiMn\n\tBtLQbmVjMoLSUZ5L3aV1MTdNU2zmerJZ+78ieGeQ=","Message-ID":"<a6edb8dc-e0ac-469b-9993-0ffaaa6d3fc6@ideasonboard.com>","Date":"Thu, 13 Nov 2025 13:24:18 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [RFC PATCH v1 1/1] treewide: Update to the C++20 standard","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tNaushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20251113110958.1117065-1-naush@raspberrypi.com>\n\t<20251113110958.1117065-2-naush@raspberrypi.com>\n\t<176303540741.567526.12694728534244247378@ping.linuxembedded.co.uk>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<176303540741.567526.12694728534244247378@ping.linuxembedded.co.uk>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":36792,"web_url":"https://patchwork.libcamera.org/comment/36792/","msgid":"<20251113124940.GB30434@pendragon.ideasonboard.com>","date":"2025-11-13T12:49:40","subject":"Re: [RFC PATCH v1 1/1] treewide: Update to the C++20 standard","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Thu, Nov 13, 2025 at 01:24:18PM +0100, Barnabás Pőcze wrote:\n> 2025. 11. 13. 13:03 keltezéssel, Kieran Bingham írta:\n> > Quoting Naushir Patuck (2025-11-13 11:05:31)\n> >> Switch to using the C++20 standard when compiling libcamera. This causes\n> >> a build error due to the deprecation of the following specialisation [1]\n> >>\n> >> std::shared_ptr<T> atomic_load(const std::shared_ptr<T>* p)\n> >>\n> >> ../src/libcamera/base/log.cpp: In member function 'void libcamera::Logger::write(const libcamera::LogMessage&)':\n> >> ../src/libcamera/base/log.cpp:468:61: error: 'std::shared_ptr<_Tp> std::atomic_load(const shared_ptr<_Tp>*) [with _Tp = libcamera::LogOutput]' is deprecated: use 'std::atomic<std::shared_ptr<T>>' instead [-Werror=deprecated-declarations]\n> >>    468 |         std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n> >>        |                                             ~~~~~~~~~~~~~~~~^~~~~~~~~~\n> >>\n> >> This error is fixed by switching to the std::atomic<std::shared_ptr<T>>\n> >> specialisation instead. Unfortunately, this is not backward compatible\n> >> with C++17, so the fix must be included in this commit.\n> > \n> > Thank you for this,\n> > \n> > I think I'm in favour of updating here when we can.\n> > \n> > We'll have to do a bit of a check to see if this impacts any projects\n> > using libcamera but I think it's workable.\n> > \n> > First part though will be CI:\n> > \n> >   https://gitlab.freedesktop.org/camera/libcamera/-/pipelines/1546400\n> > \n> > Quite a few breakages to tackle and that may be the hard part.\n> \n> I have been compiling libcamera as C++20 forever. Apart from the above\n> change, one needs to:\n> \n>   (1) disable -Wvolatile because of g_once_init() in glib\n>   (2) disable -Wredundant-move in gcc 12 as well\n> \n> ---\n> \n> As far as I remember `std::atomic<std::shared_ptr<>>` is not supported\n> in some versions, so I ended up using\n> \n>    #pragma GCC diagnostic ignored \"-Wdeprecated-declarations\"\n> \n> ---\n> \n> Also, libpisp did not compile without warnings in C++20 the last time I checked.\n> \n> ---\n> \n> There is also this peculiar issue: https://gitlab.freedesktop.org/camera/libcamera/-/issues/267\n> \n> ---\n> \n> C++20 also triggers this error: https://gitlab.freedesktop.org/camera/libcamera/-/jobs/87812672#L364\n> \n> /usr/include/c++/12/bits/char_traits.h:431:56: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 9223372036854775810 or more bytes at offsets [2, 9223372036854775807] and 1 may overlap up to 9223372036854775813 bytes at offset -3 [-Werror=restrict]\n>    431 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));\n> \n> \n> After some time I have given up on trying to fix this.\n> \n> ---\n> \n> Actually, to address (1), it should be sufficient to use `std::call_once()`, e.g.\n> \n> diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp\n> index d4492d994b..3de6fc42a7 100644\n> --- a/src/gstreamer/gstlibcameraallocator.cpp\n> +++ b/src/gstreamer/gstlibcameraallocator.cpp\n> @@ -8,6 +8,7 @@\n>   \n>   #include \"gstlibcameraallocator.h\"\n>   \n> +#include <mutex>\n>   #include <utility>\n>   \n>   #include <libcamera/camera.h>\n> @@ -77,11 +78,11 @@ FrameWrap::~FrameWrap()\n>   GQuark FrameWrap::getQuark()\n>   {\n>          static gsize frame_quark = 0;\n> +       static std::once_flag frame_quark_once;\n>   \n> -       if (g_once_init_enter(&frame_quark)) {\n> -               GQuark quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n> -               g_once_init_leave(&frame_quark, quark);\n> -       }\n> +       std::call_once(frame_quark_once, [&] {\n> +               frame_quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n> +       });\n>   \n>          return frame_quark;\n>   }\n\nHow about\n\nGQuark FrameWrap::getQuark()\n{\n\tstatic gsize frame_quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n\treturn frame_quark;\n}\n\nAccording to\nhttps://en.cppreference.com/w/cpp/language/storage_duration.html#Static_block_variables,\n\n  If multiple threads attempt to initialize the same static local\n  variable concurrently, the initialization occurs exactly once (similar\n  behavior can be obtained for arbitrary functions with std::call_once).\n\n> > With a large matrix of compilers and differing support that might be the\n> > tricky part. We'll have to identify if this will restict us to any\n> > specific compiler version minimum.\n> > \n> >> [1]: https://en.cppreference.com/w/cpp/memory/shared_ptr/atomic.html\n> >> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> >> ---\n> >>   meson.build                | 2 +-\n> >>   src/libcamera/base/log.cpp | 6 +++---\n> >>   2 files changed, 4 insertions(+), 4 deletions(-)\n> >>\n> >> diff --git a/meson.build b/meson.build\n> >> index fd508fd7f6b5..74153e1e6ce9 100644\n> >> --- a/meson.build\n> >> +++ b/meson.build\n> >> @@ -6,7 +6,7 @@ project('libcamera', 'c', 'cpp',\n> >>       default_options : [\n> >>           'werror=true',\n> >>           'warning_level=2',\n> >> -        'cpp_std=c++17',\n> >> +        'cpp_std=c++20',\n> >>       ],\n> >>       license : 'LGPL 2.1+')\n> >>   \n> >> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\n> >> index 81b550e21402..e65d83739315 100644\n> >> --- a/src/libcamera/base/log.cpp\n> >> +++ b/src/libcamera/base/log.cpp\n> >> @@ -325,7 +325,7 @@ private:\n> >>          std::vector<std::unique_ptr<LogCategory>> categories_ LIBCAMERA_TSA_GUARDED_BY(mutex_);\n> >>          std::list<std::pair<std::string, LogSeverity>> levels_;\n> >>   \n> >> -       std::shared_ptr<LogOutput> output_;\n> >> +       std::atomic<std::shared_ptr<LogOutput>> output_;\n> >>   };\n> >>   \n> >>   bool Logger::destroyed_ = false;\n> >> @@ -465,7 +465,7 @@ Logger *Logger::instance()\n> >>    */\n> >>   void Logger::write(const LogMessage &msg)\n> >>   {\n> >> -       std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n> >> +       std::shared_ptr<LogOutput> output = output_.load();\n> >>          if (!output)\n> >>                  return;\n> >>   \n> >> @@ -477,7 +477,7 @@ void Logger::write(const LogMessage &msg)\n> >>    */\n> >>   void Logger::backtrace()\n> >>   {\n> >> -       std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n> >> +       std::shared_ptr<LogOutput> output = output_.load();\n> >>          if (!output)\n> >>                  return;\n> >>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 3E677C3263\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 13 Nov 2025 12:49:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5FFAF609D8;\n\tThu, 13 Nov 2025 13:49:54 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DB33060805\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Nov 2025 13:49:52 +0100 (CET)","from pendragon.ideasonboard.com (unknown [213.216.211.176])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 84DE15B2;\n\tThu, 13 Nov 2025 13:47:52 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Z2G5WcW6\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763038072;\n\tbh=mNFlFxwUW87C8S5N9nHT/WyHSlHS54V9L2HFZPi4UJM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Z2G5WcW6krrKIQdFJGdN8FzzavGyfdv0Z16hzjKYKMHjiOjJoA4qViSs5en0IRwca\n\tnNAURmKPK/SRXEoo7+2AcClxFgVOhMKlYdaVUhkstSnagLwTwIFVCLrDgqh5QQNlQy\n\tOSMZO8i99dygTgqcRSuXjQ/Tw3+d7i1GwVpoLkKY=","Date":"Thu, 13 Nov 2025 14:49:40 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tNaushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v1 1/1] treewide: Update to the C++20 standard","Message-ID":"<20251113124940.GB30434@pendragon.ideasonboard.com>","References":"<20251113110958.1117065-1-naush@raspberrypi.com>\n\t<20251113110958.1117065-2-naush@raspberrypi.com>\n\t<176303540741.567526.12694728534244247378@ping.linuxembedded.co.uk>\n\t<a6edb8dc-e0ac-469b-9993-0ffaaa6d3fc6@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<a6edb8dc-e0ac-469b-9993-0ffaaa6d3fc6@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":36793,"web_url":"https://patchwork.libcamera.org/comment/36793/","msgid":"<00cbe340-364d-4d85-a4c4-d1a0fa1175cc@ideasonboard.com>","date":"2025-11-13T12:54:54","subject":"Re: [RFC PATCH v1 1/1] treewide: Update to the C++20 standard","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"2025. 11. 13. 13:49 keltezéssel, Laurent Pinchart írta:\n> On Thu, Nov 13, 2025 at 01:24:18PM +0100, Barnabás Pőcze wrote:\n>> 2025. 11. 13. 13:03 keltezéssel, Kieran Bingham írta:\n>>> Quoting Naushir Patuck (2025-11-13 11:05:31)\n>>>> Switch to using the C++20 standard when compiling libcamera. This causes\n>>>> a build error due to the deprecation of the following specialisation [1]\n>>>>\n>>>> std::shared_ptr<T> atomic_load(const std::shared_ptr<T>* p)\n>>>>\n>>>> ../src/libcamera/base/log.cpp: In member function 'void libcamera::Logger::write(const libcamera::LogMessage&)':\n>>>> ../src/libcamera/base/log.cpp:468:61: error: 'std::shared_ptr<_Tp> std::atomic_load(const shared_ptr<_Tp>*) [with _Tp = libcamera::LogOutput]' is deprecated: use 'std::atomic<std::shared_ptr<T>>' instead [-Werror=deprecated-declarations]\n>>>>     468 |         std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n>>>>         |                                             ~~~~~~~~~~~~~~~~^~~~~~~~~~\n>>>>\n>>>> This error is fixed by switching to the std::atomic<std::shared_ptr<T>>\n>>>> specialisation instead. Unfortunately, this is not backward compatible\n>>>> with C++17, so the fix must be included in this commit.\n>>>\n>>> Thank you for this,\n>>>\n>>> I think I'm in favour of updating here when we can.\n>>>\n>>> We'll have to do a bit of a check to see if this impacts any projects\n>>> using libcamera but I think it's workable.\n>>>\n>>> First part though will be CI:\n>>>\n>>>    https://gitlab.freedesktop.org/camera/libcamera/-/pipelines/1546400\n>>>\n>>> Quite a few breakages to tackle and that may be the hard part.\n>>\n>> I have been compiling libcamera as C++20 forever. Apart from the above\n>> change, one needs to:\n>>\n>>    (1) disable -Wvolatile because of g_once_init() in glib\n>>    (2) disable -Wredundant-move in gcc 12 as well\n>>\n>> ---\n>>\n>> As far as I remember `std::atomic<std::shared_ptr<>>` is not supported\n>> in some versions, so I ended up using\n>>\n>>     #pragma GCC diagnostic ignored \"-Wdeprecated-declarations\"\n>>\n>> ---\n>>\n>> Also, libpisp did not compile without warnings in C++20 the last time I checked.\n>>\n>> ---\n>>\n>> There is also this peculiar issue: https://gitlab.freedesktop.org/camera/libcamera/-/issues/267\n>>\n>> ---\n>>\n>> C++20 also triggers this error: https://gitlab.freedesktop.org/camera/libcamera/-/jobs/87812672#L364\n>>\n>> /usr/include/c++/12/bits/char_traits.h:431:56: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 9223372036854775810 or more bytes at offsets [2, 9223372036854775807] and 1 may overlap up to 9223372036854775813 bytes at offset -3 [-Werror=restrict]\n>>     431 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));\n>>\n>>\n>> After some time I have given up on trying to fix this.\n>>\n>> ---\n>>\n>> Actually, to address (1), it should be sufficient to use `std::call_once()`, e.g.\n>>\n>> diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp\n>> index d4492d994b..3de6fc42a7 100644\n>> --- a/src/gstreamer/gstlibcameraallocator.cpp\n>> +++ b/src/gstreamer/gstlibcameraallocator.cpp\n>> @@ -8,6 +8,7 @@\n>>    \n>>    #include \"gstlibcameraallocator.h\"\n>>    \n>> +#include <mutex>\n>>    #include <utility>\n>>    \n>>    #include <libcamera/camera.h>\n>> @@ -77,11 +78,11 @@ FrameWrap::~FrameWrap()\n>>    GQuark FrameWrap::getQuark()\n>>    {\n>>           static gsize frame_quark = 0;\n>> +       static std::once_flag frame_quark_once;\n>>    \n>> -       if (g_once_init_enter(&frame_quark)) {\n>> -               GQuark quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n>> -               g_once_init_leave(&frame_quark, quark);\n>> -       }\n>> +       std::call_once(frame_quark_once, [&] {\n>> +               frame_quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n>> +       });\n>>    \n>>           return frame_quark;\n>>    }\n> \n> How about\n> \n> GQuark FrameWrap::getQuark()\n> {\n> \tstatic gsize frame_quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n> \treturn frame_quark;\n> }\n\nAhh, yes, that should work, and is much better.\n\n\n> \n> According to\n> https://en.cppreference.com/w/cpp/language/storage_duration.html#Static_block_variables,\n> \n>    If multiple threads attempt to initialize the same static local\n>    variable concurrently, the initialization occurs exactly once (similar\n>    behavior can be obtained for arbitrary functions with std::call_once).\n> \n>>> With a large matrix of compilers and differing support that might be the\n>>> tricky part. We'll have to identify if this will restict us to any\n>>> specific compiler version minimum.\n>>>\n>>>> [1]: https://en.cppreference.com/w/cpp/memory/shared_ptr/atomic.html\n>>>> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n>>>> ---\n>>>>    meson.build                | 2 +-\n>>>>    src/libcamera/base/log.cpp | 6 +++---\n>>>>    2 files changed, 4 insertions(+), 4 deletions(-)\n>>>>\n>>>> diff --git a/meson.build b/meson.build\n>>>> index fd508fd7f6b5..74153e1e6ce9 100644\n>>>> --- a/meson.build\n>>>> +++ b/meson.build\n>>>> @@ -6,7 +6,7 @@ project('libcamera', 'c', 'cpp',\n>>>>        default_options : [\n>>>>            'werror=true',\n>>>>            'warning_level=2',\n>>>> -        'cpp_std=c++17',\n>>>> +        'cpp_std=c++20',\n>>>>        ],\n>>>>        license : 'LGPL 2.1+')\n>>>>    \n>>>> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\n>>>> index 81b550e21402..e65d83739315 100644\n>>>> --- a/src/libcamera/base/log.cpp\n>>>> +++ b/src/libcamera/base/log.cpp\n>>>> @@ -325,7 +325,7 @@ private:\n>>>>           std::vector<std::unique_ptr<LogCategory>> categories_ LIBCAMERA_TSA_GUARDED_BY(mutex_);\n>>>>           std::list<std::pair<std::string, LogSeverity>> levels_;\n>>>>    \n>>>> -       std::shared_ptr<LogOutput> output_;\n>>>> +       std::atomic<std::shared_ptr<LogOutput>> output_;\n>>>>    };\n>>>>    \n>>>>    bool Logger::destroyed_ = false;\n>>>> @@ -465,7 +465,7 @@ Logger *Logger::instance()\n>>>>     */\n>>>>    void Logger::write(const LogMessage &msg)\n>>>>    {\n>>>> -       std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n>>>> +       std::shared_ptr<LogOutput> output = output_.load();\n>>>>           if (!output)\n>>>>                   return;\n>>>>    \n>>>> @@ -477,7 +477,7 @@ void Logger::write(const LogMessage &msg)\n>>>>     */\n>>>>    void Logger::backtrace()\n>>>>    {\n>>>> -       std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n>>>> +       std::shared_ptr<LogOutput> output = output_.load();\n>>>>           if (!output)\n>>>>                   return;\n>>>>    \n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 2782FC3241\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 13 Nov 2025 12:55:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 67E11609D8;\n\tThu, 13 Nov 2025 13:54:59 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8F9CD60805\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Nov 2025 13:54:57 +0100 (CET)","from [192.168.33.32] (185.221.140.239.nat.pool.zt.hu\n\t[185.221.140.239])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2BD705B2;\n\tThu, 13 Nov 2025 13:52:57 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"WISpoTaO\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763038377;\n\tbh=WyufiuDEH5nYxTMFEuWVXGNp4/lk7QviPHis2JQVRsE=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=WISpoTaOdsJq9QHVK3vv07jbnhyZ6Gf+q2KaLdzP4hOiLkzfDoJlDAkrmfhQdl6el\n\thYdgJKrK0+AHrhSMDqPYavrpF7D5BaeGfxAJVINwWiT7xxaBQ/mEVm4/+IqAn30cgR\n\t/66dMqBy1A8x/2LiCjDKBgbpxLbA+sgPCtB46JX8=","Message-ID":"<00cbe340-364d-4d85-a4c4-d1a0fa1175cc@ideasonboard.com>","Date":"Thu, 13 Nov 2025 13:54:54 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [RFC PATCH v1 1/1] treewide: Update to the C++20 standard","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tNaushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20251113110958.1117065-1-naush@raspberrypi.com>\n\t<20251113110958.1117065-2-naush@raspberrypi.com>\n\t<176303540741.567526.12694728534244247378@ping.linuxembedded.co.uk>\n\t<a6edb8dc-e0ac-469b-9993-0ffaaa6d3fc6@ideasonboard.com>\n\t<20251113124940.GB30434@pendragon.ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20251113124940.GB30434@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":36796,"web_url":"https://patchwork.libcamera.org/comment/36796/","msgid":"<CAEmqJPqX8YVG+h-58X=bo6=wE8d=10xAMpf7SX25uxJ-RhHCnQ@mail.gmail.com>","date":"2025-11-13T13:40:10","subject":"Re: [RFC PATCH v1 1/1] treewide: Update to the C++20 standard","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi all,\n\nI should have mentioned that I was expecting many more compile errors\nto crop up with the CI compiler matrix :)  I'll attempt at bashing\nthrough them to see what's involved with making this change.  But good\nto see there's an appetite to get C++20 support merged!\n\nRegards,\nNaush\n\n\n\nOn Thu, 13 Nov 2025 at 12:54, Barnabás Pőcze\n<barnabas.pocze@ideasonboard.com> wrote:\n>\n> 2025. 11. 13. 13:49 keltezéssel, Laurent Pinchart írta:\n> > On Thu, Nov 13, 2025 at 01:24:18PM +0100, Barnabás Pőcze wrote:\n> >> 2025. 11. 13. 13:03 keltezéssel, Kieran Bingham írta:\n> >>> Quoting Naushir Patuck (2025-11-13 11:05:31)\n> >>>> Switch to using the C++20 standard when compiling libcamera. This causes\n> >>>> a build error due to the deprecation of the following specialisation [1]\n> >>>>\n> >>>> std::shared_ptr<T> atomic_load(const std::shared_ptr<T>* p)\n> >>>>\n> >>>> ../src/libcamera/base/log.cpp: In member function 'void libcamera::Logger::write(const libcamera::LogMessage&)':\n> >>>> ../src/libcamera/base/log.cpp:468:61: error: 'std::shared_ptr<_Tp> std::atomic_load(const shared_ptr<_Tp>*) [with _Tp = libcamera::LogOutput]' is deprecated: use 'std::atomic<std::shared_ptr<T>>' instead [-Werror=deprecated-declarations]\n> >>>>     468 |         std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n> >>>>         |                                             ~~~~~~~~~~~~~~~~^~~~~~~~~~\n> >>>>\n> >>>> This error is fixed by switching to the std::atomic<std::shared_ptr<T>>\n> >>>> specialisation instead. Unfortunately, this is not backward compatible\n> >>>> with C++17, so the fix must be included in this commit.\n> >>>\n> >>> Thank you for this,\n> >>>\n> >>> I think I'm in favour of updating here when we can.\n> >>>\n> >>> We'll have to do a bit of a check to see if this impacts any projects\n> >>> using libcamera but I think it's workable.\n> >>>\n> >>> First part though will be CI:\n> >>>\n> >>>    https://gitlab.freedesktop.org/camera/libcamera/-/pipelines/1546400\n> >>>\n> >>> Quite a few breakages to tackle and that may be the hard part.\n> >>\n> >> I have been compiling libcamera as C++20 forever. Apart from the above\n> >> change, one needs to:\n> >>\n> >>    (1) disable -Wvolatile because of g_once_init() in glib\n> >>    (2) disable -Wredundant-move in gcc 12 as well\n> >>\n> >> ---\n> >>\n> >> As far as I remember `std::atomic<std::shared_ptr<>>` is not supported\n> >> in some versions, so I ended up using\n> >>\n> >>     #pragma GCC diagnostic ignored \"-Wdeprecated-declarations\"\n> >>\n> >> ---\n> >>\n> >> Also, libpisp did not compile without warnings in C++20 the last time I checked.\n> >>\n> >> ---\n> >>\n> >> There is also this peculiar issue: https://gitlab.freedesktop.org/camera/libcamera/-/issues/267\n> >>\n> >> ---\n> >>\n> >> C++20 also triggers this error: https://gitlab.freedesktop.org/camera/libcamera/-/jobs/87812672#L364\n> >>\n> >> /usr/include/c++/12/bits/char_traits.h:431:56: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 9223372036854775810 or more bytes at offsets [2, 9223372036854775807] and 1 may overlap up to 9223372036854775813 bytes at offset -3 [-Werror=restrict]\n> >>     431 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));\n> >>\n> >>\n> >> After some time I have given up on trying to fix this.\n> >>\n> >> ---\n> >>\n> >> Actually, to address (1), it should be sufficient to use `std::call_once()`, e.g.\n> >>\n> >> diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp\n> >> index d4492d994b..3de6fc42a7 100644\n> >> --- a/src/gstreamer/gstlibcameraallocator.cpp\n> >> +++ b/src/gstreamer/gstlibcameraallocator.cpp\n> >> @@ -8,6 +8,7 @@\n> >>\n> >>    #include \"gstlibcameraallocator.h\"\n> >>\n> >> +#include <mutex>\n> >>    #include <utility>\n> >>\n> >>    #include <libcamera/camera.h>\n> >> @@ -77,11 +78,11 @@ FrameWrap::~FrameWrap()\n> >>    GQuark FrameWrap::getQuark()\n> >>    {\n> >>           static gsize frame_quark = 0;\n> >> +       static std::once_flag frame_quark_once;\n> >>\n> >> -       if (g_once_init_enter(&frame_quark)) {\n> >> -               GQuark quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n> >> -               g_once_init_leave(&frame_quark, quark);\n> >> -       }\n> >> +       std::call_once(frame_quark_once, [&] {\n> >> +               frame_quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n> >> +       });\n> >>\n> >>           return frame_quark;\n> >>    }\n> >\n> > How about\n> >\n> > GQuark FrameWrap::getQuark()\n> > {\n> >       static gsize frame_quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n> >       return frame_quark;\n> > }\n>\n> Ahh, yes, that should work, and is much better.\n>\n>\n> >\n> > According to\n> > https://en.cppreference.com/w/cpp/language/storage_duration.html#Static_block_variables,\n> >\n> >    If multiple threads attempt to initialize the same static local\n> >    variable concurrently, the initialization occurs exactly once (similar\n> >    behavior can be obtained for arbitrary functions with std::call_once).\n> >\n> >>> With a large matrix of compilers and differing support that might be the\n> >>> tricky part. We'll have to identify if this will restict us to any\n> >>> specific compiler version minimum.\n> >>>\n> >>>> [1]: https://en.cppreference.com/w/cpp/memory/shared_ptr/atomic.html\n> >>>> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> >>>> ---\n> >>>>    meson.build                | 2 +-\n> >>>>    src/libcamera/base/log.cpp | 6 +++---\n> >>>>    2 files changed, 4 insertions(+), 4 deletions(-)\n> >>>>\n> >>>> diff --git a/meson.build b/meson.build\n> >>>> index fd508fd7f6b5..74153e1e6ce9 100644\n> >>>> --- a/meson.build\n> >>>> +++ b/meson.build\n> >>>> @@ -6,7 +6,7 @@ project('libcamera', 'c', 'cpp',\n> >>>>        default_options : [\n> >>>>            'werror=true',\n> >>>>            'warning_level=2',\n> >>>> -        'cpp_std=c++17',\n> >>>> +        'cpp_std=c++20',\n> >>>>        ],\n> >>>>        license : 'LGPL 2.1+')\n> >>>>\n> >>>> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\n> >>>> index 81b550e21402..e65d83739315 100644\n> >>>> --- a/src/libcamera/base/log.cpp\n> >>>> +++ b/src/libcamera/base/log.cpp\n> >>>> @@ -325,7 +325,7 @@ private:\n> >>>>           std::vector<std::unique_ptr<LogCategory>> categories_ LIBCAMERA_TSA_GUARDED_BY(mutex_);\n> >>>>           std::list<std::pair<std::string, LogSeverity>> levels_;\n> >>>>\n> >>>> -       std::shared_ptr<LogOutput> output_;\n> >>>> +       std::atomic<std::shared_ptr<LogOutput>> output_;\n> >>>>    };\n> >>>>\n> >>>>    bool Logger::destroyed_ = false;\n> >>>> @@ -465,7 +465,7 @@ Logger *Logger::instance()\n> >>>>     */\n> >>>>    void Logger::write(const LogMessage &msg)\n> >>>>    {\n> >>>> -       std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n> >>>> +       std::shared_ptr<LogOutput> output = output_.load();\n> >>>>           if (!output)\n> >>>>                   return;\n> >>>>\n> >>>> @@ -477,7 +477,7 @@ void Logger::write(const LogMessage &msg)\n> >>>>     */\n> >>>>    void Logger::backtrace()\n> >>>>    {\n> >>>> -       std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n> >>>> +       std::shared_ptr<LogOutput> output = output_.load();\n> >>>>           if (!output)\n> >>>>                   return;\n> >>>>\n> >\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 74358C3263\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 13 Nov 2025 13:40:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1B12160A80;\n\tThu, 13 Nov 2025 14:40:49 +0100 (CET)","from mail-vk1-xa2d.google.com (mail-vk1-xa2d.google.com\n\t[IPv6:2607:f8b0:4864:20::a2d])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1FDEF60805\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Nov 2025 14:40:47 +0100 (CET)","by mail-vk1-xa2d.google.com with SMTP id\n\t71dfb90a1353d-557412a9de0so26969e0c.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Nov 2025 05:40:47 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"mEUCBIX+\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1763041246; x=1763646046;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=UpqBbEdvQpUthPwjTReAjFmT+N5tVOv/U6DphYRlrZw=;\n\tb=mEUCBIX+AaBf/UzBIXsUYh9hR0CXmO7/h6LnrmVqFmKoU15vPATZDLftiUAabkvizU\n\t5PcGZFfKKce/Wd5E6phgZf+HkT3bxluEM0/kxbJf+47Et4dERc5eG100An+ddJhLP56H\n\t8F5y8qhPwWwq4K3rgFXZhPDsqBPaYl4sZKAgU6+4hcFreFn4de+hSuk/oajRCMp30D1w\n\t3+RDF6XKgLnyp4uy14pahbumfOgapPeHKj0g183BKSZJu4lOwI5ctZhayywWi4qGzgsv\n\tX4rPQPeBuWoiojaX0pDFb43R2A/YvKA58fHlFtLK/ryL4Hg1TjxqjpeAHMpoE5QLtNDG\n\t3Hjg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1763041246; x=1763646046;\n\th=content-transfer-encoding:cc:to:subject:message-id:date:from\n\t:in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from\n\t:to:cc:subject:date:message-id:reply-to;\n\tbh=UpqBbEdvQpUthPwjTReAjFmT+N5tVOv/U6DphYRlrZw=;\n\tb=iTEQYr58t/PDRGH7VxbTQzpB6uHrT1dy50+haZIIWE4TA+E5RgAnHYIQWHzV0mhuFr\n\tIJEKoevnXjIfosE+3bXgbkWmxyVqLelc6LqHF5BtNrmKIu8Hy7Ci4x6ZK+dqK3h81/BK\n\ttGdLk20QGFj3wbjs+dx1a0rnsmc0hA8zxl4C6o3wOS1EyMfFsqI2Lf3CS4HjhdUspmkR\n\tklsJ/6PGQB/su1DVlgsiY4ecd2vA/GeC2011OQMvyO9q1wX2/AZ/zTogsWMlu/YuqepJ\n\t6mXznNKweoYeEmh3JSKdxaHJP51lLp3UpoDav20V4NFfIMXee1excqk7Jks32QAO5bBj\n\tlvIg==","X-Forwarded-Encrypted":"i=1;\n\tAJvYcCWeS9G/OtQju660QBEOOIX2/ncScE4bOIPHJI0iQw+iRYxJaRMHee/widSRpjQzjke9qdva4hNzUn8Ly9RzzeE=@lists.libcamera.org","X-Gm-Message-State":"AOJu0YweWFVNakSZI2JFoY8V/xf+hpYNxHEUv55D2ji0Iu/a8wvg9viH\n\tIEokF5bHN85bGsS7TuOnxvFhzzhdMHaZfspGUxVeD+uBV2cLXh2stiBCi7nkUyB3JX1XpyiH89m\n\tcTOlRhsy9rkiDgx7gQ5zaiBju2mrI7IH0rFW5csR6WQ==","X-Gm-Gg":"ASbGncsozXU8ArkJk0RG25DRrxygA2xNQxsnFiL6Btg10sr5/bYOY5Vfrv/pWGXNgp4\n\tjFTeZCJlo3ENeYzvnMp8JAYtOMw2ez6v6dBo/ag1vP43SgWyzHlW+jc2Jgm5eL7R6QF6pzT7XoU\n\tkRP4uZSJUJeFePif+J9/vt93bM4FpubX2i1SaDJgqC7V2dr8e97ttwoFVOdyUzIU3fH24RigV9z\n\tNmdzefq+q0u/c/EdcqZWwC+G9LrAtAVKbZI7AC+b5RfjOUDCVIlY/2xCcywfkE95pts0bbVzCBK\n\tfwn4wDuvvSmMucSd","X-Google-Smtp-Source":"AGHT+IFEV8FGGGX74qZjZ4JIFWJP2GwaxWK10qXPl3y2VzbdSKbLqs22f8MhWsVTQ91FHCbnbtWlfBmnqaIN3ekeUoM=","X-Received":"by 2002:a05:6102:510d:b0:5db:e851:9385 with SMTP id\n\tada2fe7eead31-5de07cdfacdmr1085504137.2.1763041245839;\n\tThu, 13 Nov 2025 05:40:45 -0800 (PST)","MIME-Version":"1.0","References":"<20251113110958.1117065-1-naush@raspberrypi.com>\n\t<20251113110958.1117065-2-naush@raspberrypi.com>\n\t<176303540741.567526.12694728534244247378@ping.linuxembedded.co.uk>\n\t<a6edb8dc-e0ac-469b-9993-0ffaaa6d3fc6@ideasonboard.com>\n\t<20251113124940.GB30434@pendragon.ideasonboard.com>\n\t<00cbe340-364d-4d85-a4c4-d1a0fa1175cc@ideasonboard.com>","In-Reply-To":"<00cbe340-364d-4d85-a4c4-d1a0fa1175cc@ideasonboard.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Thu, 13 Nov 2025 13:40:10 +0000","X-Gm-Features":"AWmQ_bnKC0Y-SjOQVzxqOX3QhTTZ3jyMj9WhSZFpYJ5dpCIyaaMRToDovm65j7g","Message-ID":"<CAEmqJPqX8YVG+h-58X=bo6=wE8d=10xAMpf7SX25uxJ-RhHCnQ@mail.gmail.com>","Subject":"Re: [RFC PATCH v1 1/1] treewide: Update to the C++20 standard","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>, \n\tKieran Bingham <kieran.bingham@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":36797,"web_url":"https://patchwork.libcamera.org/comment/36797/","msgid":"<57a97964-27fc-43af-bb41-71ae556daa65@ideasonboard.com>","date":"2025-11-13T13:41:52","subject":"Re: [RFC PATCH v1 1/1] treewide: Update to the C++20 standard","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"2025. 11. 13. 13:54 keltezéssel, Barnabás Pőcze írta:\n> 2025. 11. 13. 13:49 keltezéssel, Laurent Pinchart írta:\n>> On Thu, Nov 13, 2025 at 01:24:18PM +0100, Barnabás Pőcze wrote:\n>>> 2025. 11. 13. 13:03 keltezéssel, Kieran Bingham írta:\n>>>> Quoting Naushir Patuck (2025-11-13 11:05:31)\n>>>>> Switch to using the C++20 standard when compiling libcamera. This causes\n>>>>> a build error due to the deprecation of the following specialisation [1]\n>>>>>\n>>>>> std::shared_ptr<T> atomic_load(const std::shared_ptr<T>* p)\n>>>>>\n>>>>> ../src/libcamera/base/log.cpp: In member function 'void libcamera::Logger::write(const libcamera::LogMessage&)':\n>>>>> ../src/libcamera/base/log.cpp:468:61: error: 'std::shared_ptr<_Tp> std::atomic_load(const shared_ptr<_Tp>*) [with _Tp = libcamera::LogOutput]' is deprecated: use 'std::atomic<std::shared_ptr<T>>' instead [-Werror=deprecated-declarations]\n>>>>>     468 |         std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n>>>>>         |                                             ~~~~~~~~~~~~~~~~^~~~~~~~~~\n>>>>>\n>>>>> This error is fixed by switching to the std::atomic<std::shared_ptr<T>>\n>>>>> specialisation instead. Unfortunately, this is not backward compatible\n>>>>> with C++17, so the fix must be included in this commit.\n>>>>\n>>>> Thank you for this,\n>>>>\n>>>> I think I'm in favour of updating here when we can.\n>>>>\n>>>> We'll have to do a bit of a check to see if this impacts any projects\n>>>> using libcamera but I think it's workable.\n>>>>\n>>>> First part though will be CI:\n>>>>\n>>>>    https://gitlab.freedesktop.org/camera/libcamera/-/pipelines/1546400\n>>>>\n>>>> Quite a few breakages to tackle and that may be the hard part.\n>>>\n>>> I have been compiling libcamera as C++20 forever. Apart from the above\n>>> change, one needs to:\n>>>\n>>>    (1) disable -Wvolatile because of g_once_init() in glib\n>>>    (2) disable -Wredundant-move in gcc 12 as well\n>>>\n>>> ---\n>>>\n>>> As far as I remember `std::atomic<std::shared_ptr<>>` is not supported\n>>> in some versions, so I ended up using\n>>>\n>>>     #pragma GCC diagnostic ignored \"-Wdeprecated-declarations\"\n>>>\n>>> ---\n>>>\n>>> Also, libpisp did not compile without warnings in C++20 the last time I checked.\n>>>\n>>> ---\n>>>\n>>> There is also this peculiar issue: https://gitlab.freedesktop.org/camera/libcamera/-/issues/267\n>>>\n>>> ---\n>>>\n>>> C++20 also triggers this error: https://gitlab.freedesktop.org/camera/libcamera/-/jobs/87812672#L364\n>>>\n>>> /usr/include/c++/12/bits/char_traits.h:431:56: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 9223372036854775810 or more bytes at offsets [2, 9223372036854775807] and 1 may overlap up to 9223372036854775813 bytes at offset -3 [-Werror=restrict]\n>>>     431 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));\n>>>\n>>>\n>>> After some time I have given up on trying to fix this.\n>>>\n>>> ---\n>>>\n>>> Actually, to address (1), it should be sufficient to use `std::call_once()`, e.g.\n>>>\n>>> diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp\n>>> index d4492d994b..3de6fc42a7 100644\n>>> --- a/src/gstreamer/gstlibcameraallocator.cpp\n>>> +++ b/src/gstreamer/gstlibcameraallocator.cpp\n>>> @@ -8,6 +8,7 @@\n>>>    #include \"gstlibcameraallocator.h\"\n>>> +#include <mutex>\n>>>    #include <utility>\n>>>    #include <libcamera/camera.h>\n>>> @@ -77,11 +78,11 @@ FrameWrap::~FrameWrap()\n>>>    GQuark FrameWrap::getQuark()\n>>>    {\n>>>           static gsize frame_quark = 0;\n>>> +       static std::once_flag frame_quark_once;\n>>> -       if (g_once_init_enter(&frame_quark)) {\n>>> -               GQuark quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n>>> -               g_once_init_leave(&frame_quark, quark);\n>>> -       }\n>>> +       std::call_once(frame_quark_once, [&] {\n>>> +               frame_quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n>>> +       });\n>>>           return frame_quark;\n>>>    }\n>>\n>> How about\n>>\n>> GQuark FrameWrap::getQuark()\n>> {\n>>     static gsize frame_quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n>>     return frame_quark;\n>> }\n> \n> Ahh, yes, that should work, and is much better.\n\nUnfortunately I misremembered and this is not enough. `-Wno-volatile` is needed\nbecause `G_DEFINE_TYPE_*()` macros contain `g_once_init()`.\n\nRegardless, it might still be worth it to simplify the code.\n\n> \n> \n>>\n>> According to\n>> https://en.cppreference.com/w/cpp/language/storage_duration.html#Static_block_variables,\n>>\n>>    If multiple threads attempt to initialize the same static local\n>>    variable concurrently, the initialization occurs exactly once (similar\n>>    behavior can be obtained for arbitrary functions with std::call_once).\n>>\n>>>> With a large matrix of compilers and differing support that might be the\n>>>> tricky part. We'll have to identify if this will restict us to any\n>>>> specific compiler version minimum.\n>>>>\n>>>>> [1]: https://en.cppreference.com/w/cpp/memory/shared_ptr/atomic.html\n>>>>> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n>>>>> ---\n>>>>>    meson.build                | 2 +-\n>>>>>    src/libcamera/base/log.cpp | 6 +++---\n>>>>>    2 files changed, 4 insertions(+), 4 deletions(-)\n>>>>>\n>>>>> diff --git a/meson.build b/meson.build\n>>>>> index fd508fd7f6b5..74153e1e6ce9 100644\n>>>>> --- a/meson.build\n>>>>> +++ b/meson.build\n>>>>> @@ -6,7 +6,7 @@ project('libcamera', 'c', 'cpp',\n>>>>>        default_options : [\n>>>>>            'werror=true',\n>>>>>            'warning_level=2',\n>>>>> -        'cpp_std=c++17',\n>>>>> +        'cpp_std=c++20',\n>>>>>        ],\n>>>>>        license : 'LGPL 2.1+')\n>>>>> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\n>>>>> index 81b550e21402..e65d83739315 100644\n>>>>> --- a/src/libcamera/base/log.cpp\n>>>>> +++ b/src/libcamera/base/log.cpp\n>>>>> @@ -325,7 +325,7 @@ private:\n>>>>>           std::vector<std::unique_ptr<LogCategory>> categories_ LIBCAMERA_TSA_GUARDED_BY(mutex_);\n>>>>>           std::list<std::pair<std::string, LogSeverity>> levels_;\n>>>>> -       std::shared_ptr<LogOutput> output_;\n>>>>> +       std::atomic<std::shared_ptr<LogOutput>> output_;\n>>>>>    };\n>>>>>    bool Logger::destroyed_ = false;\n>>>>> @@ -465,7 +465,7 @@ Logger *Logger::instance()\n>>>>>     */\n>>>>>    void Logger::write(const LogMessage &msg)\n>>>>>    {\n>>>>> -       std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n>>>>> +       std::shared_ptr<LogOutput> output = output_.load();\n>>>>>           if (!output)\n>>>>>                   return;\n>>>>> @@ -477,7 +477,7 @@ void Logger::write(const LogMessage &msg)\n>>>>>     */\n>>>>>    void Logger::backtrace()\n>>>>>    {\n>>>>> -       std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n>>>>> +       std::shared_ptr<LogOutput> output = output_.load();\n>>>>>           if (!output)\n>>>>>                   return;\n>>\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A13D3C3263\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 13 Nov 2025 13:41:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5393860A80;\n\tThu, 13 Nov 2025 14:41:58 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E70CA60805\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Nov 2025 14:41:56 +0100 (CET)","from [192.168.33.32] (185.221.140.239.nat.pool.zt.hu\n\t[185.221.140.239])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7EABF446;\n\tThu, 13 Nov 2025 14:39:56 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"HeDawKyi\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763041196;\n\tbh=GBsQe2culJ5wqbxYFDeFB5+kzxbZOkNrA7jmeDl6A2w=;\n\th=Date:Subject:From:To:Cc:References:In-Reply-To:From;\n\tb=HeDawKyiHBH5yD5N0CeEB+Y8APPTlOQKXBzbuaahulQe9MDj/Gm1vcBUIclTRH/Zp\n\tvUyuaqh+VRznfWjK0ZUfWU7c7Nn4CQEodXGNEqRCB0alfBD19xAZnXg/AL2XPLdEwu\n\tGyrW3Ylon5GOpV85nL6002X51/rfjMsHUTk6xqPA=","Message-ID":"<57a97964-27fc-43af-bb41-71ae556daa65@ideasonboard.com>","Date":"Thu, 13 Nov 2025 14:41:52 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [RFC PATCH v1 1/1] treewide: Update to the C++20 standard","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tNaushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20251113110958.1117065-1-naush@raspberrypi.com>\n\t<20251113110958.1117065-2-naush@raspberrypi.com>\n\t<176303540741.567526.12694728534244247378@ping.linuxembedded.co.uk>\n\t<a6edb8dc-e0ac-469b-9993-0ffaaa6d3fc6@ideasonboard.com>\n\t<20251113124940.GB30434@pendragon.ideasonboard.com>\n\t<00cbe340-364d-4d85-a4c4-d1a0fa1175cc@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<00cbe340-364d-4d85-a4c4-d1a0fa1175cc@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":36807,"web_url":"https://patchwork.libcamera.org/comment/36807/","msgid":"<20251113153241.GG30434@pendragon.ideasonboard.com>","date":"2025-11-13T15:32:41","subject":"Re: [RFC PATCH v1 1/1] treewide: Update to the C++20 standard","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Thu, Nov 13, 2025 at 02:41:52PM +0100, Barnabás Pőcze wrote:\n> 2025. 11. 13. 13:54 keltezéssel, Barnabás Pőcze írta:\n> > 2025. 11. 13. 13:49 keltezéssel, Laurent Pinchart írta:\n> >> On Thu, Nov 13, 2025 at 01:24:18PM +0100, Barnabás Pőcze wrote:\n> >>> 2025. 11. 13. 13:03 keltezéssel, Kieran Bingham írta:\n> >>>> Quoting Naushir Patuck (2025-11-13 11:05:31)\n> >>>>> Switch to using the C++20 standard when compiling libcamera. This causes\n> >>>>> a build error due to the deprecation of the following specialisation [1]\n> >>>>>\n> >>>>> std::shared_ptr<T> atomic_load(const std::shared_ptr<T>* p)\n> >>>>>\n> >>>>> ../src/libcamera/base/log.cpp: In member function 'void libcamera::Logger::write(const libcamera::LogMessage&)':\n> >>>>> ../src/libcamera/base/log.cpp:468:61: error: 'std::shared_ptr<_Tp> std::atomic_load(const shared_ptr<_Tp>*) [with _Tp = libcamera::LogOutput]' is deprecated: use 'std::atomic<std::shared_ptr<T>>' instead [-Werror=deprecated-declarations]\n> >>>>>     468 |         std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n> >>>>>         |                                             ~~~~~~~~~~~~~~~~^~~~~~~~~~\n> >>>>>\n> >>>>> This error is fixed by switching to the std::atomic<std::shared_ptr<T>>\n> >>>>> specialisation instead. Unfortunately, this is not backward compatible\n> >>>>> with C++17, so the fix must be included in this commit.\n> >>>>\n> >>>> Thank you for this,\n> >>>>\n> >>>> I think I'm in favour of updating here when we can.\n> >>>>\n> >>>> We'll have to do a bit of a check to see if this impacts any projects\n> >>>> using libcamera but I think it's workable.\n> >>>>\n> >>>> First part though will be CI:\n> >>>>\n> >>>>    https://gitlab.freedesktop.org/camera/libcamera/-/pipelines/1546400\n> >>>>\n> >>>> Quite a few breakages to tackle and that may be the hard part.\n> >>>\n> >>> I have been compiling libcamera as C++20 forever. Apart from the above\n> >>> change, one needs to:\n> >>>\n> >>>    (1) disable -Wvolatile because of g_once_init() in glib\n> >>>    (2) disable -Wredundant-move in gcc 12 as well\n> >>>\n> >>> ---\n> >>>\n> >>> As far as I remember `std::atomic<std::shared_ptr<>>` is not supported\n> >>> in some versions, so I ended up using\n> >>>\n> >>>     #pragma GCC diagnostic ignored \"-Wdeprecated-declarations\"\n> >>>\n> >>> ---\n> >>>\n> >>> Also, libpisp did not compile without warnings in C++20 the last time I checked.\n> >>>\n> >>> ---\n> >>>\n> >>> There is also this peculiar issue: https://gitlab.freedesktop.org/camera/libcamera/-/issues/267\n> >>>\n> >>> ---\n> >>>\n> >>> C++20 also triggers this error: https://gitlab.freedesktop.org/camera/libcamera/-/jobs/87812672#L364\n> >>>\n> >>> /usr/include/c++/12/bits/char_traits.h:431:56: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 9223372036854775810 or more bytes at offsets [2, 9223372036854775807] and 1 may overlap up to 9223372036854775813 bytes at offset -3 [-Werror=restrict]\n> >>>     431 |         return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));\n> >>>\n> >>>\n> >>> After some time I have given up on trying to fix this.\n> >>>\n> >>> ---\n> >>>\n> >>> Actually, to address (1), it should be sufficient to use `std::call_once()`, e.g.\n> >>>\n> >>> diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp\n> >>> index d4492d994b..3de6fc42a7 100644\n> >>> --- a/src/gstreamer/gstlibcameraallocator.cpp\n> >>> +++ b/src/gstreamer/gstlibcameraallocator.cpp\n> >>> @@ -8,6 +8,7 @@\n> >>>    #include \"gstlibcameraallocator.h\"\n> >>> +#include <mutex>\n> >>>    #include <utility>\n> >>>    #include <libcamera/camera.h>\n> >>> @@ -77,11 +78,11 @@ FrameWrap::~FrameWrap()\n> >>>    GQuark FrameWrap::getQuark()\n> >>>    {\n> >>>           static gsize frame_quark = 0;\n> >>> +       static std::once_flag frame_quark_once;\n> >>> -       if (g_once_init_enter(&frame_quark)) {\n> >>> -               GQuark quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n> >>> -               g_once_init_leave(&frame_quark, quark);\n> >>> -       }\n> >>> +       std::call_once(frame_quark_once, [&] {\n> >>> +               frame_quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n> >>> +       });\n> >>>           return frame_quark;\n> >>>    }\n> >>\n> >> How about\n> >>\n> >> GQuark FrameWrap::getQuark()\n> >> {\n> >>     static gsize frame_quark = g_quark_from_string(\"GstLibcameraFrameWrap\");\n> >>     return frame_quark;\n> >> }\n> > \n> > Ahh, yes, that should work, and is much better.\n> \n> Unfortunately I misremembered and this is not enough. `-Wno-volatile` is needed\n> because `G_DEFINE_TYPE_*()` macros contain `g_once_init()`.\n\nPlease make this conditional to the glib version.\n\n> Regardless, it might still be worth it to simplify the code.\n> \n> >> According to\n> >> https://en.cppreference.com/w/cpp/language/storage_duration.html#Static_block_variables,\n> >>\n> >>    If multiple threads attempt to initialize the same static local\n> >>    variable concurrently, the initialization occurs exactly once (similar\n> >>    behavior can be obtained for arbitrary functions with std::call_once).\n> >>\n> >>>> With a large matrix of compilers and differing support that might be the\n> >>>> tricky part. We'll have to identify if this will restict us to any\n> >>>> specific compiler version minimum.\n> >>>>\n> >>>>> [1]: https://en.cppreference.com/w/cpp/memory/shared_ptr/atomic.html\n> >>>>> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> >>>>> ---\n> >>>>>    meson.build                | 2 +-\n> >>>>>    src/libcamera/base/log.cpp | 6 +++---\n> >>>>>    2 files changed, 4 insertions(+), 4 deletions(-)\n> >>>>>\n> >>>>> diff --git a/meson.build b/meson.build\n> >>>>> index fd508fd7f6b5..74153e1e6ce9 100644\n> >>>>> --- a/meson.build\n> >>>>> +++ b/meson.build\n> >>>>> @@ -6,7 +6,7 @@ project('libcamera', 'c', 'cpp',\n> >>>>>        default_options : [\n> >>>>>            'werror=true',\n> >>>>>            'warning_level=2',\n> >>>>> -        'cpp_std=c++17',\n> >>>>> +        'cpp_std=c++20',\n> >>>>>        ],\n> >>>>>        license : 'LGPL 2.1+')\n> >>>>> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\n> >>>>> index 81b550e21402..e65d83739315 100644\n> >>>>> --- a/src/libcamera/base/log.cpp\n> >>>>> +++ b/src/libcamera/base/log.cpp\n> >>>>> @@ -325,7 +325,7 @@ private:\n> >>>>>           std::vector<std::unique_ptr<LogCategory>> categories_ LIBCAMERA_TSA_GUARDED_BY(mutex_);\n> >>>>>           std::list<std::pair<std::string, LogSeverity>> levels_;\n> >>>>> -       std::shared_ptr<LogOutput> output_;\n> >>>>> +       std::atomic<std::shared_ptr<LogOutput>> output_;\n> >>>>>    };\n> >>>>>    bool Logger::destroyed_ = false;\n> >>>>> @@ -465,7 +465,7 @@ Logger *Logger::instance()\n> >>>>>     */\n> >>>>>    void Logger::write(const LogMessage &msg)\n> >>>>>    {\n> >>>>> -       std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n> >>>>> +       std::shared_ptr<LogOutput> output = output_.load();\n> >>>>>           if (!output)\n> >>>>>                   return;\n> >>>>> @@ -477,7 +477,7 @@ void Logger::write(const LogMessage &msg)\n> >>>>>     */\n> >>>>>    void Logger::backtrace()\n> >>>>>    {\n> >>>>> -       std::shared_ptr<LogOutput> output = std::atomic_load(&output_);\n> >>>>> +       std::shared_ptr<LogOutput> output = output_.load();\n> >>>>>           if (!output)\n> >>>>>                   return;","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 00B01C3241\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 13 Nov 2025 15:32:56 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4B80A609D8;\n\tThu, 13 Nov 2025 16:32:56 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EEF0760805\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Nov 2025 16:32:53 +0100 (CET)","from pendragon.ideasonboard.com (unknown [213.216.211.176])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 645815B2;\n\tThu, 13 Nov 2025 16:30:53 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"GD6glYGS\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1763047853;\n\tbh=bxSCVMpr3IgXhOQ1GhrxnlSh7rRlInP/2KsDRfFHMLI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=GD6glYGS/PDRK7yR2Pnr/wqtfrQU6r3JhsrAmr5T/U+AXLeTaGhaxKBwIaLIJcInK\n\to9qqf4hemYXPf0uFwtwMn+5KUMLsITe3gnZieymalPqWcfUMrlROwrSI5rV+9nxMEn\n\tX0th4WYdCJUVPvy1VDnaBD4Mg/o1kp6Xsa0RL7C4=","Date":"Thu, 13 Nov 2025 17:32:41 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tNaushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Subject":"Re: [RFC PATCH v1 1/1] treewide: Update to the C++20 standard","Message-ID":"<20251113153241.GG30434@pendragon.ideasonboard.com>","References":"<20251113110958.1117065-1-naush@raspberrypi.com>\n\t<20251113110958.1117065-2-naush@raspberrypi.com>\n\t<176303540741.567526.12694728534244247378@ping.linuxembedded.co.uk>\n\t<a6edb8dc-e0ac-469b-9993-0ffaaa6d3fc6@ideasonboard.com>\n\t<20251113124940.GB30434@pendragon.ideasonboard.com>\n\t<00cbe340-364d-4d85-a4c4-d1a0fa1175cc@ideasonboard.com>\n\t<57a97964-27fc-43af-bb41-71ae556daa65@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<57a97964-27fc-43af-bb41-71ae556daa65@ideasonboard.com>","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]