Hi Alex

> On 14 Jun 2023, at 14:31, Alex Coplan <alex.cop...@arm.com> wrote:
> 
> Hi,
> 
> This is a v2 patch addressing feedback for:
> https://gcc.gnu.org/pipermail/gcc-patches/2023-June/621050.html
> 
> macOS SDK headers using the CF_ENUM macro can expand to invalid C++ code
> of the form:
> 
> typedef enum T : BaseType T;
> 
> i.e. an elaborated-type-specifier with an additional enum-base.
> Upstream LLVM can be made to accept the above construct with
> -Wno-error=elaborated-enum-base.
> 
> This patch adds the -Welaborated-enum-base warning to GCC and adjusts
> the C++ parser to emit this warning instead of rejecting this code
> outright.
> 
> The macro expansion in the macOS headers occurs in the case that the
> compiler declares support for enums with underlying type using
> __has_feature, see
> https://gcc.gnu.org/pipermail/gcc-patches/2023-May/618450.html
> 
> GCC rejecting this construct outright means that GCC fails to bootstrap
> on Darwin in the case that it (correctly) implements __has_feature and
> declares support for C++ enums with underlying type.
> 
> With this patch, GCC can bootstrap on Darwin in combination with the
> (WIP) __has_feature patch posted at:
> https://gcc.gnu.org/pipermail/gcc-patches/2023-May/617878.html
> 
> Bootstrapped/regtested on aarch64-linux-gnu and x86_64-apple-darwin.
> OK for trunk?

For the record, I have tried this on Darwin21 and Darwin17 together with
my patches for __attribute__((availability(….))) which is also instrumental
in exposing more of the SDK content than we have previously been able
to parse on GCC.  Bootstrap succeeded there, and I will try on some older
versions as time permits (likely after WG21 meeting is done).

thanks
Iain

> 
> Thanks,
> Alex
> 
> gcc/c-family/ChangeLog:
> 
>        * c.opt (Welaborated-enum-base): New.
> 
> gcc/cp/ChangeLog:
> 
>        * parser.cc (cp_parser_enum_specifier): Don't reject
>        elaborated-type-specifier with enum-base, instead emit new
>        Welaborated-enum-base warning.
> 
> gcc/testsuite/ChangeLog:
> 
>        * g++.dg/cpp0x/enum40.C: Adjust expected diagnostics.
>        * g++.dg/cpp0x/forw_enum6.C: Likewise.
>        * g++.dg/cpp0x/elab-enum-base.C: New test.
> <patch.txt>

Reply via email to