public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH] gdbsupport: fix array-view compilation with c++11 && _GLIBCXX_DEBUG
Date: Thu, 18 Nov 2021 15:41:45 -0500	[thread overview]
Message-ID: <20211118204145.2425971-1-simon.marchi@efficios.com> (raw)

When building with -std=c++11 and -D_GLIBCXX_DEBUG=1, we get some errors
like:

      CXX    unittests/array-view-selftests.o
    In file included from /home/smarchi/src/binutils-gdb/gdb/utils.h:25,
                     from /home/smarchi/src/binutils-gdb/gdb/defs.h:630,
                     from /home/smarchi/src/binutils-gdb/gdb/unittests/array-view-selftests.c:20:
    /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/array-view.h: In instantiation of ‘constexpr gdb::array_view<T> gdb::array_view<T>::slice(gdb::array_view<T>::size_type, gdb::array_view<T>::size_type) const [with T = unsigned char; gdb::array_view<T>::size_type = long unsigned int]’:
    /home/smarchi/src/binutils-gdb/gdb/unittests/array-view-selftests.c:532:29:   required from here
    /home/smarchi/src/binutils-gdb/gdb/../gdbsupport/array-view.h:192:3: error: body of ‘constexpr’ function ‘constexpr gdb::array_view<T> gdb::array_view<T>::slice(gdb::array_view<T>::size_type, gdb::array_view<T>::size_type) const [with T = unsigned char; gdb::array_view<T>::size_type = long unsigned int]’ not a return-statement
      192 |   }
          |   ^

This is because constexpr functions in C++ can only consist of a single
return statement, so we can't have the gdb_assert in there.  Make the
gdb_assert presence conditional to the __cplusplus version, to enable it
only for c++14 and later.

Change-Id: I2ac33f7b4bd1765ddc3ac8d07445b16ac1f340f0
---
 gdbsupport/array-view.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gdbsupport/array-view.h b/gdbsupport/array-view.h
index 6f7e45a979c..edf66559e2d 100644
--- a/gdbsupport/array-view.h
+++ b/gdbsupport/array-view.h
@@ -171,7 +171,7 @@ class array_view
   }
   constexpr const_reference operator[] (size_t index) const noexcept
   {
-#if defined(_GLIBCXX_DEBUG)
+#if defined(_GLIBCXX_DEBUG) && __cplusplus >= 201402L
     gdb_assert (index < m_size);
 #endif
     return m_array[index];
@@ -185,7 +185,7 @@ class array_view
   /* Return a new array view over SIZE elements starting at START.  */
   constexpr array_view<T> slice (size_type start, size_type size) const noexcept
   {
-#if defined(_GLIBCXX_DEBUG)
+#if defined(_GLIBCXX_DEBUG) && __cplusplus >= 201402L
     gdb_assert (start + size <= m_size);
 #endif
     return {m_array + start, size};
@@ -195,7 +195,7 @@ class array_view
      inclusive.  */
   constexpr array_view<T> slice (size_type start) const noexcept
   {
-#if defined(_GLIBCXX_DEBUG)
+#if defined(_GLIBCXX_DEBUG) && __cplusplus >= 201402L
     gdb_assert (start <= m_size);
 #endif
     return {m_array + start, size () - start};
-- 
2.33.1


             reply	other threads:[~2021-11-18 20:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-18 20:41 Simon Marchi [this message]
2021-11-19 20:29 ` Tom Tromey
2021-11-20  4:26   ` Simon Marchi

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=20211118204145.2425971-1-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.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).