From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2060.outbound.protection.outlook.com [40.107.6.60]) by sourceware.org (Postfix) with ESMTPS id 6CA103858C62 for ; Thu, 8 Jun 2023 11:07:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6CA103858C62 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6MeCKBybCi8t3dO++687rJNQpnc8Jfg7NF9aLsjkbzY=; b=oPXCQN3qqYCZ87tC+dnklOaRCTgTpX6//dfSPQz+3PYGX+zlU+SFFcHM03ZlqKo+R1OP1llE/BxN5deqffRwGeWoYhrlCvfWmNxvxUdI+W3XCe9BIKzKvSJJW0hXiVRYQYNSe89cOdR16H/Nh257xPlJ5wbWgPSc49myauRZLUM= Received: from FR0P281CA0091.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a9::11) by AM8PR08MB5634.eurprd08.prod.outlook.com (2603:10a6:20b:1d1::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Thu, 8 Jun 2023 11:07:37 +0000 Received: from VI1EUR03FT045.eop-EUR03.prod.protection.outlook.com (2603:10a6:d10:a9:cafe::76) by FR0P281CA0091.outlook.office365.com (2603:10a6:d10:a9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.19 via Frontend Transport; Thu, 8 Jun 2023 11:07:47 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by VI1EUR03FT045.mail.protection.outlook.com (100.127.144.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.24 via Frontend Transport; Thu, 8 Jun 2023 11:07:46 +0000 Received: ("Tessian outbound 8b05220b4215:v136"); Thu, 08 Jun 2023 11:07:46 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: f4062195a87c8129 X-CR-MTA-TID: 64aa7808 Received: from 407d381e696a.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 0675395F-8654-41B3-B466-0F30442A601C.1; Thu, 08 Jun 2023 11:06:45 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 407d381e696a.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 08 Jun 2023 11:06:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Upl4uHEMYYRV/jBw1+ALQRteJxFKR3cVgfxb4/JfxpXcUNkksO7VEekWkfeH0MptNtOeIS4svM92/R2KbnCRNVEd14oQsQQFWEgh1HzEmtt4vksUwG7JwweRj9312SXE5PS6XateBLiusY6wbt+FlnbdqZ+8du+rxH2wlOzcIreH98VirDAK2O3Ui6hqsKD3iAXsGQYU/jwK8pLCmuBAg+igcd1hgHZ/rT5BSR9fIHjrm8pEnVlD4ldhcTtjHOFEpz3xapyTjJgnwEX77ceo5R53Rg+eaS5YBqA9xyYDf0ukBdKeky1SgGRfb8WX/mOhlrzsM2UViYKYiT9JHnd24A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6MeCKBybCi8t3dO++687rJNQpnc8Jfg7NF9aLsjkbzY=; b=f6TbmSkSd9n09ADgx1mwwuRFBIjrcR9nQOZtG/BVna/CL1K/CwYTTBqjg7i+naxS7wpWRDZnEZ+okQHbFRK3LnwugTvDXjyDbZxCBQI59b0c4/paKkHAmy8aL7F4DLgiu9jqwgRHuj20Itk7Ic/kN+NfcJHeUoxc9G3i3agvQhHFzBD2BQ+FhnICsgbQqBcjNrA28Hbx+QxQDxq2o58ueVjhvKWuI13PWQAL1V87JwyfLDD8Y7j+sVEHj0kr2EGXwDVL3vpglcBBrDUTHXrCzxoN7EWmKRXXBZeMn8rNBBo9XZ0kh1t7bL8wjXrYDe8nyAWXPZqW/Ip36g9c6Hb3Gw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6MeCKBybCi8t3dO++687rJNQpnc8Jfg7NF9aLsjkbzY=; b=oPXCQN3qqYCZ87tC+dnklOaRCTgTpX6//dfSPQz+3PYGX+zlU+SFFcHM03ZlqKo+R1OP1llE/BxN5deqffRwGeWoYhrlCvfWmNxvxUdI+W3XCe9BIKzKvSJJW0hXiVRYQYNSe89cOdR16H/Nh257xPlJ5wbWgPSc49myauRZLUM= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from PAXPR08MB7201.eurprd08.prod.outlook.com (2603:10a6:102:20b::17) by AS2PR08MB8262.eurprd08.prod.outlook.com (2603:10a6:20b:551::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Thu, 8 Jun 2023 11:06:31 +0000 Received: from PAXPR08MB7201.eurprd08.prod.outlook.com ([fe80::5b72:ef2:156a:296a]) by PAXPR08MB7201.eurprd08.prod.outlook.com ([fe80::5b72:ef2:156a:296a%6]) with mapi id 15.20.6455.030; Thu, 8 Jun 2023 11:06:42 +0000 Date: Thu, 8 Jun 2023 12:06:37 +0100 From: Alex Coplan To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell , Iain Sandoe Subject: [PATCH][RFC] c++: Accept elaborated-enum-base in system headers Message-ID: Content-Type: multipart/mixed; boundary="6+rr12XvDTdJkPGG" Content-Disposition: inline X-ClientProxiedBy: LO2P123CA0073.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:138::6) To PAXPR08MB7201.eurprd08.prod.outlook.com (2603:10a6:102:20b::17) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: PAXPR08MB7201:EE_|AS2PR08MB8262:EE_|VI1EUR03FT045:EE_|AM8PR08MB5634:EE_ X-MS-Office365-Filtering-Correlation-Id: 916d9db8-0b87-4d3c-2085-08db6810973b x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: EChY/TeKOoscPnEfehbN3BknTSa1UTNpAzLOd5KW3Guf9JHASoPwqmGGd8COqHDLsGiIGCyRDQepIoGdXZWJxqRdIDPyk9WxPcEmeR8KYQ4JY53rigUmlVQ0ZhQ0gPwzZA4yhVQrGYT13vjMDxuP4urZfORhFkk7g4oBd99aQnjHJ9LynMFffQuZFaOUOI+bc5JeiOkvAtR0goAyLlOgmsuo43GT86ybi7YOTflYyQE6YsC8PSou33PPhBPnRMP3fnW3bwwFybm9n0YT3jQn8yQgNXTR2L7WoTYcNykMO4h0SIzfTfo6eyciDguAntiUTfyxuLV2MdHLDVG5O3U//q4/HBhPCauz3LpTlAczWVHg4/w7avs2069tQrlUdhTdeqAOso7Dq1JF81AxsCzqmi4kxrJ6hNy/TkJ50jY8Q6PEAvLyqbl+X3SD+JGrHQD06EVz3hL3cgg7Wiag5isVrrNfiByYayD3nZ6vT8tIP7JOuV9hSf7kJEpv5Se/np3Nt8MbDxA0DxjxV0W+ZHPmaOjFUYYdcWwrovFTDdqFScXiDUU4ogHz/KKDc8HtukVkcWvKSiJyxUM00iARF5zDh5n+uK1U+EXcVQpdylPMb8iOe0dsSJH+m+E7B+iZgQ0AP6mBD9dYkNkI78SAycxcuw== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR08MB7201.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(376002)(396003)(136003)(366004)(39860400002)(451199021)(66946007)(66476007)(6916009)(66556008)(8936002)(8676002)(4326008)(316002)(54906003)(2906002)(41300700001)(478600001)(235185007)(5660300002)(44832011)(33964004)(44144004)(6486002)(966005)(6512007)(6506007)(26005)(6666004)(186003)(86362001)(21480400003)(36756003)(2616005)(38100700002)(2700100001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB8262 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VI1EUR03FT045.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: b9be4807-c97b-4b8e-11da-08db68107097 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AE+2L9untd5nmujBjxQ7kuor2D+SXVRdhKUDtzWuHuMvFtVBZxpRaZyfwPg2oxh1fCn3JzreRQibmJKSvW0WWNUxZWOJxF/qjCvXYsYYqQjTBi8XxjGBZccmkU7Uyu+BbkpEQHezacN/xGfYzXnW4fHWgj/Qx8I1r2g/3PtnuQlldospPesDUKcygrfdAIq7oKWLPnuhvr9STKus1LPlHxaAIDEHSAg1Op3qUhAuj5eL4TcAdWZPerIb4ZE3Aie+lKRzyXG5d2dgZqZxqC3BwXIi/JNgBHLh3F8uPTeNpwJ20yQ/CUoUg6DJuZ+hRxjRzRXjctYOQpyY7DXKaGingmhSLQeF9yGTEYSlfpSpbKgXuS5Z/Rpoa7rA8unatY/KHGQiffSibmcJ6QeP9QAIMjkrTQxIo8IroPgatPaZy8f03p0/KKuFEBPej5+QgAzhP3UDSKYtGWOSogjMoPki3Zd4m50R3+Osak/fqpisZ5Htt8q5S+hU9QX8RdTi7ngJeqZyycJu1ohfgdkGk/uv6TuJgDaOXK+qhBA2+LPQnUbBzaeuAV5H6xmtX3t4TvtP4Rdj3b8H3dOMdfto81uj6X/Lw5oKmCG/dMaTqOJ1ki/tRVmRTizGrXH9ZASqBCjYmbOxBP6vrUhULs0yJr0Q3S2F1epLM645mn2thJMERq0gPIKrbWOEBlkHCQnIn9oWpwufuK4RwNnJNCT9eTMIMVuaiOh0jG4rMZVxpf9b12WWnB996e4XAeOgVUoXb0gexF44lEhZsLsPmzBQvneafsIQnsCTpDn52t8Y44Ofb2g= X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230028)(4636009)(346002)(376002)(136003)(39860400002)(396003)(451199021)(46966006)(40470700004)(36840700001)(36756003)(54906003)(2906002)(40460700003)(82310400005)(478600001)(8676002)(86362001)(235185007)(41300700001)(5660300002)(82740400003)(8936002)(81166007)(316002)(40480700001)(44832011)(70206006)(70586007)(21480400003)(4326008)(47076005)(6916009)(6506007)(356005)(6512007)(26005)(2616005)(186003)(336012)(36860700001)(107886003)(44144004)(966005)(6486002)(33964004)(6666004)(2700100001);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jun 2023 11:07:46.7494 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 916d9db8-0b87-4d3c-2085-08db6810973b X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: VI1EUR03FT045.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5634 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,GIT_PATCH_0,KAM_DMARC_NONE,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY 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: --6+rr12XvDTdJkPGG Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Hi, 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 macro expansion 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. This patch attempts to accept this construct in the C++ parser but only if it appears in system headers. 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 We also attempt to improve the diagnostic for this case, using a similar diagnostic to that given by LLVM. If it is more palatable I can look into restricting the change to accept this code to only take effect on Darwin, but it's not clear that that's any better or worse. Other possible approaches here include trying to fixincludes the SDK framework headers, but as Iain pointed out in the review of the has_feature RFC, the necessary infrastructure doesn't exist at the moment. Even if this support did exist, I believe the headers would require quite extensive non-trivial "fixing". Adjusting the parser to accept this construct in system headers seemed more pragmatic and cleaner on balance. Bootstrapped/regtested on aarch64-linux-gnu and x86_64-apple-darwin. Any thoughts? Thanks, Alex gcc/cp/ChangeLog: * parser.cc (cp_parser_enum_specifier): Accept elaborated-type-specifier with enum-base if in system headers. Improve diagnostic when rejecting such a construct. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/enum40.C: Adjust expected diagnostics. * g++.dg/cpp0x/forw_enum6.C: Likewise. * g++.dg/ext/elab-enum-header.C: New test. * g++.dg/ext/elab-enum-invalid.C: New test. --6+rr12XvDTdJkPGG Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="patch.txt" diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index d77fbd20e56..e13133a6cfb 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -21024,11 +21024,13 @@ cp_parser_enum_specifier (cp_parser* parser) /* Check for the `:' that denotes a specified underlying type in C++0x. Note that a ':' could also indicate a bitfield width, however. */ + location_t colon_loc = UNKNOWN_LOCATION; if (cp_lexer_next_token_is (parser->lexer, CPP_COLON)) { cp_decl_specifier_seq type_specifiers; /* Consume the `:'. */ + colon_loc = cp_lexer_peek_token (parser->lexer)->location; cp_lexer_consume_token (parser->lexer); auto tdf @@ -21073,12 +21075,20 @@ cp_parser_enum_specifier (cp_parser* parser) return error_mark_node; } /* An opaque-enum-specifier must have a ';' here. */ - if ((scoped_enum_p || underlying_type) + if ((scoped_enum_p + || (underlying_type && !in_system_header_at (colon_loc))) && cp_lexer_next_token_is_not (parser->lexer, CPP_SEMICOLON)) { if (has_underlying_type) - cp_parser_commit_to_tentative_parse (parser); - cp_parser_error (parser, "expected %<;%> or %<{%>"); + { + cp_parser_commit_to_tentative_parse (parser); + error_at (colon_loc, + "declaration of enumeration with " + "fixed underlying type and no enumerator list is " + "only permitted as a standalone declaration"); + } + else + cp_parser_error (parser, "expected %<;%> or %<{%>"); if (has_underlying_type) return error_mark_node; } diff --git a/gcc/testsuite/g++.dg/cpp0x/enum40.C b/gcc/testsuite/g++.dg/cpp0x/enum40.C index cfdf2a4a18a..d3ffeb62d70 100644 --- a/gcc/testsuite/g++.dg/cpp0x/enum40.C +++ b/gcc/testsuite/g++.dg/cpp0x/enum40.C @@ -4,23 +4,25 @@ void foo () { - enum : int a alignas; // { dg-error "expected" } + enum : int a alignas; // { dg-error "declaration of enum" } + // { dg-error {expected '\(' before ';'} "" { target *-*-* } .-1 } } void bar () { - enum : int a; // { dg-error "expected" } + enum : int a; // { dg-error "declaration of enum" } } void baz () { - enum class a : int b alignas; // { dg-error "expected" } + enum class a : int b alignas; // { dg-error "declaration of enum" } + // { dg-error {expected '\(' before ';'} "" { target *-*-* } .-1 } } void qux () { - enum class a : int b; // { dg-error "expected" } + enum class a : int b; // { dg-error "declaration of enum" } } diff --git a/gcc/testsuite/g++.dg/cpp0x/forw_enum6.C b/gcc/testsuite/g++.dg/cpp0x/forw_enum6.C index 01bf563bcdd..8ad3f733292 100644 --- a/gcc/testsuite/g++.dg/cpp0x/forw_enum6.C +++ b/gcc/testsuite/g++.dg/cpp0x/forw_enum6.C @@ -23,7 +23,7 @@ enum class E7 : int; //ok enum class E3 e3; // { dg-error "scoped enum must not use" } enum struct E3 e4; // { dg-error "scoped enum must not use" } -enum E5 : int e5; // { dg-error "expected|invalid type" } +enum E5 : int e5; // { dg-error "declaration of enumeration with fixed underlying type|invalid type" } enum E6 : int { a, b, c }; // { dg-message "previous definition" } enum E6 : int { a, b, c }; // { dg-error "multiple definition" } diff --git a/gcc/testsuite/g++.dg/ext/elab-enum-header.C b/gcc/testsuite/g++.dg/ext/elab-enum-header.C new file mode 100644 index 00000000000..d8c03faf443 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/elab-enum-header.C @@ -0,0 +1,5 @@ +// { dg-do compile { target c++11 } } +// { dg-additional-options "-fpreprocessed" } +# 1 "" 3 +typedef long CFIndex; +typedef enum CFComparisonResult : CFIndex CFComparisonResult; diff --git a/gcc/testsuite/g++.dg/ext/elab-enum-invalid.C b/gcc/testsuite/g++.dg/ext/elab-enum-invalid.C new file mode 100644 index 00000000000..db3957d7367 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/elab-enum-invalid.C @@ -0,0 +1,4 @@ +// { dg-do compile { target c++11 } } +typedef long CFIndex; +typedef enum CFComparisonResult : CFIndex CFComparisonResult; +// { dg-error "declaration of enumeration with fixed underlying type" "" {target *-*-*} .-1 } --6+rr12XvDTdJkPGG--