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.133.124]) by sourceware.org (Postfix) with ESMTPS id 295A33858C54 for ; Thu, 11 May 2023 21:27:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 295A33858C54 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=1683840422; 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: in-reply-to:in-reply-to:references:references; bh=72Jb8N6mdNgj5soYEYRE7szrikEhhrA3UAnJbDOQIbU=; b=HoSQdWR4Vx05yadaz1YCOAzKVUjeGI4NzyjKv97zvu+OJkcKiMSzAg8oJBVRGQR8dQ0cXZ KWQavhxHNi+QrAEh4QKij1dLUzZTTYrHRSufnKqtCCCsjef+AHaSjKIEBNrcMUYvmsf2tx A58ACd29g4ZMIZ5Krucw0/DONjgyb6c= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-578-mY_ySdOaOXSDBZFUrRVzrw-1; Thu, 11 May 2023 17:27:00 -0400 X-MC-Unique: mY_ySdOaOXSDBZFUrRVzrw-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2acd53b376dso32371561fa.0 for ; Thu, 11 May 2023 14:27:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683840419; x=1686432419; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=72Jb8N6mdNgj5soYEYRE7szrikEhhrA3UAnJbDOQIbU=; b=IYI4hC9hZIOAwkz+zJC/3DvT8jxoVZvuI8qdh57MxIVJrxyZHatFViXQRbj0iNuH1q aJ7RywQjTTl3qBUdTV9hFk1q4ENdMN6OtYCLHmEdZOoxZRIimAdUDgM4XExENlRh02wy uexL8B6OpTBKfDgPvggB4vzKQ6mbYZ1QY5vdqcQJOPah/bcC8wxvD8uY/giCLuSdU43p Q2YVFqFs9DTZ+1WaeL/xyfrxrFzy6Oiv3VunY7dG7FX5Xm1pNLgNU0BAufOGqPQp6KO3 vRPn0p+tdtNAYHSOn8iJqVyz3wP1z19QZCTOUTcU/ruKMc05iOmzkNzw8jkbxF/Gvoh/ B0zg== X-Gm-Message-State: AC+VfDysbcps9vYSbE/uPNLRo385oZ5/ouainEy+IYX7Resk4v2QMfKO CeWbGbhgyMd88tocbcC+4eEZaQX4sDGO+YV3OEntZKowX9r6TBMRxHsnnuP86Sa2vVAg8g2oIKy RRdVhD/k5K22T6nfhcQO6+Ms6wzlF43SV7g== X-Received: by 2002:a2e:91c5:0:b0:2aa:af16:5c55 with SMTP id u5-20020a2e91c5000000b002aaaf165c55mr3717386ljg.44.1683840419514; Thu, 11 May 2023 14:26:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7dI+ph4ag7KtB1Js7g/9lQb28xOZOKovIK/xupviatqDIE19A9BZiGgGVrasa6IZaMLi53FPdrj4iCB+c3Q/4= X-Received: by 2002:a2e:91c5:0:b0:2aa:af16:5c55 with SMTP id u5-20020a2e91c5000000b002aaaf165c55mr3717384ljg.44.1683840419200; Thu, 11 May 2023 14:26:59 -0700 (PDT) MIME-Version: 1.0 References: <4d1f72c2-be3c-c548-00b8-d80216898c8a@redhat.com> In-Reply-To: <4d1f72c2-be3c-c548-00b8-d80216898c8a@redhat.com> From: Jonathan Wakely Date: Thu, 11 May 2023 22:26:47 +0100 Message-ID: Subject: Re: [PATCH][RFC] c-family: Implement __has_feature and __has_extension [PR60512] To: Jason Merrill Cc: Alex Coplan , gcc-patches@gcc.gnu.org, Iain Sandoe , Joseph Myers , Nathan Sidwell X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="0000000000000b99a405fb71a626" X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,LIKELY_SPAM_BODY,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --0000000000000b99a405fb71a626 Content-Type: text/plain; charset="UTF-8" On Thu, 11 May 2023 at 21:25, Jason Merrill wrote: > 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. FWIW, I think the only other C++11 feature that libstdc++ assumes is unconditionally available in C++98 mode is 'long long' (which is technically not defined until C99 and C++11). > 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 }, > > > > --0000000000000b99a405fb71a626--