From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2vF6DyO6c184WgAAWB0awg (envelope-from ) for ; Tue, 29 Sep 2020 18:50:11 -0400 Received: by simark.ca (Postfix, from userid 112) id 31B161EF4A; Tue, 29 Sep 2020 18:50:11 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 224061EF44 for ; Tue, 29 Sep 2020 18:50:09 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 58349386F478; Tue, 29 Sep 2020 22:50:08 +0000 (GMT) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by sourceware.org (Postfix) with ESMTPS id F1003385ED4B for ; Tue, 29 Sep 2020 22:50:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F1003385ED4B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=alves.ped@gmail.com Received: by mail-wm1-f67.google.com with SMTP id k18so6480676wmj.5 for ; Tue, 29 Sep 2020 15:50:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:cc:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=E+bhsWU6eFYNZ38O5o45W7d2GsFzdD8BEpkfgcyqMuc=; b=szDyb5RtwjDN4yvZYa5LTNOB4U0a2r5brsumWJvvimAnBu6ke2GXYyCicsE2aXnrWM EFg6NUXixWvyln0eiqjSFG8RKQstbYl4CPVKBP0yI36xwBXhPOgGAYSTF8kxjsN1FXpA 8/6wHq7sDAKYlbwsSXGhmuiEZ8ZbtmdhnHmlWd860opbu546b6hrioPAQ1mELZ4gjn4F T+Q87LNxrs/0knYt+fTRcnM1RfZIexycfBpF6o08wc2luz27/6xMxcMso1EbPwLYLpME rZBsixbY/lyiqPjSnyR5Yg0D/Kvite6uVW4+pRvgh8AUoEhXLyQ7JSOM7jBzeYLYC3yx qTFQ== X-Gm-Message-State: AOAM531v8vAHa57bSnQQ23bMrZ3eBICmYmtadH5o6MSPjxNJ7XBXfI2s pNNjJ2lCvTQH6qfUFeX8LjJofkSeKRS6ow== X-Google-Smtp-Source: ABdhPJyiuXdloFB0ZV8FtoLEuNaSWTgLPHX5UVYKWAzm8Tmnel0bUbaVIgP1R4+eULserTTV0C6Dpw== X-Received: by 2002:a1c:7e15:: with SMTP id z21mr6768917wmc.21.1601419804145; Tue, 29 Sep 2020 15:50:04 -0700 (PDT) Received: from ?IPv6:2001:8a0:f905:5600:eefd:c63:53e0:3e8a? ([2001:8a0:f905:5600:eefd:c63:53e0:3e8a]) by smtp.gmail.com with ESMTPSA id i3sm7746826wrs.4.2020.09.29.15.50.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 29 Sep 2020 15:50:02 -0700 (PDT) Subject: [pushed] Tweak gdbsupport/valid-expr.h for GCC 6, fix build (Re: [PATCH 1/3] Rewrite valid-expr.h's internals in terms of the detection idiom (C++17/N4502)) From: Pedro Alves To: Tom Tromey References: <20200821144523.19451-1-pedro@palves.net> <20200821144523.19451-2-pedro@palves.net> <87mu19hgmh.fsf@tromey.com> <7dc15697-160f-e1a9-84da-f7a770e36a80@linaro.org> <87eemlhdti.fsf@tromey.com> <87a6x8hgz5.fsf@tromey.com> <1aea544a-50b6-8812-6d55-c67fe2444b61@palves.net> Message-ID: Date: Tue, 29 Sep 2020 23:50:01 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <1aea544a-50b6-8812-6d55-c67fe2444b61@palves.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit 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: , Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 9/29/20 8:24 PM, Pedro Alves wrote: > On 9/29/20 2:04 PM, Tom Tromey wrote: >>>>> I'm not sure if it was exactly this patch, but after I merged this code >>>>> to our internal tree, we started having build problems on a machine that >>>>> uses GCC 6.4. I've appended the error message. >>>>> I'm not sure it is worth doing anything about this, but I thought it >>>>> would be worth noting in case anybody else winds up in this situation. >>>>> Tom >> >> Luis> It was reported before on this thread a week or so ago. Unless GCC 6.4 >> Luis> isn't supported any longer, I think it should be fixed. >> >> Tom> Ok, thanks. I will find out tonight. >> >> Oops, I really misunderstood your note, and re-reading it now I can't >> really understand why. I thought you were saying it was fixed, but >> really you were saying it is still there and should be fixed if we want >> to support GCC 6.4. >> >> I am not sure if we should try to fix it or not. Locally I plan to >> disable unit tests on this particular machine. It is the only one using >> 6.4. > > I built a GCC 6.4 here, and could reproduce it. I'm testing a fix. > Here's what I merged. >From de38d64ad2502312afb0000ac806474c1e2c0fe5 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 29 Sep 2020 20:08:51 +0100 Subject: [PATCH] Tweak gdbsupport/valid-expr.h for GCC 6, fix build With GCC 6.4 and 6.5 (at least), unit tests that use gdbsupport/valid-expr.h's CHECK_VALID fail to compile, with: In file included from src/gdb/unittests/offset-type-selftests.c:24:0: src/gdb/unittests/offset-type-selftests.c: In substitution of 'template class Op, class ... Args> using is_detected_exact = std::is_same::type> [with Expected = selftests::offset_type::off_A&; Op = selftests::offset_type::check_valid_expr75::archetype; Args = {selftests::offset_type::off_A, selftests::offset_type::off_B}]': src/gdb/unittests/offset-type-selftests.c:75:1: required from here src/gdb/../gdbsupport/valid-expr.h:65:20: error: type/value mismatch at argument 2 in template parameter list for 'template class Op, class ... Args> using is_detected_exact = std::is_same::type>' archetype, TYPES>::value == VALID, \ ^ The important part is the "error: type/value mismatch" error. Seems like that GCC doesn't understand that archetype is an alias template, and is being strict in requiring a template class. The fix here is then to make archetype a template class, to pacify GCC. The resulting code looks like this: template struct archetype { }; static_assert (gdb::is_detected_exact, archetype, TYPES>::value == VALID, ""); is_detected_exact checks whether Op is type Expected: - For Expected, we pass the explicit EXPR_TYPE, overriding the default parameter type of archetype. - For Args we don't pass the last template parameter, so archtype defaults to the EXPR's decltype. So in essence, we're really checking whether EXPR_TYPE is the same as decltype(EXPR). We need to do the decltype in a template context in order to trigger SFINAE instead of failing to compile. The hunk in unittests/enum-flags-selftests.c becomes necessary, because unlike with the current alias template version, this new version makes GCC trigger -Wenum-compare warnings as well: src/gdb/unittests/enum-flags-selftests.c:328:33: error: comparison between 'enum selftests::enum_flags_tests::RE' and 'enum selftests::enum_flags_tests::RE2' [-Werror=enum-compare] CHECK_VALID (true, bool, RE () != RE2 ()) ^ src/gdb/../gdbsupport/valid-expr.h:61:45: note: in definition of macro 'CHECK_VALID_EXPR_INT' template \ ^ Build-tested with: - GCC {4.8.5, 6.4, 6.5, 7.3.1, 9.3.0, 11.0.0-20200910} - Clang 10.0.0 gdbsupport/ChangeLog: * valid-expr.h (CHECK_VALID_EXPR_INT): Make archetype a template class instead of an alias template and adjust static_assert. gdb/ChangeLog: * unittests/enum-flags-selftests.c: Check whether __GNUC__ is defined before using '#pragma GCC diagnostic' instead of checking __clang__. --- gdb/ChangeLog | 6 ++++++ gdbsupport/ChangeLog | 5 +++++ gdb/unittests/enum-flags-selftests.c | 24 +++++++++++++++++------- gdbsupport/valid-expr.h | 8 +++++--- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fcfa751fd7f..28e34fba04f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2020-09-29 Pedro Alves + + * unittests/enum-flags-selftests.c: Check whether __GNUC__ is + defined before using '#pragma GCC diagnostic' instead of checking + __clang__. + 2020-09-28 Tom Tromey * infrun.c (displaced_step_fixup, thread_still_needs_step_over) diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog index a2f563c81c0..91435ff1e8e 100644 --- a/gdbsupport/ChangeLog +++ b/gdbsupport/ChangeLog @@ -1,3 +1,8 @@ +2020-09-29 Pedro Alves + + * valid-expr.h (CHECK_VALID_EXPR_INT): Make archetype a template + class instead of an alias template and adjust static_assert. + 2020-09-24 Simon Marchi * event-loop.c (struct file_handler): Remove typedef, re-format. diff --git a/gdb/unittests/enum-flags-selftests.c b/gdb/unittests/enum-flags-selftests.c index af585f04ae5..5455120a259 100644 --- a/gdb/unittests/enum-flags-selftests.c +++ b/gdb/unittests/enum-flags-selftests.c @@ -315,18 +315,28 @@ CHECK_VALID (false, void, EF () != EF2 ()) CHECK_VALID (false, void, EF () != RE2 ()) CHECK_VALID (false, void, RE () != EF2 ()) -/* On clang, disable -Wenum-compare due to "error: comparison of two - values with different enumeration types [-Werror,-Wenum-compare]". - clang doesn't suppress -Wenum-compare in SFINAE contexts. Not a - big deal since misuses like these in GDB will be caught by -Werror - anyway. This check is here mainly for completeness. */ -#if defined __clang__ +/* Disable -Wenum-compare due to: + + Clang: + + "error: comparison of two values with different enumeration types + [-Werror,-Wenum-compare]" + + GCC: + + "error: comparison between ‘enum selftests::enum_flags_tests::RE’ + and ‘enum selftests::enum_flags_tests::RE2’ + [-Werror=enum-compare]" + + Not a big deal since misuses like these in GDB will be caught by + -Werror anyway. This check is here mainly for completeness. */ +#if defined __GNUC__ # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wenum-compare" #endif CHECK_VALID (true, bool, RE () == RE2 ()) CHECK_VALID (true, bool, RE () != RE2 ()) -#if defined __clang__ +#if defined __GNUC__ # pragma GCC diagnostic pop #endif diff --git a/gdbsupport/valid-expr.h b/gdbsupport/valid-expr.h index 459de179266..ff5b8f510a4 100644 --- a/gdbsupport/valid-expr.h +++ b/gdbsupport/valid-expr.h @@ -58,10 +58,12 @@ #define CHECK_VALID_EXPR_INT(TYPENAMES, TYPES, VALID, EXPR_TYPE, EXPR) \ namespace CONCAT (check_valid_expr, __LINE__) { \ \ - template \ - using archetype = decltype (EXPR); \ + template \ + struct archetype \ + { \ + }; \ \ - static_assert (gdb::is_detected_exact, \ archetype, TYPES>::value == VALID, \ ""); \ } /* namespace */ base-commit: aeaccbf4c55033bd6641709f98f3f6d65e695f85 -- 2.14.5