c: restore definition of _Noreturn as [[noreturn]] in C++

Akim Demaille <[email protected]>
Newsgroups gmane.comp.parsers.bison.patches
Message-ID <[email protected]>
commit 22c38391682bb2cb95a7014e87785afbcb41efe1
Author: Akim Demaille <[email protected]>
Date:   Sat May 16 17:24:31 2020 +0200

    c: restore definition of _Noreturn as [[noreturn]] in C++
    
    c.m4 contains a definition of _Noreturn which is modeled after
    gnulib's lib/_Noreturn.h.  The latter was recently
    changed (b61bf2f0e8bdc1e522ae8e97d57d5625163b42ea) to not using
    [[noreturn]] at all, because the uses of _Noreturn in gnulib are
    sometimes incompatible with the rules of [[noreturn]].
    
    As a result glr.cc started to use _Noreturn in C++, which clang
    refuses (all the glr.cc tests currently fail with Clang++).
    
    * data/skeletons/c.m4 (b4_attribute_define): Restore the definition of
    _Noreturn as [[noreturn]] in modern C++.
    The generated code uses _Noreturn in places where [[noreturn]] is
    valid.

diff --git a/data/skeletons/c.m4 b/data/skeletons/c.m4
index f2d7b32f..d9cc2d8b 100644
--- a/data/skeletons/c.m4
+++ b/data/skeletons/c.m4
@@ -355,18 +355,15 @@ m4_define([b4_attribute_define],
 #endif
 
 ]m4_bmatch([$1], [\bnoreturn\b], [[/* The _Noreturn keyword of C11.  */
-]dnl This is an exact copy of lib/_Noreturn.h.
+]dnl This is close to lib/_Noreturn.h, except that we do enable
+dnl the use of [[noreturn]], because _Noreturn is used in places
+dnl where [[noreturn]] works in C++.  We need this in particular
+dnl because of glr.cc which compiles code from glr.c in C++.
+dnl And the C++ compiler chokes on _Noreturn.
 [#ifndef _Noreturn
 # if (defined __cplusplus \
       && ((201103 <= __cplusplus && !(__GNUC__ == 4 && __GNUC_MINOR__ == 7)) \
-          || (defined _MSC_VER && 1900 <= _MSC_VER)) \
-      && 0)
-    /* [[noreturn]] is not practically usable, because with it the syntax
-         extern _Noreturn void func (...);
-       would not be valid; such a declaration would only be valid with 'extern'
-       and '_Noreturn' swapped, or without the 'extern' keyword.  However, some
-       AIX system header files and several gnulib header files use precisely
-       this syntax with 'extern'.  */
+          || (defined _MSC_VER && 1900 <= _MSC_VER)))
 #  define _Noreturn [[noreturn]]
 # elif ((!defined __cplusplus || defined __clang__)                     \
         && (201112 <= (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0)  \
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.