bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Akim Demaille <akim.demaille@gmail.com>
To: Bruno Haible <bruno@clisp.org>
Cc: bug-gnulib@gnu.org
Subject: Re: undefined behaviour findings in bitset
Date: Fri, 22 Mar 2019 17:00:43 +0100	[thread overview]
Message-ID: <EE6CA906-21A3-47A8-94DF-96D5DC20DA6A@gmail.com> (raw)
In-Reply-To: <334DD9B5-B8E4-4A48-BBAA-9677F912FFF2@lrde.epita.fr>

Hi Bruno,

> Le 19 mars 2019 à 07:07, Akim Demaille <akim@lrde.epita.fr> a écrit :
> 
> Hi Bruno,
> 
>> Le 18 mars 2019 à 22:03, Bruno Haible <bruno@clisp.org> a écrit :
>> 
>> Hi Akim,
>> 
>>> Also, the relationship with noreturn.h is not completely clear for
>>> me either.
>> 
>> There are a couple of comment in noreturn.h lines 33..41. But I agree,
>> some text in the documentation would be better.
>> 
>>> Clang 7 pretends to be GCC 4.2 (__GNUC__ __GNUC_MINOR__).
>> 
>>> For instance I see it already has the above fix for
>>> GCC 4.7, but in a different way.
>>> 
>>> /* Use ISO C++11 syntax when the compiler supports it. */
>>> # if (__cplusplus >= 201103 && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
>>> || (_MSC_VER >= 1900)
>>> # define _GL_NORETURN_FUNC [[noreturn]]
>> 
>> Right, this snippet gets clang++ and MSVC++ support right. How about this
>> patch?
> 
> Yes, I agree this is the best option so far, thanks!

Well, it does not work with G++ in C++98 mode: _Noreturn is not supported there.

This works with Bison's CI:

commit b2a7dec46c0b702b5f7618994641e7381c8ff86f
Author: Akim Demaille <akim.demaille@gmail.com>
Date:   Fri Mar 22 08:25:53 2019 +0100

  _Noreturn: beware of C's _Noreturn in C++ pre C++11

  * lib/_Noreturn.h, m4/gnulib-common.m4: Using C's _Noreturn in
  C++98 appears to be supported by Clang, but not by GCC nor ICC.

diff --git a/ChangeLog b/ChangeLog
index 62c522e65..b694c3512 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-03-22  Akim Demaille  <akim@lrde.epita.fr>
+
+	_Noreturn: beware of C's _Noreturn in C++ pre C++11.
+	* lib/_Noreturn.h, m4/gnulib-common.m4: Using C's _Noreturn in
+	C++98 appears to be supported by Clang, but not by GCC nor ICC.
+
2019-03-19  Akim Demaille  <akim@lrde.epita.fr>

	bitset: fix memory leaks
diff --git a/lib/_Noreturn.h b/lib/_Noreturn.h
index 1629cef39..7594e4b0c 100644
--- a/lib/_Noreturn.h
+++ b/lib/_Noreturn.h
@@ -3,8 +3,9 @@
     && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
         || (defined _MSC_VER && 1900 <= _MSC_VER)))
#  define _Noreturn [[noreturn]]
-# elif (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
-        || 4 < __GNUC__ + (7 <= __GNUC_MINOR__))
+# elif ((!defined __cplusplus || defined __clang__)                     \
+        && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0)  \
+            || 4 < __GNUC__ + (7 <= __GNUC_MINOR__)))
  /* _Noreturn works as-is.  */
# elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C
#  define _Noreturn __attribute__ ((__noreturn__))
diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index 8ad963e35..57b94ed53 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -21,8 +21,9 @@ AC_DEFUN([gl_COMMON_BODY], [
     && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
         || (defined _MSC_VER && 1900 <= _MSC_VER)))
#  define _Noreturn [[noreturn]]
-# elif (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) \
-        || 4 < __GNUC__ + (7 <= __GNUC_MINOR__))
+# elif ((!defined __cplusplus || defined __clang__) \
+        && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0)  \
+            || 4 < __GNUC__ + (7 <= __GNUC_MINOR__)))
  /* _Noreturn works as-is.  */
# elif 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C
#  define _Noreturn __attribute__ ((__noreturn__))



  reply	other threads:[~2019-03-22 16:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-09 19:33 undefined behaviour findings Bruno Haible
2019-03-09 19:37 ` undefined behaviour findings in bitset Bruno Haible
2019-03-16 16:38   ` Akim Demaille
2019-03-16 16:42     ` Akim Demaille
2019-03-16 19:53     ` Bruno Haible
2019-03-17  7:39       ` Akim Demaille
2019-03-17 18:36         ` Akim Demaille
2019-03-17 18:56           ` Paul Eggert
2019-03-17 19:27           ` Bruno Haible
2019-03-18  8:16             ` Akim Demaille
2019-03-18 21:03               ` Bruno Haible
2019-03-19  6:07                 ` Akim Demaille
2019-03-22 16:00                   ` Akim Demaille [this message]
2019-03-23 18:54                     ` Bruno Haible
2019-03-20  3:39               ` Bruno Haible
2019-03-20 17:04                 ` Akim Demaille
2019-03-09 21:22 ` undefined behaviour findings Bruno Haible

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

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

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

  git send-email \
    --in-reply-to=EE6CA906-21A3-47A8-94DF-96D5DC20DA6A@gmail.com \
    --to=akim.demaille@gmail.com \
    --cc=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).