public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Alex Coplan <alex.coplan@arm.com>, gcc-patches@gcc.gnu.org
Cc: Iain Sandoe <iain@sandoe.co.uk>,
	Joseph Myers <joseph@codesourcery.com>,
	Nathan Sidwell <nathan@acm.org>,
	Jonathan Wakely <jwakely@redhat.com>
Subject: Re: [PATCH][RFC] c-family: Implement __has_feature and __has_extension [PR60512]
Date: Thu, 11 May 2023 16:25:52 -0400	[thread overview]
Message-ID: <4d1f72c2-be3c-c548-00b8-d80216898c8a@redhat.com> (raw)
In-Reply-To: <ZFo3b8RDN8nseojl@arm.com>

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 },




  reply	other threads:[~2023-05-11 20:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-09 12:07 Alex Coplan
2023-05-11 20:25 ` Jason Merrill [this message]
2023-05-11 21:26   ` Jonathan Wakely
2023-07-06 13:58   ` Alex Coplan
2023-05-14 16:05 ` Iain Sandoe
2023-06-20 12:30   ` Alex Coplan
2023-06-20 14:08     ` Iain Sandoe
2023-07-06 14:01       ` Alex Coplan
2023-07-06 15:23         ` Iain Sandoe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4d1f72c2-be3c-c548-00b8-d80216898c8a@redhat.com \
    --to=jason@redhat.com \
    --cc=alex.coplan@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=iain@sandoe.co.uk \
    --cc=joseph@codesourcery.com \
    --cc=jwakely@redhat.com \
    --cc=nathan@acm.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).