From: Simon Marchi Date: Thu, 18 Nov 2021 20:41:45 +0000 (-0500) Subject: gdbsupport: fix array-view compilation with c++11 && _GLIBCXX_DEBUG X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=911438f9f4;p=binutils-gdb.git gdbsupport: fix array-view compilation with c++11 && _GLIBCXX_DEBUG 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 gdb::array_view::slice(gdb::array_view::size_type, gdb::array_view::size_type) const [with T = unsigned char; gdb::array_view::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 gdb::array_view::slice(gdb::array_view::size_type, gdb::array_view::size_type) const [with T = unsigned char; gdb::array_view::size_type = long unsigned int not a return-statement 192 | } | ^ This is because constexpr functions in c++11 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 --- 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 @@ public: } 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 @@ public: /* Return a new array view over SIZE elements starting at START. */ constexpr array_view 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 @@ public: inclusive. */ constexpr array_view 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};