Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: Simon Marchi <simon.marchi@polymtl.ca>, Yao Qi <qiyaoltc@gmail.com>
Cc: <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Replace gdb_static_assert with static_assert
Date: Tue, 05 Dec 2017 21:21:00 -0000	[thread overview]
Message-ID: <7e9d77f7-8ac0-d959-c150-57b8676ccfa3@ericsson.com> (raw)
In-Reply-To: <f7560a6b9531c83007168fec62bb776a@polymtl.ca>

On 2017-12-05 11:32 AM, Simon Marchi wrote:
> On 2017-12-05 11:29, Yao Qi wrote:
>> Simon Marchi <simon.marchi@ericsson.com> writes:
>>
>>> gdb/ChangeLog:
>>>
>>>     * common/gdb_assert.h: Remove.
>>
>>         * common/gdb_assert.h (gdb_static_assert): Remove.
>>
>> because you don't remove this file.
> 
> Woops, thanks.
> 
>>> -/* A static assertion.  This will cause a compile-time error if EXPR,
>>> -   which must be a compile-time constant, is false.  */
>>> -
>>> -#define gdb_static_assert(expr) \
>>> -  extern int never_defined_just_used_for_checking[(expr) ? 1 : -1]
>>
>> Did you consider define gdb_static_assert as static_assert ((expr), "")?
>> You don't have to change anywhere else.  Additionally, one day we move
>> to c++17, we can replace gdb_static_assert with static_assert globally.
> 
> That's a good idea, I'll do that.
> 
> Thanks,
> 
> Simon

Here's what I pushed.  Thanks again for the suggestion.

Simon

From ed9376bd95c52ba00aa37b224b4407030a00d184 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@ericsson.com>
Date: Tue, 5 Dec 2017 16:15:08 -0500
Subject: [PATCH] Redefine gdb_static_assert as static_assert

Since we use C++11, we can use static_assert instead doing the trick
that makes a negative-sized array if the expression is false.
static_assert is built in the language and gives clearer error messages.

To avoid modifying the usages of gdb_static_assert, redefine
gdb_static_assert in terms of static_assert, passing an empty message.
If we want to add an assert with a message, it's always possible to use
static_assert directly.

gdb/ChangeLog:

	* common/gdb_assert.h (gdb_static_assert): Redefine using
	static_assert.
---
 gdb/ChangeLog           | 5 +++++
 gdb/common/gdb_assert.h | 3 +--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 524eef3..ef0c4bd 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2017-12-05  Simon Marchi  <simon.marchi@ericsson.com>

+	* common/gdb_assert.h (gdb_static_assert): Redefine using
+	static_assert.
+
+2017-12-05  Simon Marchi  <simon.marchi@ericsson.com>
+
 	* ada-lang.c (ada_collect_symbol_completion_matches): Remove
 	unused variables.
 	(ada_is_redundant_range_encoding): Likewise.
diff --git a/gdb/common/gdb_assert.h b/gdb/common/gdb_assert.h
index 5de9d3f..20825c8 100644
--- a/gdb/common/gdb_assert.h
+++ b/gdb/common/gdb_assert.h
@@ -22,8 +22,7 @@
 /* A static assertion.  This will cause a compile-time error if EXPR,
    which must be a compile-time constant, is false.  */

-#define gdb_static_assert(expr) \
-  extern int never_defined_just_used_for_checking[(expr) ? 1 : -1]
+#define gdb_static_assert(expr) static_assert (expr, "")

 /* PRAGMATICS: "gdb_assert.h":gdb_assert() is a lower case (rather
    than upper case) macro since that provides the closest fit to the
-- 
2.7.4


      reply	other threads:[~2017-12-05 21:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-04 21:26 Simon Marchi
2017-12-05 16:29 ` Yao Qi
2017-12-05 16:32   ` Simon Marchi
2017-12-05 21:21     ` Simon Marchi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7e9d77f7-8ac0-d959-c150-57b8676ccfa3@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    --cc=qiyaoltc@gmail.com \
    --cc=simon.marchi@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox