[{"id":4813,"web_url":"https://patchwork.libcamera.org/comment/4813/","msgid":"<20200513120128.GD5945@pendragon.ideasonboard.com>","date":"2020-05-13T12:01:28","subject":"Re: [libcamera-devel] [PATCH] libcamera: controls: Replace array\n\tdesignated initializer","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Wed, May 13, 2020 at 11:12:55AM +0200, Jacopo Mondi wrote:\n> Since version 10.0 the LLVM clang++ compiler emits warning to report\n> usage of array designated initializer, a C99 feature that was only\n> supported through an extension of the compiler and will be not valid\n> anymore in C++20.\n> \n> From https://releases.llvm.org/10.0.0/tools/clang/docs/ReleaseNotes.html\n> The new warnings -Wc99-designator and -Wreorder-init-list warn about\n> uses of C99 initializers in C++ mode for cases that are valid in C99 but\n> not in C++20.\n> \n> This generates the following build error in the controls.cpp file:\n> ../src/libcamera/controls.cpp:54:2: error: array designators are a C99 extension [-Werror,-Wc99-designator]\n>         [ControlTypeNone]               = 0,\n>         ^~~~~~~~~~~~~~~~~\n> \n> Fix this by replacing the plain C array with an std:map<>.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> \n> ---\n> I would have liked the map to be immutable, but I can't due to missing\n> overloading for operator[]:\n> error: no viable overloaded operator[] for type 'const std::map<unsigned int, size_t>'\n> \n> Tested with clang++ 10.0.0 and g++ 9.3.0.1\n> ---\n>  src/libcamera/controls.cpp | 21 +++++++++++----------\n>  1 file changed, 11 insertions(+), 10 deletions(-)\n> \n> diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\n> index 08df7f29e938..eaef45a5f62c 100644\n> --- a/src/libcamera/controls.cpp\n> +++ b/src/libcamera/controls.cpp\n> @@ -8,6 +8,7 @@\n>  #include <libcamera/controls.h>\n> \n>  #include <iomanip>\n> +#include <map>\n>  #include <sstream>\n>  #include <string>\n>  #include <string.h>\n> @@ -50,16 +51,16 @@ LOG_DEFINE_CATEGORY(Controls)\n> \n>  namespace {\n> \n> -static constexpr size_t ControlValueSize[] = {\n> -\t[ControlTypeNone]\t\t= 0,\n> -\t[ControlTypeBool]\t\t= sizeof(bool),\n> -\t[ControlTypeByte]\t\t= sizeof(uint8_t),\n> -\t[ControlTypeInteger32]\t\t= sizeof(int32_t),\n> -\t[ControlTypeInteger64]\t\t= sizeof(int64_t),\n> -\t[ControlTypeFloat]\t\t= sizeof(float),\n> -\t[ControlTypeString]\t\t= sizeof(char),\n> -\t[ControlTypeRectangle]\t\t= sizeof(Rectangle),\n> -\t[ControlTypeSize]\t\t= sizeof(Size),\n> +std::map<unsigned int, size_t> ControlValueSize = {\n> +\t{ ControlTypeNone,\t0  },\n> +\t{ ControlTypeBool,\tsizeof(bool) },\n> +\t{ ControlTypeByte,\tsizeof(uint8_t) },\n> +\t{ ControlTypeInteger32,\tsizeof(int32_t) },\n> +\t{ ControlTypeInteger64,\tsizeof(int64_t) },\n> +\t{ ControlTypeFloat,\tsizeof(float) },\n> +\t{ ControlTypeString,\tsizeof(char) },\n> +\t{ ControlTypeRectangle,\tsizeof(Rectangle) },\n> +\t{ ControlTypeSize,\tsizeof(Size) },\n>  };\n\nEfficiency will take a hit :-S And making it non-const is asking for\ntrouble. I think we need a better solution.\n\nFirst of all I'd like to know where the warning comes from, as I don't\nhit it when compiling with clang++ 10.0.0.\n\n> \n>  } /* namespace */","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3715560DE6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 May 2020 14:01:36 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C687551F;\n\tWed, 13 May 2020 14:01:34 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"XkIQg93j\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1589371295;\n\tbh=zxXGTsirgm6GaBnTVss6Sg0X3Smm8qZyTKa7UZP7zrM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=XkIQg93jhbj6unVHlHBkhcMtKEoddOGnukir0BF1TbD6nICtyQKE4w/1yJ0WYrDuf\n\tHO/cbT/pRPX01bDSTxy+TZxVGCmijyHynG/3Yd83L7fHAUYJ6YimEdNfFihf+iQyzi\n\tBHe8C2sasLsklxtSMkFamZDN0n/in7cVRJ0PQjtc=","Date":"Wed, 13 May 2020 15:01:28 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200513120128.GD5945@pendragon.ideasonboard.com>","References":"<20200513091255.7109-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200513091255.7109-1-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: controls: Replace array\n\tdesignated initializer","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>","X-List-Received-Date":"Wed, 13 May 2020 12:01:36 -0000"}},{"id":4814,"web_url":"https://patchwork.libcamera.org/comment/4814/","msgid":"<20200513124114.v26k3hzws5jhcepp@uno.localdomain>","date":"2020-05-13T12:41:14","subject":"Re: [libcamera-devel] [PATCH] libcamera: controls: Replace array\n\tdesignated initializer","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Wed, May 13, 2020 at 03:01:28PM +0300, Laurent Pinchart wrote:\n> Hi Jacopo,\n>\n> Thank you for the patch.\n>\n> On Wed, May 13, 2020 at 11:12:55AM +0200, Jacopo Mondi wrote:\n> > Since version 10.0 the LLVM clang++ compiler emits warning to report\n> > usage of array designated initializer, a C99 feature that was only\n> > supported through an extension of the compiler and will be not valid\n> > anymore in C++20.\n> >\n> > From https://releases.llvm.org/10.0.0/tools/clang/docs/ReleaseNotes.html\n> > The new warnings -Wc99-designator and -Wreorder-init-list warn about\n> > uses of C99 initializers in C++ mode for cases that are valid in C99 but\n> > not in C++20.\n> >\n> > This generates the following build error in the controls.cpp file:\n> > ../src/libcamera/controls.cpp:54:2: error: array designators are a C99 extension [-Werror,-Wc99-designator]\n> >         [ControlTypeNone]               = 0,\n> >         ^~~~~~~~~~~~~~~~~\n> >\n> > Fix this by replacing the plain C array with an std:map<>.\n> >\n> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> >\n> > ---\n> > I would have liked the map to be immutable, but I can't due to missing\n> > overloading for operator[]:\n> > error: no viable overloaded operator[] for type 'const std::map<unsigned int, size_t>'\n> >\n> > Tested with clang++ 10.0.0 and g++ 9.3.0.1\n> > ---\n> >  src/libcamera/controls.cpp | 21 +++++++++++----------\n> >  1 file changed, 11 insertions(+), 10 deletions(-)\n> >\n> > diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\n> > index 08df7f29e938..eaef45a5f62c 100644\n> > --- a/src/libcamera/controls.cpp\n> > +++ b/src/libcamera/controls.cpp\n> > @@ -8,6 +8,7 @@\n> >  #include <libcamera/controls.h>\n> >\n> >  #include <iomanip>\n> > +#include <map>\n> >  #include <sstream>\n> >  #include <string>\n> >  #include <string.h>\n> > @@ -50,16 +51,16 @@ LOG_DEFINE_CATEGORY(Controls)\n> >\n> >  namespace {\n> >\n> > -static constexpr size_t ControlValueSize[] = {\n> > -\t[ControlTypeNone]\t\t= 0,\n> > -\t[ControlTypeBool]\t\t= sizeof(bool),\n> > -\t[ControlTypeByte]\t\t= sizeof(uint8_t),\n> > -\t[ControlTypeInteger32]\t\t= sizeof(int32_t),\n> > -\t[ControlTypeInteger64]\t\t= sizeof(int64_t),\n> > -\t[ControlTypeFloat]\t\t= sizeof(float),\n> > -\t[ControlTypeString]\t\t= sizeof(char),\n> > -\t[ControlTypeRectangle]\t\t= sizeof(Rectangle),\n> > -\t[ControlTypeSize]\t\t= sizeof(Size),\n> > +std::map<unsigned int, size_t> ControlValueSize = {\n> > +\t{ ControlTypeNone,\t0  },\n> > +\t{ ControlTypeBool,\tsizeof(bool) },\n> > +\t{ ControlTypeByte,\tsizeof(uint8_t) },\n> > +\t{ ControlTypeInteger32,\tsizeof(int32_t) },\n> > +\t{ ControlTypeInteger64,\tsizeof(int64_t) },\n> > +\t{ ControlTypeFloat,\tsizeof(float) },\n> > +\t{ ControlTypeString,\tsizeof(char) },\n> > +\t{ ControlTypeRectangle,\tsizeof(Rectangle) },\n> > +\t{ ControlTypeSize,\tsizeof(Size) },\n> >  };\n>\n> Efficiency will take a hit :-S And making it non-const is asking for\n> trouble. I think we need a better solution.\n>\n> First of all I'd like to know where the warning comes from, as I don't\n> hit it when compiling with clang++ 10.0.0.\n\nPlease ignore this. I have gone through a compiler version update and\nthe build directory had to be nuked and re-created otherwise\n-Wno-c99-designator does not get collected.\n\nFalse alarm :)\n\n>\n> >\n> >  } /* namespace */\n>\n> --\n> Regards,\n>\n> Laurent Pinchart","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net\n\t[217.70.183.196])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1947160DE6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 13 May 2020 14:37:58 +0200 (CEST)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 71FB9E0002;\n\tWed, 13 May 2020 12:37:57 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Wed, 13 May 2020 14:41:14 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200513124114.v26k3hzws5jhcepp@uno.localdomain>","References":"<20200513091255.7109-1-jacopo@jmondi.org>\n\t<20200513120128.GD5945@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200513120128.GD5945@pendragon.ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] libcamera: controls: Replace array\n\tdesignated initializer","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>","X-List-Received-Date":"Wed, 13 May 2020 12:37:58 -0000"}}]