From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id DDAC73858D1E for ; Thu, 11 May 2023 20:25:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DDAC73858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683836758; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9ImwUrUwR4bWFCA3setGsIZYGaewQMtL18TH7SV6e1o=; b=E/SxaYH7yR2iSM1RmlR7MjDEhMNw+/7s6Zqs38YTpdwPVRPnX4i5IT1FW9wMltL7IsqFv/ 0EKrek+qLlmuL9RxB0OANrucmFW9m7Dkuh6soh0cPZ9YAcNgwavqH9+Nqf8AE5hkFbD4hC sLO6eB70TjGmb2id0cFRzLj03X+U+u8= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-675-jG9nN7FvOF-7Qw6WqDNJkw-1; Thu, 11 May 2023 16:25:55 -0400 X-MC-Unique: jG9nN7FvOF-7Qw6WqDNJkw-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-61b78e49e99so47126816d6.1 for ; Thu, 11 May 2023 13:25:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683836755; x=1686428755; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9ImwUrUwR4bWFCA3setGsIZYGaewQMtL18TH7SV6e1o=; b=TeyPlSIZl+MWte9ozhccBZiSoaGs7jvPF4nS5ddxsMrQzCnHflWMPRG2p6v/lhS5wd +dAHwb8lIPftzvJ4YiOSYV07YZPovmPvtlW32wGvvVAJurC2uqMrwbIsachgNYbUBAgz VokSaxAlI6uKX5e12dpnJzuF3XKg41y+gr47ilawZyC06Azsa65xet5H7875OBB/uZeN OhCtozb6LEemBvSCRmaIlnwNWGOt5OA79h0kjHoginKvtK8X+Ky0Pjz7J6S4PSfni0aQ FXqDyp80qt/ADbtUrpIl0WpG+rJewW5rH55fCe/9e2fRuD8W1u5m+bsUgGRxlPGFBrFN Oywg== X-Gm-Message-State: AC+VfDymZ5Z75xYnkupLz/mZu9w22dycLd/TZ2KswiLfDUO5txWyQBh6 drWEO7Po8UI4cHB0INypwNzCS4WZpCsS4NBwG+YeXsys69kPhTy5zbKTvxYkqsdSoUn/ogUhnkX 2QlElk01VnQkikCD6vg== X-Received: by 2002:ad4:5ecb:0:b0:615:53c3:f32a with SMTP id jm11-20020ad45ecb000000b0061553c3f32amr37709527qvb.42.1683836754938; Thu, 11 May 2023 13:25:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Da9ds+zZjesBmyideVm91iBuO0bySTwss3mJrD5gxCCUecSUOFJwBNEiZjqjFIC4mipaWrg== X-Received: by 2002:ad4:5ecb:0:b0:615:53c3:f32a with SMTP id jm11-20020ad45ecb000000b0061553c3f32amr37709499qvb.42.1683836754647; Thu, 11 May 2023 13:25:54 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id n2-20020a0c8c02000000b005fdbcab3065sm2504998qvb.72.2023.05.11.13.25.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 May 2023 13:25:54 -0700 (PDT) Message-ID: <4d1f72c2-be3c-c548-00b8-d80216898c8a@redhat.com> Date: Thu, 11 May 2023 16:25:52 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: [PATCH][RFC] c-family: Implement __has_feature and __has_extension [PR60512] To: Alex Coplan , gcc-patches@gcc.gnu.org Cc: Iain Sandoe , Joseph Myers , Nathan Sidwell , Jonathan Wakely References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,LIKELY_SPAM_BODY,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 5/9/23 08:07, Alex Coplan wrote: > This patch implements clang's __has_feature and __has_extension in GCC. Thanks! > Currently the patch aims to implement all documented features (and some > undocumented ones) following the documentation at > https://clang.llvm.org/docs/LanguageExtensions.html with the following > omissions: > - C++ type traits. > - Objective-C-specific features. > > C++ type traits aren't currently implemented since, as the clang > documentation notes, __has_builtin is the correct "modern" way to query > for these (which GCC already implements). Of course there's an argument > that we should recognize the legacy set of C++ type traits that can be > queried through __has_feature for backwards compatibility with older > code. I'm happy to do this if reviewers think that's a good idea. That seems unnecessary unless there's a specific motivation. > There are some comments in the patch marked with XXX, I'm looking for > review comments from C/C++ maintainers on those areas in particular. > > Bootstrapped/regtested on aarch64-linux-gnu. Any comments? All the has_*_feature_p functions need to check flag_pedantic_errors, for compatibility with the Clang documented behavior "If the -pedantic-errors option is given, __has_extension is equivalent to __has_feature." > +static const cp_feature_info cp_feature_table[] = > +{ > + { "cxx_exceptions", &flag_exceptions }, > + { "cxx_rtti", &flag_rtti }, > + { "cxx_access_control_sfinae", { cxx11, cxx98 } }, > + { "cxx_alias_templates", cxx11 }, > + { "cxx_alignas", cxx11 }, > + { "cxx_alignof", cxx11 }, > + { "cxx_attributes", cxx11 }, > + { "cxx_constexpr", cxx11 }, > + { "cxx_constexpr_string_builtins", cxx11 }, > + { "cxx_decltype", cxx11 }, > + { "cxx_decltype_incomplete_return_types", cxx11 }, > + { "cxx_default_function_template_args", cxx11 }, > + { "cxx_defaulted_functions", cxx11 }, /* XXX: extension in c++98? */ I'm not sure I see the benefit of advertising a lot of these as C++98 extensions, even if we do accept them with a pedwarn by default. The ones that indicate DRs like cxx_access_control_sfinae, yes, but I'm inclined to be conservative if it isn't an extension that libstdc++ relies on, like variadic templates or inline namespaces. My concern is that important implementation is limited to C++11 mode even if we don't immediately give an error. For instance, struct A { int i = 42; A() = default; }; breaks in C++98 mode; even though we only warn for the two C++11 features, trying to actually combine them fails. So if there's a question, let's say no. > + { "cxx_delegating_constructors", { cxx11, cxx98 } }, > + { "cxx_deleted_functions", cxx11 }, > + { "cxx_explicit_conversions", { cxx11, cxx98 } }, > + { "cxx_generalized_initializers", cxx11 }, > + { "cxx_implicit_moves", cxx11 }, > + { "cxx_inheriting_constructors", cxx11 }, /* XXX: extension in c++98? */ > + { "cxx_inline_namespaces", { cxx11, cxx98 } }, > + { "cxx_lambdas", cxx11 }, /* XXX: extension in c++98? */ > + { "cxx_local_type_template_args", cxx11 }, > + { "cxx_noexcept", cxx11 }, > + { "cxx_nonstatic_member_init", { cxx11, cxx98 } }, > + { "cxx_nullptr", cxx11 }, > + { "cxx_override_control", { cxx11, cxx98 } }, > + { "cxx_reference_qualified_functions", cxx11 }, > + { "cxx_range_for", cxx11 }, > + { "cxx_raw_string_literals", cxx11 }, > + { "cxx_rvalue_references", cxx11 }, > + { "cxx_static_assert", cxx11 }, > + { "cxx_thread_local", cxx11 }, > + { "cxx_auto_type", cxx11 }, > + { "cxx_strong_enums", cxx11 }, > + { "cxx_trailing_return", cxx11 }, > + { "cxx_unicode_literals", cxx11 }, > + { "cxx_unrestricted_unions", cxx11 }, > + { "cxx_user_literals", cxx11 }, > + { "cxx_variadic_templates", { cxx11, cxx98 } }, > + { "cxx_binary_literals", { cxx14, cxx98 } }, > + { "cxx_contextual_conversions", { cxx14, cxx98 } }, > + { "cxx_decltype_auto", cxx14 }, > + { "cxx_aggregate_nsdmi", cxx14 }, > + { "cxx_init_captures", { cxx14, cxx11 } }, > + { "cxx_generic_lambdas", cxx14 }, > + { "cxx_relaxed_constexpr", cxx14 }, > + { "cxx_return_type_deduction", cxx14 }, > + { "cxx_variable_templates", { cxx14, cxx98 } }, > + { "modules", &flag_modules },