[{"id":206,"web_url":"https://patchwork.libcamera.org/comment/206/","msgid":"<20190106112949.GC11987@bigcity.dyn.berto.se>","date":"2019-01-06T11:29:49","subject":"Re: [libcamera-devel] [PATCH 02/11] libcamera: log: Add an ASSERT\n\tmacro","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your patch.\n\nOn 2019-01-06 04:33:19 +0200, Laurent Pinchart wrote:\n> The ASSERT() macro is similar to the assert() macro defined by the C\n> standard, but uses the libcamera logging infrastructure.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/include/log.h |  9 +++++++++\n>  src/libcamera/log.cpp       | 16 ++++++++++++++++\n>  2 files changed, 25 insertions(+)\n> \n> diff --git a/src/libcamera/include/log.h b/src/libcamera/include/log.h\n> index 03842be02d0e..774916f04274 100644\n> --- a/src/libcamera/include/log.h\n> +++ b/src/libcamera/include/log.h\n> @@ -36,6 +36,15 @@ private:\n>  \n>  #define LOG(severity) LogMessage(__FILE__, __LINE__, Log##severity).stream()\n>  \n> +#ifdef NDEBUG\n\nTo match the documentation bellow this should be '#ifndef NDEBUG' right?\n\nWith this fixed-up,\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> +#define ASSERT(condition) static_cast<void>({\t\t\t\t\\\n> +\tif (condition)\t\t\t\t\t\t\t\\\n> +\t\tLOG(Fatal) << \"assertion \\\"\" #condition \"\\\" failed\";\t\\\n> +})\n> +#else\n> +#define ASSERT(condition) static_cast<void>(false && (condition))\n> +#endif\n> +\n>  } /* namespace libcamera */\n>  \n>  #endif /* __LIBCAMERA_LOG_H__ */\n> diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\n> index a5823c64eaa6..4165cbd654fc 100644\n> --- a/src/libcamera/log.cpp\n> +++ b/src/libcamera/log.cpp\n> @@ -48,6 +48,22 @@ namespace libcamera {\n>   * terminates immediately after printing the message.\n>   */\n>  \n> +/**\n> + * \\def ASSERT(condition)\n> + * \\brief Abort program execution if assertion is failed\n> + *\n> + * If \\a condition is false, ASSERT() logs an error message with the Fatal log\n> + * level and aborts program execution.\n> + *\n> + * If the macro NDEBUG is defined before including log.h, ASSERT() generates no\n> + * code.\n> + *\n> + * Using conditions that have side effects with ASSERT() is not recommended, as\n> + * these effects would depend on whether NDEBUG is defined or not. Similarly,\n> + * ASSERT() should not be used to check for errors that can occur under normal\n> + * conditions as those checks would then be removed when compiling with NDEBUG.\n> + */\n> +\n>  static const char *log_severity_name(LogSeverity severity)\n>  {\n>  \tstatic const char * const names[] = {\n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lf1-x144.google.com (mail-lf1-x144.google.com\n\t[IPv6:2a00:1450:4864:20::144])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E38D360B2C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  6 Jan 2019 12:29:51 +0100 (CET)","by mail-lf1-x144.google.com with SMTP id y11so28221240lfj.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 06 Jan 2019 03:29:51 -0800 (PST)","from localhost (89-233-230-99.cust.bredband2.com. [89.233.230.99])\n\tby smtp.gmail.com with ESMTPSA id\n\tc203sm12152405lfe.95.2019.01.06.03.29.50\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tSun, 06 Jan 2019 03:29:50 -0800 (PST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=Frwep9wstGEOswpZLS9n8JxmbvD43tXAyoz4T/5nmQw=;\n\tb=sYJgZ1xNoFX6lhacWL5UsJLmoWDvUvUNfuP6II36/4euXrRHW4ht2tytXIe6UEDiqT\n\tUEUNBpxuIAYy1WVDuC8knaSS9lAHfL6Z7HmULLro9hOA26e3Anv9DWZFqfF9tps1Jp82\n\tcfRHVU7qnMFpo9gDO4CdpiXHCj3A0pBhia7deY7ch5eArOJgLDA3bEX4weRpQlNs5FAn\n\tK2NJwMDGbz4gcCEq8p/kMCfoSLHW6UdWzPt9EeTFIVknMn+Pa3mkFGIK233VEfthr+3P\n\tqzRjF/FBhGdBsgdqP05nubKj4oBT4uJQllpZ0ch/eX9lzWMLPlpcvUdTvRq3UlCJwuHz\n\tQ0Ag==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=Frwep9wstGEOswpZLS9n8JxmbvD43tXAyoz4T/5nmQw=;\n\tb=bcwPUGT1H6Sfa2SGXwwSUyWwMGuYn+HjUizfl0xIna3SA+Z33CQpHeR+DuXUrPXTso\n\thrkTM9pCPugu5wTZPryOH9204r2EKfcAKOPYfG3scGk0e8nzcTvZoraSTNtujW1vITap\n\tnfdsVrxAg/A56VUy6UilGCRNWGcqpreiX1spVQCijMJI63AGhu1L2TQnC6z3T51AoTm9\n\t0u6aeafVIs6gwEbPlQnpVFcm3iYXBPcHdKselXHRhbTqx3rsFAAgQrIXvcgfHkd8tNiw\n\tC8FIuL4rKav43yVLHB/N7dtiHy53bSaY6jED+zLGsp6SYT9CLai7mfI5vSgKno+lyrVp\n\tIvqQ==","X-Gm-Message-State":"AA+aEWYrtINrVYic6+LGZl8MP1GquQ76qB8SJWyJJy38yDSFGtLeXHW2\n\tXDj81BzzBJsw5VwzZbys2oFISw==","X-Google-Smtp-Source":"AFSGD/U1TuNK3xoMoSdQXd0v1EEtZuX9gWVrcjMXAj9teAJbTXnQe+Yi1n3Z9owTGDHUMfonkw/uAQ==","X-Received":"by 2002:a19:2755:: with SMTP id\n\tn82mr26898599lfn.94.1546774191214; \n\tSun, 06 Jan 2019 03:29:51 -0800 (PST)","Date":"Sun, 6 Jan 2019 12:29:49 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190106112949.GC11987@bigcity.dyn.berto.se>","References":"<20190106023328.10989-1-laurent.pinchart@ideasonboard.com>\n\t<20190106023328.10989-2-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190106023328.10989-2-laurent.pinchart@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 02/11] libcamera: log: Add an ASSERT\n\tmacro","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Sun, 06 Jan 2019 11:29:52 -0000"}},{"id":209,"web_url":"https://patchwork.libcamera.org/comment/209/","msgid":"<1956783.QGc4UckM2D@avalon>","date":"2019-01-06T13:38:36","subject":"Re: [libcamera-devel] [PATCH 02/11] libcamera: log: Add an ASSERT\n\tmacro","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nOn Sunday, 6 January 2019 13:29:49 EET Niklas Söderlund wrote:\n> On 2019-01-06 04:33:19 +0200, Laurent Pinchart wrote:\n> > The ASSERT() macro is similar to the assert() macro defined by the C\n> > standard, but uses the libcamera logging infrastructure.\n> > \n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> > \n> >  src/libcamera/include/log.h |  9 +++++++++\n> >  src/libcamera/log.cpp       | 16 ++++++++++++++++\n> >  2 files changed, 25 insertions(+)\n> > \n> > diff --git a/src/libcamera/include/log.h b/src/libcamera/include/log.h\n> > index 03842be02d0e..774916f04274 100644\n> > --- a/src/libcamera/include/log.h\n> > +++ b/src/libcamera/include/log.h\n> > \n> > @@ -36,6 +36,15 @@ private:\n> >  #define LOG(severity) LogMessage(__FILE__, __LINE__,\n> >  Log##severity).stream()> \n> > +#ifdef NDEBUG\n> \n> To match the documentation bellow this should be '#ifndef NDEBUG' right?\n\nAbsolutely, my bad. I've fixed this.\n\n> With this fixed-up,\n> \n> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> \n> > +#define ASSERT(condition) static_cast<void>({\t\t\t\t\\\n> > +\tif (condition)\t\t\t\t\t\t\t\\\n> > +\t\tLOG(Fatal) << \"assertion \\\"\" #condition \"\\\" failed\";\t\\\n> > +})\n> > +#else\n> > +#define ASSERT(condition) static_cast<void>(false && (condition))\n> > +#endif\n> > +\n> > \n> >  } /* namespace libcamera */\n> >  \n> >  #endif /* __LIBCAMERA_LOG_H__ */\n> > \n> > diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\n> > index a5823c64eaa6..4165cbd654fc 100644\n> > --- a/src/libcamera/log.cpp\n> > +++ b/src/libcamera/log.cpp\n> > @@ -48,6 +48,22 @@ namespace libcamera {\n> > \n> >   * terminates immediately after printing the message.\n> >   */\n> > \n> > +/**\n> > + * \\def ASSERT(condition)\n> > + * \\brief Abort program execution if assertion is failed\n> > + *\n> > + * If \\a condition is false, ASSERT() logs an error message with the\n> > Fatal log + * level and aborts program execution.\n> > + *\n> > + * If the macro NDEBUG is defined before including log.h, ASSERT()\n> > generates no + * code.\n> > + *\n> > + * Using conditions that have side effects with ASSERT() is not\n> > recommended, as + * these effects would depend on whether NDEBUG is\n> > defined or not. Similarly, + * ASSERT() should not be used to check for\n> > errors that can occur under normal + * conditions as those checks would\n> > then be removed when compiling with NDEBUG. + */\n> > +\n> > \n> >  static const char *log_severity_name(LogSeverity severity)\n> >  {\n> >  \n> >  \tstatic const char * const names[] = {","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["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 669F660B2C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  6 Jan 2019 14:37:31 +0100 (CET)","from avalon.localnet (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E020998C;\n\tSun,  6 Jan 2019 14:37:30 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1546781851;\n\tbh=UmxVO8eoY8kYkffW13845tU64hYpHK3Ogz8VfN+LSnA=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=kA2yGqEaypaFm4k8qTbUfMHKwiaaWCe2ZS1AqfLmkyVCKOaqjMaR6sWxVIGnuzDMN\n\t1QLB4Jof//gaUX9RBhCIKvr0Rlyx8Z/Zpr6ooRbicwQvM3DgaAalnYoW9/3O5VZ2I0\n\tm5lMqYK7uefMSBU23JunJYj3N5KePOfKaFW368j0=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","Cc":"libcamera-devel@lists.libcamera.org","Date":"Sun, 06 Jan 2019 15:38:36 +0200","Message-ID":"<1956783.QGc4UckM2D@avalon>","Organization":"Ideas on Board Oy","In-Reply-To":"<20190106112949.GC11987@bigcity.dyn.berto.se>","References":"<20190106023328.10989-1-laurent.pinchart@ideasonboard.com>\n\t<20190106023328.10989-2-laurent.pinchart@ideasonboard.com>\n\t<20190106112949.GC11987@bigcity.dyn.berto.se>","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","Content-Type":"text/plain; charset=\"iso-8859-1\"","Subject":"Re: [libcamera-devel] [PATCH 02/11] libcamera: log: Add an ASSERT\n\tmacro","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Sun, 06 Jan 2019 13:37:31 -0000"}},{"id":218,"web_url":"https://patchwork.libcamera.org/comment/218/","msgid":"<20190107102513.jggqz4m2tdcbzxu2@uno.localdomain>","date":"2019-01-07T10:25:13","subject":"Re: [libcamera-devel] [PATCH 02/11] libcamera: log: Add an ASSERT\n\tmacro","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Sun, Jan 06, 2019 at 04:33:19AM +0200, Laurent Pinchart wrote:\n> The ASSERT() macro is similar to the assert() macro defined by the C\n> standard, but uses the libcamera logging infrastructure.\n>\n\n../src/libcamera/include/log.h:42:45: error: expected primary-expression before ‘{’ token\n #define ASSERT(condition) static_cast<void>({    \\\n                                             ^\n../src/libcamera/media_device.cpp:267:2: note: in expansion of macro ‘ASSERT’\n  ASSERT(valid_);\n  ^~~~~~\n\nAm I the only one?\n\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  src/libcamera/include/log.h |  9 +++++++++\n>  src/libcamera/log.cpp       | 16 ++++++++++++++++\n>  2 files changed, 25 insertions(+)\n>\n> diff --git a/src/libcamera/include/log.h b/src/libcamera/include/log.h\n> index 03842be02d0e..774916f04274 100644\n> --- a/src/libcamera/include/log.h\n> +++ b/src/libcamera/include/log.h\n> @@ -36,6 +36,15 @@ private:\n>\n>  #define LOG(severity) LogMessage(__FILE__, __LINE__, Log##severity).stream()\n>\n> +#ifdef NDEBUG\n> +#define ASSERT(condition) static_cast<void>({\t\t\t\t\\\n\nWhy do you use a cast to void? Isn't this better wrapped in a\ncanonical \"do { } while(0)\" ?\n\n> +\tif (condition)\t\t\t\t\t\t\t\\\n\nI feel we should trigger this if the condition is not satisfied, not\nthe other way around, am I wrong?\nhttp://www.cplusplus.com/reference/cassert/assert/\n\n\n> +\t\tLOG(Fatal) << \"assertion \\\"\" #condition \"\\\" failed\";\t\\\n> +})\n> +#else\n> +#define ASSERT(condition) static_cast<void>(false && (condition))\n> +#endif\n> +\n>  } /* namespace libcamera */\n>\n>  #endif /* __LIBCAMERA_LOG_H__ */\n> diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\n> index a5823c64eaa6..4165cbd654fc 100644\n> --- a/src/libcamera/log.cpp\n> +++ b/src/libcamera/log.cpp\n> @@ -48,6 +48,22 @@ namespace libcamera {\n>   * terminates immediately after printing the message.\n>   */\n>\n> +/**\n> + * \\def ASSERT(condition)\n> + * \\brief Abort program execution if assertion is failed\n\ns/is failed/fails ?\n\n> + *\n> + * If \\a condition is false, ASSERT() logs an error message with the Fatal log\n> + * level and aborts program execution.\n\nAh, ok, seems like it should then be \"if (!(condition))\" according to\ndocumentation too.\n\nThanks\n  j\n\n> + *\n> + * If the macro NDEBUG is defined before including log.h, ASSERT() generates no\n> + * code.\n> + *\n> + * Using conditions that have side effects with ASSERT() is not recommended, as\n> + * these effects would depend on whether NDEBUG is defined or not. Similarly,\n> + * ASSERT() should not be used to check for errors that can occur under normal\n> + * conditions as those checks would then be removed when compiling with NDEBUG.\n> + */\n> +\n>  static const char *log_severity_name(LogSeverity severity)\n>  {\n>  \tstatic const char * const names[] = {\n> --\n> Regards,\n>\n> Laurent Pinchart\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9DD2760B0B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  7 Jan 2019 11:25:08 +0100 (CET)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id 338F7100015;\n\tMon,  7 Jan 2019 10:25:07 +0000 (UTC)"],"Date":"Mon, 7 Jan 2019 11:25:13 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190107102513.jggqz4m2tdcbzxu2@uno.localdomain>","References":"<20190106023328.10989-1-laurent.pinchart@ideasonboard.com>\n\t<20190106023328.10989-2-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"3fyxzx676jads4u3\"","Content-Disposition":"inline","In-Reply-To":"<20190106023328.10989-2-laurent.pinchart@ideasonboard.com>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 02/11] libcamera: log: Add an ASSERT\n\tmacro","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Mon, 07 Jan 2019 10:25:08 -0000"}},{"id":220,"web_url":"https://patchwork.libcamera.org/comment/220/","msgid":"<257813208.Qtsim8Rt3b@avalon>","date":"2019-01-07T11:20:01","subject":"Re: [libcamera-devel] [PATCH 02/11] libcamera: log: Add an ASSERT\n\tmacro","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn Monday, 7 January 2019 12:25:13 EET Jacopo Mondi wrote:\n> On Sun, Jan 06, 2019 at 04:33:19AM +0200, Laurent Pinchart wrote:\n> > The ASSERT() macro is similar to the assert() macro defined by the C\n> > standard, but uses the libcamera logging infrastructure.\n> \n> ../src/libcamera/include/log.h:42:45: error: expected primary-expression\n> before ‘{’ token #define ASSERT(condition) static_cast<void>({    \\\n>                                              ^\n> ../src/libcamera/media_device.cpp:267:2: note: in expansion of macro\n> ‘ASSERT’ ASSERT(valid_);\n>   ^~~~~~\n> \n> Am I the only one?\n\nNo, after fixing the #if(n)def NDEBUG issue Niklas pointed out, I received the \nsame error. I've fixed it by adding an extra () around the {} statement.\n\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> > \n> >  src/libcamera/include/log.h |  9 +++++++++\n> >  src/libcamera/log.cpp       | 16 ++++++++++++++++\n> >  2 files changed, 25 insertions(+)\n> > \n> > diff --git a/src/libcamera/include/log.h b/src/libcamera/include/log.h\n> > index 03842be02d0e..774916f04274 100644\n> > --- a/src/libcamera/include/log.h\n> > +++ b/src/libcamera/include/log.h\n> > \n> > @@ -36,6 +36,15 @@ private:\n> >  #define LOG(severity) LogMessage(__FILE__, __LINE__,\n> >  Log##severity).stream()> \n> > +#ifdef NDEBUG\n> > +#define ASSERT(condition) static_cast<void>({\t\t\t\t\\\n> \n> Why do you use a cast to void? Isn't this better wrapped in a\n> canonical \"do { } while(0)\" ?\n\nI don't know what the pros and cons of each option are, they're both used \nwidely.\n\n> > +\tif (condition)\t\t\t\t\t\t\t\\\n> \n> I feel we should trigger this if the condition is not satisfied, not\n> the other way around, am I wrong?\n> http://www.cplusplus.com/reference/cassert/assert/\n\nI must have been really tired when I wrote this... Will fix.\n\n> > +\t\tLOG(Fatal) << \"assertion \\\"\" #condition \"\\\" failed\";\t\\\n> > +})\n> > +#else\n> > +#define ASSERT(condition) static_cast<void>(false && (condition))\n> > +#endif\n> > +\n> >  } /* namespace libcamera */\n> >  \n> >  #endif /* __LIBCAMERA_LOG_H__ */\n> > diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\n> > index a5823c64eaa6..4165cbd654fc 100644\n> > --- a/src/libcamera/log.cpp\n> > +++ b/src/libcamera/log.cpp\n> > @@ -48,6 +48,22 @@ namespace libcamera {\n> > \n> >   * terminates immediately after printing the message.\n> >   */\n> > \n> > +/**\n> > + * \\def ASSERT(condition)\n> > + * \\brief Abort program execution if assertion is failed\n> \n> s/is failed/fails ?\n\nFixed.\n\n> > + *\n> > + * If \\a condition is false, ASSERT() logs an error message with the\n> > Fatal log + * level and aborts program execution.\n> \n> Ah, ok, seems like it should then be \"if (!(condition))\" according to\n> documentation too.\n\nAt least the documentation is right :-)\n\n> > + *\n> > + * If the macro NDEBUG is defined before including log.h, ASSERT()\n> > generates no + * code.\n> > + *\n> > + * Using conditions that have side effects with ASSERT() is not\n> > recommended, as + * these effects would depend on whether NDEBUG is\n> > defined or not. Similarly, + * ASSERT() should not be used to check for\n> > errors that can occur under normal + * conditions as those checks would\n> > then be removed when compiling with NDEBUG.\n> > + */\n> > +\n> >  static const char *log_severity_name(LogSeverity severity)\n> >  {\n> >  \tstatic const char * const names[] = {","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["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 5340F600CC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  7 Jan 2019 12:18:55 +0100 (CET)","from avalon.localnet (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CA6DB53E;\n\tMon,  7 Jan 2019 12:18:54 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1546859934;\n\tbh=2rKWbrXlu9QE4ZcYL5zeC/9z2zGhCJ9zpUB2Hl4zGAU=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=C8NWfPzeMbtJ8xrOfYl3LhrzPErI9RM/qolnNqASCa1lihjcCxgfcvsw6RqkfcSB1\n\tqygAO+vmrEctTHozKSftGdTGzie+fiReq6qUq46brijaXIEe+3DdfmgGyiiO2OGNqy\n\t3enxYTEAqKtsTp7mjRQl/KDr1+/gq4J8g+BtbW5g=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Date":"Mon, 07 Jan 2019 13:20:01 +0200","Message-ID":"<257813208.Qtsim8Rt3b@avalon>","Organization":"Ideas on Board Oy","In-Reply-To":"<20190107102513.jggqz4m2tdcbzxu2@uno.localdomain>","References":"<20190106023328.10989-1-laurent.pinchart@ideasonboard.com>\n\t<20190106023328.10989-2-laurent.pinchart@ideasonboard.com>\n\t<20190107102513.jggqz4m2tdcbzxu2@uno.localdomain>","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH 02/11] libcamera: log: Add an ASSERT\n\tmacro","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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":"Mon, 07 Jan 2019 11:18:55 -0000"}}]