From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by sourceware.org (Postfix) with ESMTPS id 7503D398E4BA for ; Thu, 17 Sep 2020 16:23:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7503D398E4BA Received: by mail-qv1-xf32.google.com with SMTP id q10so1277159qvs.1 for ; Thu, 17 Sep 2020 09:23:20 -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:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=kwKAkIQtxjPT/KrpPovVPjktEBOnghNDXOhK2sZ57pw=; b=dx77/uBKjGfTQf3U4jnxMqRPsD+8RYSzN0vUr04nA9zrE2bwtx5U9uJ/wtZVmfueqO Wt39a9NhCCkvh0tc4Jt0EGjU1xUJBksWHe4LgDXaNijhe6aLM0ORHkFQULnEp2H+cPym r9qZTD7bNB1LLRyLGpbhIESk93Cj5Z1OCZw6Ns1BTbdLP4uvsA5olLPBra6mfJbor/JR y3h/f7d2sbNyYD4C1EQpngVgSHW37E5Cv+0nifzVr9DGf3WHVrHLb1UESXkaVthB1go2 4EMf+YMjWUS1eQ7PwDSJWt4JJ6bE3KfcSTvPQIeQc1ZS+J8HQkiBn1tvhz4z/+kDwVoK QTpQ== X-Gm-Message-State: AOAM530FuHsQEtrTW14hZzZgw2LHOUwAenpb+oFyvnU5VNhM1fOk6Bt+ 0XGUd2S1UibuDVyTgXYZFXhC+nKYIGnv+g== X-Google-Smtp-Source: ABdhPJxe5nnk5SiUiHTTN9p7zNbFPaNQWFl2W796Yac43rsSCYkFNbi2tfVX17y7zY0ySctWnq7IzA== X-Received: by 2002:a0c:8f02:: with SMTP id z2mr29660073qvd.21.1600359799585; Thu, 17 Sep 2020 09:23:19 -0700 (PDT) Received: from ?IPv6:2804:7f0:8283:9bb9:21e0:ece7:98fb:b205? ([2804:7f0:8283:9bb9:21e0:ece7:98fb:b205]) by smtp.gmail.com with ESMTPSA id f13sm158759qko.122.2020.09.17.09.23.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Sep 2020 09:23:19 -0700 (PDT) Subject: Re: [pushed v2 3/4] Rewrite valid-expr.h's internals in terms of the detection idiom (C++17/N4502) To: Vaseeharan Vinayagamoorthy , Pedro Alves , "gdb-patches@sourceware.org" References: <20200914213112.19593-1-pedro@palves.net> <20200914213112.19593-4-pedro@palves.net> <63D23DB1-0CE4-44B5-A074-F64C2DE53109@arm.com> <6E9EDA4F-A4F7-4A0D-8E06-3CBA7752F695@arm.com> From: Luis Machado Message-ID: <1d234e1b-a910-da9c-272e-e658b14ea1ca@linaro.org> Date: Thu, 17 Sep 2020 13:23:15 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <6E9EDA4F-A4F7-4A0D-8E06-3CBA7752F695@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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, 17 Sep 2020 16:23:22 -0000 Ok. Even though 14.04 is no longer supported, I suspect GCC 6.4.1 is still fairly recent that we shouldn't be seeing this. On 9/17/20 1:10 PM, Vaseeharan Vinayagamoorthy wrote: > I observe this error when building on an aarch64-none-linux-gnu machine, running ubuntu 14.04.5. > The compiler it is using is aarch64-none-linux-gnu-gcc version 6.4.1. > > > On 17/09/2020, 11:58, "Gdb-patches on behalf of Vaseeharan Vinayagamoorthy" wrote: > > Relevant to this patch, I am seeing error: type/value mismatch from valid-expr.h:65:20 when building GDB with: > Build: aarch64-none-linux-gnu > Host: aarch64-none-linux-gnu > Target: aarch64-none-linux-gnu > > > In file included from binutils-gdb--gdb/gdb/unittests/offset-type-selftests.c:24:0: > /binutils-gdb--gdb/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}]': > > /binutils-gdb--gdb/gdb/unittests/offset-type-selftests.c:75:1: required from here > /binutils-gdb--gdb/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, \ > ^ > /binutils-gdb--gdb/gdb/../gdbsupport/valid-expr.h:79:3: note: in expansion of macro 'CHECK_VALID_EXPR_INT' > CHECK_VALID_EXPR_INT (ESC_PARENS(typename T1, typename T2), \ > ^~~~~~~~~~~~~~~~~~~~ > /binutils-gdb--gdb/gdb/unittests/offset-type-selftests.c:42:3: note: in expansion of macro 'CHECK_VALID_EXPR_2' > CHECK_VALID_EXPR_2 (off_A, off_B, VALID, EXPR_TYPE, EXPR) > ^~~~~~~~~~~~~~~~~~ > > > > Regards, > Vasee > > > > > On 14/09/2020, 22:31, "Gdb-patches on behalf of Pedro Alves" wrote: > > An earlier attempt at doing this had failed (wouldn't work in GCCs > around 4.8, IIRC), but now that I try again, it works. I suspect that > my previous attempt did not use the pre C++14-safe void_t (in > traits.h). > > I want to switch to this model because: > > - It's the standard detection idiom that folks will learn starting > with C++17. > > - In the enum_flags unit tests, I have a static_assert that triggers > a warning (resulting in build error), which GCC does not suppress > because the warning is not being triggered in the SFINAE context. > Switching to the detection idiom fixes that. Alternatively, > switching to the C++03-style expression-validity checking with a > varargs overload would allow addressing that, but I think that > would be going backwards idiomatically speaking. > > - While this patch shows a net increase of lines of code, the magic > being added to traits.h can be removed in a few years when we start > requiring C++17. > > gdbsupport/ChangeLog: > > * traits.h (struct nonesuch, struct detector, detected_or) > (detected_or_t, is_detected, detected_t, detected_or) > (detected_or_t, is_detected_exact, is_detected_convertible): New. > * valid-expr.h (CHECK_VALID_EXPR_INT): Use gdb::is_detected_exact. > --- > gdbsupport/ChangeLog | 7 ++++++ > gdbsupport/traits.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ > gdbsupport/valid-expr.h | 20 +++------------ > 3 files changed, 77 insertions(+), 17 deletions(-) > > diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog > index 6cda6050f9..4858cc6b56 100644 > --- a/gdbsupport/ChangeLog > +++ b/gdbsupport/ChangeLog > @@ -1,3 +1,10 @@ > +2020-09-14 Pedro Alves > + > + * traits.h (struct nonesuch, struct detector, detected_or) > + (detected_or_t, is_detected, detected_t, detected_or) > + (detected_or_t, is_detected_exact, is_detected_convertible): New. > + * valid-expr.h (CHECK_VALID_EXPR_INT): Use gdb::is_detected_exact. > + > 2020-09-10 Kamil Rytarowski > > * eintr.h: New file. > diff --git a/gdbsupport/traits.h b/gdbsupport/traits.h > index 2a6f00654c..93b609ac10 100644 > --- a/gdbsupport/traits.h > +++ b/gdbsupport/traits.h > @@ -52,6 +52,73 @@ struct make_void { typedef void type; }; > template > using void_t = typename make_void::type; > > +/* Implementation of the detection idiom: > + > + - http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4502.pdf > + - http://en.cppreference.com/w/cpp/experimental/is_detected > + > +*/ > + > +struct nonesuch > +{ > + nonesuch () = delete; > + ~nonesuch () = delete; > + nonesuch (const nonesuch &) = delete; > + void operator= (const nonesuch &) = delete; > +}; > + > +namespace detection_detail { > +/* Implementation of the detection idiom (negative case). */ > +template + template class Op, typename... Args> > +struct detector > +{ > + using value_t = std::false_type; > + using type = Default; > +}; > + > +/* Implementation of the detection idiom (positive case). */ > +template class Op, typename... Args> > +struct detector>, Op, Args...> > +{ > + using value_t = std::true_type; > + using type = Op; > +}; > + > +/* Detect whether Op is a valid type, use Default if not. */ > +template class Op, > + typename... Args> > +using detected_or = detector; > + > +/* Op if that is a valid type, otherwise Default. */ > +template class Op, > + typename... Args> > +using detected_or_t > + = typename detected_or::type; > + > +} /* detection_detail */ > + > +template class Op, typename... Args> > +using is_detected > + = typename detection_detail::detector::value_t; > + > +template class Op, typename... Args> > +using detected_t > + = typename detection_detail::detector::type; > + > +template class Op, typename... Args> > +using detected_or = detection_detail::detected_or; > + > +template class Op, typename... Args> > +using detected_or_t = typename detected_or::type; > + > +template class Op, typename... Args> > +using is_detected_exact = std::is_same>; > + > +template class Op, typename... Args> > +using is_detected_convertible > + = std::is_convertible, To>; > + > /* A few trait helpers, mainly stolen from libstdc++. Uppercase > because "and/or", etc. are reserved keywords. */ > > diff --git a/gdbsupport/valid-expr.h b/gdbsupport/valid-expr.h > index b1c8446814..a22fa61134 100644 > --- a/gdbsupport/valid-expr.h > +++ b/gdbsupport/valid-expr.h > @@ -58,26 +58,12 @@ > #define CHECK_VALID_EXPR_INT(TYPENAMES, TYPES, VALID, EXPR_TYPE, EXPR) \ > namespace CONCAT (check_valid_expr, __LINE__) { \ > \ > - template \ > - struct is_valid_expression \ > - : std::false_type {}; \ > - \ > template \ > - struct is_valid_expression> \ > - : std::true_type {}; \ > + using archetype = decltype (EXPR); \ > \ > - static_assert (is_valid_expression::value == VALID, \ > + static_assert (gdb::is_detected_exact + archetype, TYPES>::value == VALID, \ > ""); \ > - \ > - template \ > - struct is_same_type \ > - : std::is_same {}; \ > - \ > - template \ > - struct is_same_type> \ > - : std::is_same {}; \ > - \ > - static_assert (is_same_type::value, ""); \ > } /* namespace */ > > /* A few convenience macros that support expressions involving a > -- > 2.14.5 > > >