bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Cc: Reuben Thomas <rrt@sc3d.org>
Subject: Re: static_assert in G++
Date: Thu, 10 Jan 2019 21:08:15 +0100	[thread overview]
Message-ID: <1605725.3D5YJeabIe@omega> (raw)
In-Reply-To: <CAOnWdoh9w0U5E-ahHtuu0oeG-VisRrRtvmiEpgGOSbp6TwvJcQ@mail.gmail.com>

Hi Reuben,

>     verify: Fix syntax error with GCC 4.6 in C++ mode.
> 
> This is odd, since the GCC web page on C++11 support:
> https://gcc.gnu.org/projects/cxx-status.html#cxx11
> 
> says that static assertions have been supported for C++ since GCC 4.3:

See the discussion on the mailing list:
https://lists.gnu.org/archive/html/bug-gnulib/2011-04/msg00115.html

Continuing with the next versions of g++:

$ g++-version 4.3.6 -S foo1.cc
foo1.cc:2: error: expected constructor, destructor, or type conversion before '(' token
$ g++-version 4.4.7 -S foo1.cc
foo1.cc:2: error: expected constructor, destructor, or type conversion before '(' token
$ g++-version 4.5.4 -S foo1.cc
foo1.cc:2:15: error: expected constructor, destructor, or type conversion before '(' token
$ g++-version 4.6.4 -S foo1.cc
foo1.cc:2:15: error: expected constructor, destructor, or type conversion before '(' token
$ g++-version 4.7.3 -S foo1.cc
foo1.cc:2:15: error: expected constructor, destructor, or type conversion before '(' token
$ g++-version 4.8.5 -S foo1.cc
foo1.cc:2:15: error: expected constructor, destructor, or type conversion before '(' token
 static_assert (sizeof (long) > 1, "long too small");
               ^
$ g++-version 4.9.4 -S foo1.cc
foo1.cc:2:15: error: expected constructor, destructor, or type conversion before '(' token
 static_assert (sizeof (long) > 1, "long too small");
               ^
$ g++-version 5.5.0 -S foo1.cc
foo1.cc:2:15: error: expected constructor, destructor, or type conversion before '(' token
 static_assert (sizeof (long) > 1, "long too small");
               ^
$ g++-version 6.5.0 -S foo1.cc
$ g++-version 7.4.0 -S foo1.cc
$ g++-version 8.2.0 -S foo1.cc


I'm therefore applying this patch:


2019-01-10  Bruno Haible  <bruno@clisp.org>

	verify: Enable _GL_HAVE_STATIC_ASSERT for recent G++ versions.
	Reported by Reuben Thomas <rrt@sc3d.org>.
	* lib/verify.h (_GL_HAVE_STATIC_ASSERT): Define for g++ versions >= 6.

diff --git a/lib/verify.h b/lib/verify.h
index b2e5f64..6930645 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -26,7 +26,7 @@
    here generates easier-to-read diagnostics when verify (R) fails.
 
    Define _GL_HAVE_STATIC_ASSERT to 1 if static_assert works as per C++11.
-   This will likely be supported by future GCC versions, in C++ mode.
+   This is supported by GCC 6.1.0 and later, in C++ mode.
 
    Use this only with GCC.  If we were willing to slow 'configure'
    down we could also use it with other compilers, but since this
@@ -36,9 +36,7 @@
      && !defined __cplusplus)
 # define _GL_HAVE__STATIC_ASSERT 1
 #endif
-/* The condition (99 < __GNUC__) is temporary, until we know about the
-   first G++ release that supports static_assert.  */
-#if (99 < __GNUC__) && defined __cplusplus
+#if (6 <= __GNUC__) && defined __cplusplus
 # define _GL_HAVE_STATIC_ASSERT 1
 #endif
 



  reply	other threads:[~2019-01-10 20:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-10 12:17 static_assert in G++ Reuben Thomas
2019-01-10 20:08 ` Bruno Haible [this message]
2019-01-10 20:21   ` Reuben Thomas
2019-01-10 20:57     ` 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=1605725.3D5YJeabIe@omega \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=rrt@sc3d.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).