From patchwork Thu Feb 22 08:27:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 204617 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp108308dyb; Thu, 22 Feb 2024 00:28:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUqUssFIJRXXvcOtC7I68yq2sY3kjMmKB2yNVgBK0yn8IaOBTihEAqQnS2JLreoY8l0DiZ2ZgeWlXQkhWTq1F42LiJ+jA== X-Google-Smtp-Source: AGHT+IFXQwb/qeQB3xTqNnUXnkIZE3XDsLRF1+5r7Pos5fFqsJKJAg4Xsl1UKh7SWpCGc3X30YqO X-Received: by 2002:a81:a743:0:b0:607:9cf8:931f with SMTP id e64-20020a81a743000000b006079cf8931fmr17688561ywh.6.1708590529501; Thu, 22 Feb 2024 00:28:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708590529; cv=pass; d=google.com; s=arc-20160816; b=Ni1NcPuy1TE8lTAL6Xkb6chVuoTofJKqJ2wQZNp+go1kL7nsbZ13y/zzYiCy55+a6T //E0rXe5sGe03W0frTWCFFNmQjE/vNF0x7voZr5d5DzShROmRSCg5/1lDEIjF5E6tqmx JN++f2iHEU4ie5VQLkvdwZkWGjoXMa/pN17grFajjWkXNkem5zkxW61Nk88Jj3Hzydl/ DypVUyw/pNFpfaRU/ctEO+mxvlDnDkTAJcdsq+4s2ZxA4AuA/gLeKrt3uhG3IvkYWNB/ r2kVmDylx48SasYVRt4c6qop6n3hE1r2lTHGFN5EYtQu/sYwl7CblOjglPv9Rlm1cdZQ j7mw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=Pxyw61+Xd8JcT8JyLnYAxjXZ6PN7TqhktEE6PxAi1Zo=; fh=WTPIEFAqRJUGMGa+mWD6eZvLHBN5WcIP5KyiQkU5DGA=; b=0l09NyADeQQhYbwPvjxabOn2TbcpQpzH6cfzNNPA8VKrSCcOovTxr2jW067J7SrSDm adlKLJ6yrRD7tZ8O2nKxjyLGIWkmQyeombFcTTLb4K8isHpB81gGdz88eOoLUtZm7cBO 05EUmsNBdtD0dvfbc4beCk26I6l0uLf+kD7I4V7Vso9I+0+WSNvlTNVVsHNEUzVYZqC7 a3HP/gt8C4cmN8FP3Kr0Fh+0pS8V5r6YYO8nW4Pc777CyoKX9vFOxVDWOVc2fRdDuVXm xCXML0erHDS64aLNovUG6QgG/+iswSDVClINAI1opoBE9wR4KwbzkdL6avIqd9z+PoN2 hi+g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KQZtFA0m; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ye23-20020a05620a3b9700b007878ab06c11si2432521qkn.235.2024.02.22.00.28.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 00:28:49 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KQZtFA0m; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2CE433858418 for ; Thu, 22 Feb 2024 08:28:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 8EE943858D34 for ; Thu, 22 Feb 2024 08:27:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8EE943858D34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8EE943858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708590451; cv=none; b=Ar6wd14eYQhMuAZ+yJk8beOfBucS7IaHAI2urMFi8MMo2UBG7YOaUp1O5gI0gUJtGFGIno7jntkwMIxK95hr2DQmZhW3nqSJg2AF2yvuzlbkHdgrvmxdxqoNt0S0UpEQR3nWRVM2CU5wC9it1rwR61GL4mYY7DWsRtWNYJPJ+68= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708590451; c=relaxed/simple; bh=ohCJTFDgyKytTKbiq0sv3o0C3fNk/9KfwZIQyzXirmg=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=WzmoMF+Du3Ev1ubcfQ9373npEIszMh5ylbDBGvrbJuBW3OBjOr8QOvq2L6rL77TRWL1NBLrzVrKKOfp3pbKa7Av3GmAdNBjMX5GO/HBOnPhqgS6NnnTXTwwCFIyZruJqsELru1CN2piTt7sKgonUUxOhoMCI2OjjYpen49UBuhA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708590448; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=Pxyw61+Xd8JcT8JyLnYAxjXZ6PN7TqhktEE6PxAi1Zo=; b=KQZtFA0mmo3J+6HM8H6gvtVDFqsERKKCTOh4dmBJTse+V+8wDJsU9a4nA4WJirmO1Yr5G2 fb41BuzzTp4NVWxt3o0EKwd8uMrkIllNlMaNZpLv7U9IjP+XlIcQM/afrJjkKWN12WI6Xl HmRD2UiZr+08KyHuinsdc7/iG513C2I= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-333-jJtX2lvSObiYnoXFN-pdCw-1; Thu, 22 Feb 2024 03:27:26 -0500 X-MC-Unique: jJtX2lvSObiYnoXFN-pdCw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1DF7A811E81; Thu, 22 Feb 2024 08:27:26 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9F280492BE7; Thu, 22 Feb 2024 08:27:25 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 41M8RMqR2145673 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 22 Feb 2024 09:27:23 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 41M8RM3M2145672; Thu, 22 Feb 2024 09:27:22 +0100 Date: Thu, 22 Feb 2024 09:27:21 +0100 From: Jakub Jelinek To: "Joseph S. Myers" , Richard.Sandiford@arm.com Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c: Handle scoped attributes in __has*attribute and scoped attribute parsing changes in -std=c11 etc. modes [PR114007] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791587022993432313 X-GMAIL-MSGID: 1791587022993432313 Hi! We aren't able to parse __has_attribute (vendor::attr) (and __has_c_attribute and __has_cpp_attribute) in strict C < C23 modes. While in -std=gnu* modes or in -std=c23 there is CPP_SCOPE token, in -std=c* (except for -std=c23) there are is just a pair of CPP_COLON tokens. The c-lex.cc hunk adds support for that. That leads to a question if we should return 1 or 0 from __has_attribute (gnu::unused) or not, because while [[gnu::unused]] is parsed fine in -std=gnu*/-std=c23 modes (sure, with pedwarn for < C23), we do not parse it at all in -std=c* (except for -std=c23), we only parse [[__extension__ gnu::unused]] there. While the __extension__ in there helps to avoid the pedwarn, I think it is better to be consistent between GNU and strict C < C23 modes and parse [[gnu::unused]] too; on the other side, I think parsing [[__extension__ gnu : : unused]] is too weird and undesirable. So, the following patch adds a flag during preprocessing at the point where we normally create CPP_SCOPE tokens out of 2 consecutive colons on the first CPP_COLON to mark the consecutive case (as we are tight on the bits, I've reused the PURE_ZERO flag, which is used just by the C++ FE and only ever set (both C and C++) on CPP_NUMBER tokens, this new flag has the same value and is only ever used on CPP_COLON tokens) and instead of checking loose_scope_p argument (i.e. whether it is [[__extension__ ...]] or not), it just parses CPP_SCOPE or CPP_COLON with CLONE_SCOPE flag followed by another CPP_COLON the same. The latter will never appear in >= C23 or -std=gnu* modes, though guarding its use say with flag_iso && !flag_isoc23 && doesn't really work because the __extension__ case temporarily clears flag_iso flag. This makes the -std=c11 etc. behavior more similar to -std=gnu11 or -std=c23, the only difference I'm aware of are the #define JOIN2(A, B) A##B [[vendor JOIN2(:,:) attr]] [[__extension__ vendor JOIN2(:,:) attr]] cases, which are accepted in the latter modes, but results in error in -std=c11; but the error is during preprocessing that :: doesn't form a valid preprocessing token, which is true, so just don't do that if you try to have __STRICT_ANSI__ && __STDC_VERSION__ <= 201710L compatibility. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-02-21 Jakub Jelinek PR c/114007 gcc/ * doc/extend.texi: (__extension__): Remove comments about scope tokens vs. two colons. gcc/c-family/ * c-lex.cc (c_common_has_attribute): Parse 2 CPP_COLONs with the first one with COLON_SCOPE flag the same as CPP_SCOPE. gcc/c/ * c-parser.cc (c_parser_std_attribute): Remove loose_scope_p argument. Instead of checking it, parse 2 CPP_COLONs with the first one with COLON_SCOPE flag the same as CPP_SCOPE. (c_parser_std_attribute_list): Remove loose_scope_p argument, don't pass it to c_parser_std_attribute. (c_parser_std_attribute_specifier): Adjust c_parser_std_attribute_list caller. gcc/testsuite/ * gcc.dg/c23-attr-syntax-6.c: Adjust testcase for :: being valid even in -std=c11 even without __extension__ and : : etc. not being valid anymore even with __extension__. * gcc.dg/c23-attr-syntax-7.c: Likewise. * gcc.dg/c23-attr-syntax-8.c: New test. libcpp/ * include/cpplib.h (COLON_SCOPE): Define to PURE_ZERO. * lex.cc (_cpp_lex_direct): When lexing CPP_COLON with another colon after it, if !CPP_OPTION (pfile, scope) set COLON_SCOPE flag on the first CPP_COLON token. Jakub --- gcc/doc/extend.texi.jj 2024-02-21 10:46:55.746515061 +0100 +++ gcc/doc/extend.texi 2024-02-21 17:03:22.137717754 +0100 @@ -12626,10 +12626,7 @@ In C, writing: @end smallexample suppresses warnings about using @samp{[[]]} attributes in C versions -that predate C23@. Since the scope token @samp{::} is not a single -lexing token in earlier versions of C, this construct also allows two colons -to be used in place of @code{::}. GCC does not check whether the two -colons are immediately adjacent. +that predate C23@. @end itemize @code{__extension__} has no effect aside from this. --- gcc/c-family/c-lex.cc.jj 2024-01-03 12:07:02.171734141 +0100 +++ gcc/c-family/c-lex.cc 2024-02-21 18:07:37.615640395 +0100 @@ -357,7 +357,24 @@ c_common_has_attribute (cpp_reader *pfil do nxt_token = cpp_peek_token (pfile, idx++); while (nxt_token->type == CPP_PADDING); - if (nxt_token->type == CPP_SCOPE) + if (!c_dialect_cxx () + && nxt_token->type == CPP_COLON + && (nxt_token->flags & COLON_SCOPE) != 0) + { + do + nxt_token = cpp_peek_token (pfile, idx++); + while (nxt_token->type == CPP_PADDING); + if (nxt_token->type == CPP_COLON) + { + /* __has_attribute (vendor::attr) in -std=c17 etc. modes. + :: isn't CPP_SCOPE but 2 CPP_COLON tokens, where the + first one should have COLON_SCOPE flag to distinguish + it from : :. */ + have_scope = true; + get_token_no_padding (pfile); // Eat first colon. + } + } + if (nxt_token->type == CPP_SCOPE || have_scope) { have_scope = true; get_token_no_padding (pfile); // Eat scope. --- gcc/c/c-parser.cc.jj 2024-02-14 14:26:19.599812963 +0100 +++ gcc/c/c-parser.cc 2024-02-21 18:07:20.583874512 +0100 @@ -5705,8 +5705,7 @@ c_parser_omp_sequence_args (c_parser *pa indicates whether this relaxation is in effect. */ static tree -c_parser_std_attribute (c_parser *parser, bool for_tm, - bool loose_scope_p = false) +c_parser_std_attribute (c_parser *parser, bool for_tm) { c_token *token = c_parser_peek_token (parser); tree ns, name, attribute; @@ -5720,8 +5719,8 @@ c_parser_std_attribute (c_parser *parser name = canonicalize_attr_name (token->value); c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_SCOPE) - || (loose_scope_p - && c_parser_next_token_is (parser, CPP_COLON) + || (c_parser_next_token_is (parser, CPP_COLON) + && (c_parser_peek_token (parser)->flags & COLON_SCOPE) != 0 && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) { ns = name; @@ -5841,8 +5840,7 @@ c_parser_std_attribute (c_parser *parser } static tree -c_parser_std_attribute_list (c_parser *parser, bool for_tm, - bool loose_scope_p = false) +c_parser_std_attribute_list (c_parser *parser, bool for_tm) { tree attributes = NULL_TREE; while (true) @@ -5855,7 +5853,7 @@ c_parser_std_attribute_list (c_parser *p c_parser_consume_token (parser); continue; } - tree attribute = c_parser_std_attribute (parser, for_tm, loose_scope_p); + tree attribute = c_parser_std_attribute (parser, for_tm); if (attribute != error_mark_node) { TREE_CHAIN (attribute) = attributes; @@ -5883,7 +5881,7 @@ c_parser_std_attribute_specifier (c_pars { auto ext = disable_extension_diagnostics (); c_parser_consume_token (parser); - attributes = c_parser_std_attribute_list (parser, for_tm, true); + attributes = c_parser_std_attribute_list (parser, for_tm); restore_extension_diagnostics (ext); } else --- gcc/testsuite/gcc.dg/c23-attr-syntax-6.c.jj 2023-11-09 09:04:19.499530894 +0100 +++ gcc/testsuite/gcc.dg/c23-attr-syntax-6.c 2024-02-21 19:16:48.904662570 +0100 @@ -9,19 +9,14 @@ typedef int [[__extension__ gnu::vector_size (4)]] g1; typedef int [[__extension__ gnu :: vector_size (4)]] g2; -typedef int [[__extension__ gnu : : vector_size (4)]] g3; -typedef int [[__extension__ gnu: :vector_size (4)]] g4; -typedef int [[__extension__ gnu FOO vector_size (4)]] g5; -typedef int [[__extension__ gnu BAR BAR vector_size (4)]] g6; -typedef int [[__extension__ gnu :/**/: vector_size (4)]] g7; -typedef int [[__extension__ gnu JOIN(:,:) vector_size (4)]] g8; -typedef int [[__extension__ gnu :: vector_size (sizeof (void (*)(...)))]] g10; -typedef int [[__extension__]] g11; -typedef int [[__extension__,]] g12; -typedef int [[__extension__, ,,,, ,, ,]] g13; -[[__extension__ deprecated]] int g14 (); -[[__extension__ nodiscard]] int g15 (); -[[__extension__ noreturn]] void g16 (); +typedef int [[__extension__ gnu FOO vector_size (4)]] g3; +typedef int [[__extension__ gnu :: vector_size (sizeof (void (*)(...)))]] g4; +typedef int [[__extension__]] g5; +typedef int [[__extension__,]] g6; +typedef int [[__extension__, ,,,, ,, ,]] g7; +[[__extension__ deprecated]] int g8 (); +[[__extension__ nodiscard]] int g9 (); +[[__extension__ noreturn]] void g10 (); int cases (int x) @@ -51,12 +46,42 @@ typedef int [[__extension__ unknown_attr typedef int [[__extension__ gnu:vector_size(4)]] b4; /* { dg-error {expected '\]' before ':'} } */ /* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ typedef int [[__extension__ gnu JOIN2(:,:) vector_size (4)]] b5; /* { dg-error {pasting ":" and ":" does not give a valid preprocessing token} } */ -typedef int [[gnu::vector_size(4)]] b6; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {expected '\]' before ':'} "" { target *-*-* } .-1 } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-2 } */ +typedef int [[__extension__ gnu : : vector_size (4)]] b6; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +typedef int [[__extension__ gnu: :vector_size (4)]] b7; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +typedef int [[__extension__ gnu BAR BAR vector_size (4)]] b8; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +typedef int [[__extension__ gnu :/**/: vector_size (4)]] b9; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +typedef int [[__extension__ gnu JOIN(:,:) vector_size (4)]] b10; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +typedef int [[gnu::vector_size(4)]] b11; /* { dg-error {attributes before C23} } */ +typedef int [[gnu : : vector_size(4)]] b12; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +/* { dg-error {attributes before C23} "" { target *-*-* } .-2 } */ +typedef int [[gnu : vector_size(4)]] b13; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +/* { dg-error {attributes before C23} "" { target *-*-* } .-2 } */ +typedef int [[gnu: :vector_size (4)]] b14; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +/* { dg-error {attributes before C23} "" { target *-*-* } .-2 } */ +typedef int [[gnu BAR BAR vector_size (4)]] b15; /* { dg-error {expected '\]' before ':'} } */ /* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ /* { dg-error {attributes before C23} "" { target *-*-* } .-2 } */ -typedef int [[gnu : : vector_size(4)]] b7; /* { dg-error {expected '\]' before ':'} } */ +typedef int [[gnu :/**/: vector_size (4)]] b16; /* { dg-error {expected '\]' before ':'} } */ /* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ /* { dg-error {attributes before C23} "" { target *-*-* } .-2 } */ -typedef int [[gnu : vector_size(4)]] b8; /* { dg-error {expected '\]' before ':'} } */ +typedef int [[gnu JOIN(:,:) vector_size (4)]] b17; /* { dg-error {expected '\]' before ':'} } */ /* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ /* { dg-error {attributes before C23} "" { target *-*-* } .-2 } */ +typedef int [[gnu :: vector_size (4)]] b18; /* { dg-error {attributes before C23} } */ +typedef int [[gnu FOO vector_size (4)]] b19; /* { dg-error {attributes before C23} } */ +typedef int [[gnu :: vector_size (sizeof (void (*)(...)))]] b20; /* { dg-error {attributes before C23} } */ +/* { dg-error {requires a named argument before} "" { target *-*-* } .-1 } */ +typedef int [[gnu JOIN2(:,:) vector_size (4)]] b21; /* { dg-error {pasting ":" and ":" does not give a valid preprocessing token} } */ +/* { dg-error {expected '\]' before ':'} "" { target *-*-* } .-1 } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-2 } */ +/* { dg-error {attributes before C23} "" { target *-*-* } .-3 } */ --- gcc/testsuite/gcc.dg/c23-attr-syntax-7.c.jj 2023-11-09 09:04:19.499530894 +0100 +++ gcc/testsuite/gcc.dg/c23-attr-syntax-7.c 2024-02-21 19:17:19.193247405 +0100 @@ -9,19 +9,14 @@ typedef int [[__extension__ gnu::vector_size (4)]] g1; typedef int [[__extension__ gnu :: vector_size (4)]] g2; -typedef int [[__extension__ gnu : : vector_size (4)]] g3; -typedef int [[__extension__ gnu: :vector_size (4)]] g4; -typedef int [[__extension__ gnu FOO vector_size (4)]] g5; -typedef int [[__extension__ gnu BAR BAR vector_size (4)]] g6; -typedef int [[__extension__ gnu :/**/: vector_size (4)]] g7; -typedef int [[__extension__ gnu JOIN(:,:) vector_size (4)]] g8; -typedef int [[__extension__ gnu :: vector_size (sizeof (void (*)(...)))]] g10; -typedef int [[__extension__]] g11; -typedef int [[__extension__,]] g12; -typedef int [[__extension__, ,,,, ,, ,]] g13; -[[__extension__ deprecated]] int g14 (); -[[__extension__ nodiscard]] int g15 (); -[[__extension__ noreturn]] void g16 (); +typedef int [[__extension__ gnu FOO vector_size (4)]] g3; +typedef int [[__extension__ gnu :: vector_size (sizeof (void (*)(...)))]] g4; +typedef int [[__extension__]] g5; +typedef int [[__extension__,]] g6; +typedef int [[__extension__, ,,,, ,, ,]] g7; +[[__extension__ deprecated]] int g8 (); +[[__extension__ nodiscard]] int g9 (); +[[__extension__ noreturn]] void g10 (); int cases (int x) @@ -51,10 +46,37 @@ typedef int [[__extension__ unknown_attr typedef int [[__extension__ gnu:vector_size(4)]] b4; /* { dg-error {expected '\]' before ':'} } */ /* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ typedef int [[__extension__ gnu JOIN2(:,:) vector_size (4)]] b5; -typedef int [[gnu::vector_size(4)]] b6; /* { dg-warning {attributes before C23} } */ -typedef int [[gnu : : vector_size(4)]] b7; /* { dg-error {expected '\]' before ':'} } */ +typedef int [[__extension__ gnu : : vector_size (4)]] b6; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +typedef int [[__extension__ gnu: :vector_size (4)]] b7; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +typedef int [[__extension__ gnu BAR BAR vector_size (4)]] b8; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +typedef int [[__extension__ gnu :/**/: vector_size (4)]] b9; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +typedef int [[__extension__ gnu JOIN(:,:) vector_size (4)]] b10; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +typedef int [[gnu::vector_size(4)]] b11; /* { dg-warning {attributes before C23} } */ +typedef int [[gnu : : vector_size(4)]] b12; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +/* { dg-warning {attributes before C23} "" { target *-*-* } .-2 } */ +typedef int [[gnu : vector_size(4)]] b13; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +/* { dg-warning {attributes before C23} "" { target *-*-* } .-2 } */ +typedef int [[gnu: :vector_size (4)]] b14; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +/* { dg-warning {attributes before C23} "" { target *-*-* } .-2 } */ +typedef int [[gnu BAR BAR vector_size (4)]] b15; /* { dg-error {expected '\]' before ':'} } */ +/* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ +/* { dg-warning {attributes before C23} "" { target *-*-* } .-2 } */ +typedef int [[gnu :/**/: vector_size (4)]] b16; /* { dg-error {expected '\]' before ':'} } */ /* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ /* { dg-warning {attributes before C23} "" { target *-*-* } .-2 } */ -typedef int [[gnu : vector_size(4)]] b8; /* { dg-error {expected '\]' before ':'} } */ +typedef int [[gnu JOIN(:,:) vector_size (4)]] b17; /* { dg-error {expected '\]' before ':'} } */ /* { dg-error {'gnu' attribute ignored} "" { target *-*-* } .-1 } */ /* { dg-warning {attributes before C23} "" { target *-*-* } .-2 } */ +typedef int [[gnu :: vector_size (4)]] b18; /* { dg-warning {attributes before C23} } */ +typedef int [[gnu FOO vector_size (4)]] b19; /* { dg-warning {attributes before C23} } */ +typedef int [[gnu :: vector_size (sizeof (void (*)(...)))]] b20; /* { dg-warning {attributes before C23} } */ +/* { dg-warning {requires a named argument before} "" { target *-*-* } .-1 } */ +typedef int [[gnu JOIN2(:,:) vector_size (4)]] b21; /* { dg-warning {attributes before C23} } */ --- gcc/testsuite/gcc.dg/c23-attr-syntax-8.c.jj 2024-02-21 17:12:06.949467337 +0100 +++ gcc/testsuite/gcc.dg/c23-attr-syntax-8.c 2024-02-21 17:07:37.412189117 +0100 @@ -0,0 +1,12 @@ +/* PR c/114007 */ +/* { dg-do compile } */ +/* { dg-options "-std=c11" } */ + +#if __has_c_attribute (gnu::unused) +[[gnu::unused]] +#endif +int i; +#if __has_cpp_attribute (gnu::unused) +[[gnu::unused]] +#endif +int j; --- libcpp/include/cpplib.h.jj 2024-01-05 08:35:13.720827001 +0100 +++ libcpp/include/cpplib.h 2024-02-21 16:45:17.134709568 +0100 @@ -200,6 +200,7 @@ struct GTY(()) cpp_string { #define DECIMAL_INT (1 << 6) /* Decimal integer, set in c-lex.cc. */ #define PURE_ZERO (1 << 7) /* Single 0 digit, used by the C++ frontend, set in c-lex.cc. */ +#define COLON_SCOPE PURE_ZERO /* Adjacent colons in C < 23. */ #define SP_DIGRAPH (1 << 8) /* # or ## token was a digraph. */ #define SP_PREV_WHITE (1 << 9) /* If whitespace before a ## operator, or before this token --- libcpp/lex.cc.jj 2024-01-03 12:07:27.589378046 +0100 +++ libcpp/lex.cc 2024-02-21 16:38:38.719164770 +0100 @@ -4235,8 +4235,13 @@ _cpp_lex_direct (cpp_reader *pfile) case ':': result->type = CPP_COLON; - if (*buffer->cur == ':' && CPP_OPTION (pfile, scope)) - buffer->cur++, result->type = CPP_SCOPE; + if (*buffer->cur == ':') + { + if (CPP_OPTION (pfile, scope)) + buffer->cur++, result->type = CPP_SCOPE; + else + result->flags |= COLON_SCOPE; + } else if (*buffer->cur == '>' && CPP_OPTION (pfile, digraphs)) { buffer->cur++;