From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 1DD3C3858422 for ; Thu, 18 Nov 2021 20:41:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1DD3C3858422 X-ASG-Debug-ID: 1637268106-0c856e2e46178300001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id 6ZwEeE8GTOjw6EDV (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 18 Nov 2021 15:41:46 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@efficios.com X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from epycamd.internal.efficios.com (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtp.ebox.ca (Postfix) with ESMTP id 8661D441B21; Thu, 18 Nov 2021 15:41:46 -0500 (EST) From: Simon Marchi X-Barracuda-RBL-IP: 192.222.180.24 X-Barracuda-Effective-Source-IP: 192-222-180-24.qc.cable.ebox.net[192.222.180.24] X-Barracuda-Apparent-Source-IP: 192.222.180.24 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdbsupport: fix array-view compilation with c++11 && _GLIBCXX_DEBUG Date: Thu, 18 Nov 2021 15:41:45 -0500 X-ASG-Orig-Subj: [PATCH] gdbsupport: fix array-view compilation with c++11 && _GLIBCXX_DEBUG Message-Id: <20211118204145.2425971-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1637268106 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 2695 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.94047 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-19.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Nov 2021 20:41:52 -0000 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++ 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 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 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