From patchwork Tue Oct 15 06:33:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1997211 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DAM0X5Fd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XSPSc757Hz1xvK for ; Tue, 15 Oct 2024 17:33:52 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 33A513857B9F for ; Tue, 15 Oct 2024 06:33:51 +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 ESMTP id 68FA63858290 for ; Tue, 15 Oct 2024 06:33:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 68FA63858290 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 68FA63858290 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=1728974010; cv=none; b=J/ddTkcugLzwM1FXXQAdSlUiaafs9Noa6mMIEbuoNS5R+M/tDtU0UC0ypfwm23PrdBmJx4K4nyYTb1If3weDbhlUq2Z6vl5k3AwcTRw98Fm157L1o5vn7aARWs3SYun80ReNxDrDqUmGuZvWYlkD4cofqKnrB4YIJ2O6hPlHCxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728974010; c=relaxed/simple; bh=x2K/2V8DvqaUAJUU4Y0OY96QWtJdN+lOfnYv8mkDsi4=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=b0wwe7NSq6YFvI71laZRJRCH/Kv0XAgXAdPnQLHuGovnmHSyd9haFb55KeDU+Sa5LaeWA1nhg2QjHJeTcVfG+doCc+LOS1GDD5ZV00owB+nKyoKa5cdN6KNcm4V6UfzfuzJUg9GKcu0KoDYakuBJYAnkq0PYTMjbgQDsztOD5ik= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728974004; 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=I68fEDuU0YH+4gnet28W2FxsnyW37zCGPSjEYkCZrBA=; b=DAM0X5FdibYrXHjHS0pKVmMXINpC5+AwZtg0ONvq5X1WIyVesMvUkJ9C216Hy1dshGTknv 7IuQsnsjStmUKs57YN7sM/eXBnAuTxrcEOkmlvVgU2xiLivamHuVcTvyV3G3aey7Ufv+BX GHJsQzR8y+joZZ5j/chu2UAnb2yBMqs= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-sJ2SflGMOIS4eJbyaGOSAQ-1; Tue, 15 Oct 2024 02:33:20 -0400 X-MC-Unique: sJ2SflGMOIS4eJbyaGOSAQ-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C5B27195608A for ; Tue, 15 Oct 2024 06:33:19 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.16]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CD362300019D; Tue, 15 Oct 2024 06:33:18 +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 49F6XG3E2872221 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 15 Oct 2024 08:33:16 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 49F6XFwE2872220; Tue, 15 Oct 2024 08:33:15 +0200 Date: Tue, 15 Oct 2024 08:33:15 +0200 From: Jakub Jelinek To: "Joseph S. Myers" Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c, libcpp: Partially implement C2Y N3353 paper [PR117028] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no 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~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! The following patch partially implements the N3353 paper. In particular, it adds support for the delimited escape sequences (\u{123}, \x{123}, \o{123}) which were added already for C++23, all I had to do is split the delimited escape sequence guarding from named universal character escape sequence guards (\N{LATIN CAPITAL LETTER C WITH CARON}), which C++23 has but C2Y doesn't and emit different diagnostics for C from C++ for the delimited escape sequences. And it adds support for the new style of octal literals, 0o137 or 0O1777. I have so far added that just for C and not C++, because I have no idea whether C++ will want to handle it similarly. What the patch doesn't do is any kind of diagnostics for obsoletion of \137 or 0137, as discussed in the PR, I think it is way too early for that. Perhaps some non-default warning later on. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-10-15 Jakub Jelinek PR c/117028 libcpp/ * include/cpplib.h (struct cpp_options): Add named_uc_escape_seqs, octal_constants and cpp_warn_c23_c2y_compat members. (enum cpp_warning_reason): Add CPP_W_C23_C2Y_COMPAT enumerator. * init.cc (struct lang_flags): Add named_uc_escape_seqs and octal_constants bit-fields. (lang_defaults): Add initializers for them into the table. (cpp_set_lang): Initialize named_uc_escape_seqs and octal_constants. (cpp_create_reader): Initialize cpp_warn_c23_c2y_compat to -1. * charset.cc (_cpp_valid_ucn): Test CPP_OPTION (pfile, named_uc_escape_seqs) rather than CPP_OPTION (pfile, delimited_escape_seqs) in \N{} related tests. Change wording of C cpp_pedwarning for \u{} and emit -Wc23-c2y-compat warning for it too if needed. Formatting fixes. (convert_hex): Change wording of C cpp_pedwarning for \u{} and emit -Wc23-c2y-compat warning for it too if needed. (convert_oct): Likewise. * expr.cc (cpp_classify_number): Handle C2Y 0o or 0O prefixed octal constants. (cpp_interpret_integer): Likewise. gcc/c-family/ * c.opt (Wc23-c2y-compat): Add CPP and CppReason parameters. * c-opts.cc (set_std_c2y): Use CLK_STDC2Y or CLK_GNUC2Y rather than CLK_STDC23 and CLK_GNUC23. Formatting fix. * c-lex.cc (interpret_integer): Handle C2Y 0o or 0O prefixed and wb/WB/uwb/UWB suffixed octal constants. gcc/testsuite/ * gcc.dg/bitint-112.c: New test. * gcc.dg/c23-octal-constants-1.c: New test. * gcc.dg/c23-octal-constants-2.c: New test. * gcc.dg/c2y-octal-constants-1.c: New test. * gcc.dg/c2y-octal-constants-2.c: New test. * gcc.dg/c2y-octal-constants-3.c: New test. * gcc.dg/cpp/c23-delimited-escape-seq-1.c: New test. * gcc.dg/cpp/c23-delimited-escape-seq-2.c: New test. * gcc.dg/cpp/c2y-delimited-escape-seq-1.c: New test. * gcc.dg/cpp/c2y-delimited-escape-seq-2.c: New test. * gcc.dg/cpp/c2y-delimited-escape-seq-3.c: New test. * gcc.dg/cpp/c2y-delimited-escape-seq-4.c: New test. * gcc.dg/octal-constants-1.c: New test. * gcc.dg/octal-constants-2.c: New test. * gcc.dg/octal-constants-3.c: New test. * gcc.dg/octal-constants-4.c: New test. * gcc.dg/system-octal-constants-1.c: New test. * gcc.dg/system-octal-constants-1.h: New file. Jakub --- libcpp/include/cpplib.h.jj 2024-10-12 10:50:41.065854381 +0200 +++ libcpp/include/cpplib.h 2024-10-14 17:05:37.018748463 +0200 @@ -546,6 +546,12 @@ struct cpp_options /* Nonzero for C++23 delimited escape sequences. */ unsigned char delimited_escape_seqs; + /* Nonzero for C++23 named universal character escape sequences. */ + unsigned char named_uc_escape_seqs; + + /* Nonzero for C2Y 0o prefixed octal integer constants. */ + unsigned char octal_constants; + /* Nonzero for 'true' and 'false' in #if expressions. */ unsigned char true_false; @@ -577,6 +583,9 @@ struct cpp_options /* True if warn about differences between C11 and C23. */ signed char cpp_warn_c11_c23_compat; + /* True if warn about differences between C23 and C2Y. */ + signed char cpp_warn_c23_c2y_compat; + /* True if warn about differences between C++98 and C++11. */ bool cpp_warn_cxx11_compat; @@ -711,6 +720,7 @@ enum cpp_warning_reason { CPP_W_PEDANTIC, CPP_W_C90_C99_COMPAT, CPP_W_C11_C23_COMPAT, + CPP_W_C23_C2Y_COMPAT, CPP_W_CXX11_COMPAT, CPP_W_CXX20_COMPAT, CPP_W_CXX14_EXTENSIONS, --- libcpp/init.cc.jj 2024-10-12 10:50:41.065854381 +0200 +++ libcpp/init.cc 2024-10-14 17:37:19.958977766 +0200 @@ -108,46 +108,48 @@ struct lang_flags unsigned int elifdef : 1; unsigned int warning_directive : 1; unsigned int delimited_escape_seqs : 1; + unsigned int named_uc_escape_seqs : 1; + unsigned int octal_constants : 1; unsigned int true_false : 1; unsigned int embed : 1; }; static const struct lang_flags lang_defaults[] = { - /* u e w - b d 8 l a t - x u i i c v s s i r d r e - x i d u r d n g t h a c z f n e u m - c c n x c d s i l l l c s r l o o d l d d l f b - 9 + u i 1 i t g i i i s e i i p p f i e i i a e - 9 + m d 1 d d r t t t t p g t t e p t f r m l d */ - /* GNUC89 */ { 0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0 }, - /* GNUC99 */ { 1,0,1,1,0,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0 }, - /* GNUC11 */ { 1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0 }, - /* GNUC17 */ { 1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0 }, - /* GNUC23 */ { 1,0,1,1,1,1,0,1,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1,1 }, - /* GNUC2Y */ { 1,0,1,1,1,1,0,1,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1,1 }, - /* STDC89 */ { 0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0 }, - /* STDC94 */ { 0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0 }, - /* STDC99 */ { 1,0,1,1,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0 }, - /* STDC11 */ { 1,0,1,1,1,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0 }, - /* STDC17 */ { 1,0,1,1,1,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0 }, - /* STDC23 */ { 1,0,1,1,1,1,1,1,1,0,0,1,1,0,1,1,1,1,0,1,1,0,1,1 }, - /* STDC2Y */ { 1,0,1,1,1,1,1,1,1,0,0,1,1,0,1,1,1,1,0,1,1,0,1,1 }, - /* GNUCXX */ { 0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0 }, - /* CXX98 */ { 0,1,0,1,0,1,1,1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1,0 }, - /* GNUCXX11 */ { 1,1,1,1,1,1,0,1,1,1,1,0,0,0,0,1,1,0,0,0,0,0,1,0 }, - /* CXX11 */ { 1,1,0,1,1,1,1,1,1,1,1,0,0,1,0,0,1,0,0,0,0,0,1,0 }, - /* GNUCXX14 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0,1,0 }, - /* CXX14 */ { 1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,0,1,0,0,0,0,0,1,0 }, - /* GNUCXX17 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,1,0 }, - /* CXX17 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,0,0,0,1,0 }, - /* GNUCXX20 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,1,0 }, - /* CXX20 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,1,0 }, - /* GNUCXX23 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0 }, - /* CXX23 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0 }, - /* GNUCXX26 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0 }, - /* CXX26 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0 }, - /* ASM */ { 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } + /* u e w n + b d 8 l a a t + x u i i c v s s i r d m o r e + x i d u r d n g t h a c z f n e e c u m + c c n x c d s i l l l c s r l o o d l d d l d t f b + 9 + u i 1 i t g i i i s e i i p p f i e i i u a a e + 9 + m d 1 d d r t t t t p g t t e p t f r m c l l d */ + /* GNUC89 */ { 0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0 }, + /* GNUC99 */ { 1,0,1,1,0,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0 }, + /* GNUC11 */ { 1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0 }, + /* GNUC17 */ { 1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0 }, + /* GNUC23 */ { 1,0,1,1,1,1,0,1,1,1,0,1,1,0,1,1,1,1,0,1,1,0,0,0,1,1 }, + /* GNUC2Y */ { 1,0,1,1,1,1,0,1,1,1,0,1,1,0,1,1,1,1,0,1,1,1,0,1,1,1 }, + /* STDC89 */ { 0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 }, + /* STDC94 */ { 0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 }, + /* STDC99 */ { 1,0,1,1,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 }, + /* STDC11 */ { 1,0,1,1,1,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 }, + /* STDC17 */ { 1,0,1,1,1,0,1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 }, + /* STDC23 */ { 1,0,1,1,1,1,1,1,1,0,0,1,1,0,1,1,1,1,0,1,1,0,0,0,1,1 }, + /* STDC2Y */ { 1,0,1,1,1,1,1,1,1,0,0,1,1,0,1,1,1,1,0,1,1,1,0,1,1,1 }, + /* GNUCXX */ { 0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0 }, + /* CXX98 */ { 0,1,0,1,0,1,1,1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1,0 }, + /* GNUCXX11 */ { 1,1,1,1,1,1,0,1,1,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0 }, + /* CXX11 */ { 1,1,0,1,1,1,1,1,1,1,1,0,0,1,0,0,1,0,0,0,0,0,0,0,1,0 }, + /* GNUCXX14 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,1,0 }, + /* CXX14 */ { 1,1,0,1,1,1,1,1,1,1,1,1,1,1,0,0,1,0,0,0,0,0,0,0,1,0 }, + /* GNUCXX17 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,0,0,1,0 }, + /* CXX17 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,0,0,0,0,0,1,0 }, + /* GNUCXX20 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,0,0,1,0 }, + /* CXX20 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,0,0,0,0,0,0,1,0 }, + /* GNUCXX23 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0 }, + /* CXX23 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0 }, + /* GNUCXX26 */ { 1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0 }, + /* CXX26 */ { 1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,0 }, + /* ASM */ { 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } }; /* Sets internal flags correctly for a given language. */ @@ -180,6 +182,8 @@ cpp_set_lang (cpp_reader *pfile, enum c_ CPP_OPTION (pfile, elifdef) = l->elifdef; CPP_OPTION (pfile, warning_directive) = l->warning_directive; CPP_OPTION (pfile, delimited_escape_seqs) = l->delimited_escape_seqs; + CPP_OPTION (pfile, named_uc_escape_seqs) = l->named_uc_escape_seqs; + CPP_OPTION (pfile, octal_constants) = l->octal_constants; CPP_OPTION (pfile, true_false) = l->true_false; CPP_OPTION (pfile, embed) = l->embed; } @@ -230,6 +234,7 @@ cpp_create_reader (enum c_lang lang, cpp CPP_OPTION (pfile, warn_endif_labels) = 1; CPP_OPTION (pfile, cpp_warn_c90_c99_compat) = -1; CPP_OPTION (pfile, cpp_warn_c11_c23_compat) = -1; + CPP_OPTION (pfile, cpp_warn_c23_c2y_compat) = -1; CPP_OPTION (pfile, cpp_warn_cxx11_compat) = 0; CPP_OPTION (pfile, cpp_warn_cxx20_compat) = 0; CPP_OPTION (pfile, cpp_warn_deprecated) = 1; --- libcpp/charset.cc.jj 2024-10-12 10:50:41.063854408 +0200 +++ libcpp/charset.cc 2024-10-14 17:06:21.715119420 +0200 @@ -1579,7 +1579,7 @@ _cpp_valid_ucn (cpp_reader *pfile, const { length = 4; if (identifier_pos - && !CPP_OPTION (pfile, delimited_escape_seqs) + && !CPP_OPTION (pfile, named_uc_escape_seqs) && CPP_OPTION (pfile, std)) { *cp = 0; @@ -1631,7 +1631,7 @@ _cpp_valid_ucn (cpp_reader *pfile, const cpp_error (pfile, CPP_DL_ERROR, "empty named universal character escape sequence"); else if ((!identifier_pos || strict) - && !CPP_OPTION (pfile, delimited_escape_seqs) + && !CPP_OPTION (pfile, named_uc_escape_seqs) && CPP_OPTION (pfile, cpp_pedantic)) cpp_pedwarning (pfile, CPP_OPTION (pfile, cplusplus) @@ -1653,7 +1653,7 @@ _cpp_valid_ucn (cpp_reader *pfile, const { bool ret = true; if (identifier_pos - && (!CPP_OPTION (pfile, delimited_escape_seqs) + && (!CPP_OPTION (pfile, named_uc_escape_seqs) || !strict)) ret = cpp_warning (pfile, CPP_W_UNICODE, "%<\\N{%.*s}%> is not a valid " @@ -1676,7 +1676,7 @@ _cpp_valid_ucn (cpp_reader *pfile, const else result = 0xC0; if (identifier_pos - && (!CPP_OPTION (pfile, delimited_escape_seqs) + && (!CPP_OPTION (pfile, named_uc_escape_seqs) || !strict)) { *cp = 0; @@ -1746,6 +1746,7 @@ _cpp_valid_ucn (cpp_reader *pfile, const if (delimited && str < limit && *str == '}') { + bool warned = false; if (length == 32 && identifier_pos) { cpp_warning (pfile, CPP_W_UNICODE, @@ -1755,13 +1756,28 @@ _cpp_valid_ucn (cpp_reader *pfile, const return false; } else if (length == 32) - cpp_error (pfile, CPP_DL_ERROR, - "empty delimited escape sequence"); + { + cpp_error (pfile, CPP_DL_ERROR, "empty delimited escape sequence"); + warned = true; + } else if (!CPP_OPTION (pfile, delimited_escape_seqs) && CPP_OPTION (pfile, cpp_pedantic)) - cpp_pedwarning (pfile, (CPP_OPTION (pfile, cplusplus) - ? CPP_W_CXX23_EXTENSIONS : CPP_W_PEDANTIC), - "delimited escape sequences are only valid in C++23"); + { + if (CPP_OPTION (pfile, cplusplus)) + warned + = cpp_pedwarning (pfile, CPP_W_CXX23_EXTENSIONS, + "delimited escape sequences are only valid " + "in C++23"); + else + warned + = cpp_pedwarning (pfile, CPP_W_PEDANTIC, + "delimited escape sequences are only valid " + "in C2Y"); + } + if (!warned && CPP_OPTION (pfile, cpp_warn_c23_c2y_compat) > 0) + cpp_warning (pfile, CPP_W_C11_C23_COMPAT, + "delimited escape sequences are only valid in C2Y"); + str++; length = 0; delimited = false; @@ -2125,6 +2141,7 @@ convert_hex (cpp_reader *pfile, const uc if (delimited && from < limit && *from == '}') { + bool warned = false; from++; if (!digits_found) { @@ -2134,9 +2151,21 @@ convert_hex (cpp_reader *pfile, const uc } else if (!CPP_OPTION (pfile, delimited_escape_seqs) && CPP_OPTION (pfile, cpp_pedantic)) - cpp_pedwarning (pfile, (CPP_OPTION (pfile, cplusplus) - ? CPP_W_CXX23_EXTENSIONS : CPP_W_PEDANTIC), - "delimited escape sequences are only valid in C++23"); + { + if (CPP_OPTION (pfile, cplusplus)) + warned + = cpp_pedwarning (pfile, CPP_W_CXX23_EXTENSIONS, + "delimited escape sequences are only valid " + "in C++23"); + else + warned + = cpp_pedwarning (pfile, CPP_W_PEDANTIC, + "delimited escape sequences are only valid " + "in C2Y"); + } + if (!warned && CPP_OPTION (pfile, cpp_warn_c23_c2y_compat) > 0) + cpp_warning (pfile, CPP_W_C11_C23_COMPAT, + "delimited escape sequences are only valid in C2Y"); delimited = false; extend_char_range (&char_range, loc_reader); } @@ -2229,6 +2258,7 @@ convert_oct (cpp_reader *pfile, const uc { if (from < limit && *from == '}') { + bool warned = false; from++; if (count == 1) { @@ -2238,10 +2268,21 @@ convert_oct (cpp_reader *pfile, const uc } else if (!CPP_OPTION (pfile, delimited_escape_seqs) && CPP_OPTION (pfile, cpp_pedantic)) - cpp_pedwarning (pfile, (CPP_OPTION (pfile, cplusplus) - ? CPP_W_CXX23_EXTENSIONS : CPP_W_PEDANTIC), - "delimited escape sequences are only valid " - "in C++23"); + { + if (CPP_OPTION (pfile, cplusplus)) + warned + = cpp_pedwarning (pfile, CPP_W_CXX23_EXTENSIONS, + "delimited escape sequences are only " + "valid in C++23"); + else + warned + = cpp_pedwarning (pfile, CPP_W_PEDANTIC, + "delimited escape sequences are only " + "valid in C2Y"); + } + if (!warned && CPP_OPTION (pfile, cpp_warn_c23_c2y_compat) > 0) + cpp_warning (pfile, CPP_W_C11_C23_COMPAT, + "delimited escape sequences are only valid in C2Y"); extend_char_range (&char_range, loc_reader); } else --- libcpp/expr.cc.jj 2024-10-12 10:50:41.064854395 +0200 +++ libcpp/expr.cc 2024-10-14 17:06:05.826343034 +0200 @@ -556,6 +556,7 @@ cpp_classify_number (cpp_reader *pfile, enum {NOT_FLOAT = 0, AFTER_POINT, AFTER_EXPON} float_flag; bool seen_digit; bool seen_digit_sep; + bool zero_o_prefix; if (ud_suffix) *ud_suffix = NULL; @@ -571,6 +572,7 @@ cpp_classify_number (cpp_reader *pfile, radix = 10; seen_digit = false; seen_digit_sep = false; + zero_o_prefix = false; /* First, interpret the radix. */ if (*str == '0') @@ -601,6 +603,17 @@ cpp_classify_number (cpp_reader *pfile, SYNTAX_ERROR_AT (virtual_location, "digit separator after base indicator"); } + else if ((*str == 'o' || *str == 'O') && !CPP_OPTION (pfile, cplusplus)) + { + if (ISDIGIT (str[1])) + { + zero_o_prefix = true; + str++; + } + else if (DIGIT_SEP (str[1])) + SYNTAX_ERROR_AT (virtual_location, + "digit separator after base indicator"); + } } /* Now scan for a well-formed integer or float. */ @@ -694,6 +707,12 @@ cpp_classify_number (cpp_reader *pfile, "invalid prefix %<0b%> for floating constant"); return CPP_N_INVALID; } + if (zero_o_prefix) + { + cpp_error_with_line (pfile, CPP_DL_ERROR, virtual_location, 0, + "invalid prefix %<0o%> for floating constant"); + return CPP_N_INVALID; + } if (radix == 16 && !seen_digit) SYNTAX_ERROR_AT (virtual_location, @@ -897,8 +916,7 @@ cpp_classify_number (cpp_reader *pfile, if (radix == 2) { bool warned = false; - if (!CPP_OPTION (pfile, binary_constants) - && CPP_PEDANTIC (pfile)) + if (!CPP_OPTION (pfile, binary_constants) && CPP_PEDANTIC (pfile)) { if (CPP_OPTION (pfile, cplusplus)) warned @@ -916,6 +934,19 @@ cpp_classify_number (cpp_reader *pfile, virtual_location, 0, "binary constants are a C23 feature"); } + if (zero_o_prefix) + { + bool warned = false; + if (!CPP_OPTION (pfile, octal_constants) && CPP_PEDANTIC (pfile)) + warned + = cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC, virtual_location, + 0, "%<0o%> prefixed constants are a C2Y " + "feature or GCC extension"); + if (!warned && CPP_OPTION (pfile, cpp_warn_c23_c2y_compat) > 0) + cpp_warning_with_line (pfile, CPP_W_C23_C2Y_COMPAT, + virtual_location, 0, + "%<0o%> prefixed constants are a C2Y feature"); + } if (radix == 10) result |= CPP_N_DECIMAL; @@ -967,6 +998,8 @@ cpp_interpret_integer (cpp_reader *pfile { base = 8; p++; + if (*p == 'o' || *p == 'O') + p++; } else if ((type & CPP_N_RADIX) == CPP_N_HEX) { --- gcc/c-family/c.opt.jj 2024-10-11 11:30:38.497394831 +0200 +++ gcc/c-family/c.opt 2024-10-14 15:59:25.964318381 +0200 @@ -452,7 +452,7 @@ C ObjC Alias(Wc11-c23-compat) Deprecated in favor of -Wc11-c23-compat. Wc23-c2y-compat -C ObjC Var(warn_c23_c2y_compat) Init(-1) Warning +C ObjC CPP(cpp_warn_c23_c2y_compat) CppReason(CPP_W_C23_C2Y_COMPAT) Var(warn_c23_c2y_compat) Init(-1) Warning Warn about features not present in ISO C23, but present in ISO C2Y. Wc90-c99-compat --- gcc/c-family/c-opts.cc.jj 2024-10-04 12:28:08.544902990 +0200 +++ gcc/c-family/c-opts.cc 2024-10-14 17:48:29.550582149 +0200 @@ -1892,7 +1892,7 @@ set_std_c23 (int iso) static void set_std_c2y (int iso) { - cpp_set_lang (parse_in, iso ? CLK_STDC23: CLK_GNUC23); + cpp_set_lang (parse_in, iso ? CLK_STDC2Y : CLK_GNUC2Y); flag_no_asm = iso; flag_no_nonansi_builtin = iso; flag_iso = iso; --- gcc/c-family/c-lex.cc.jj 2024-10-12 10:50:41.054854533 +0200 +++ gcc/c-family/c-lex.cc 2024-10-14 16:52:00.322193835 +0200 @@ -899,6 +899,10 @@ interpret_integer (const cpp_token *toke { max_bits_per_digit = 3; prefix_len = 1; + if (token->val.str.len > 2 + && (token->val.str.text[1] == 'o' + || token->val.str.text[1] == 'O')) + prefix_len = 2; } else if ((flags & CPP_N_RADIX) == CPP_N_HEX) { --- gcc/testsuite/gcc.dg/bitint-112.c.jj 2024-10-14 19:01:19.743225831 +0200 +++ gcc/testsuite/gcc.dg/bitint-112.c 2024-10-14 19:02:30.459231810 +0200 @@ -0,0 +1,5 @@ +/* { dg-do compile { target bitint575 } } */ +/* { dg-options "-std=c2y" } */ + +static_assert (0o177777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777wb / 2wb * 2wb + 1wb == 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffwb, ""); +static_assert (0O3211423263360473024126605062402061031423012516423720422320324010721642021266620206352436541213777372642147046071532121506001467430513304743521547653653136162305775772330633147605317353126354wb == 0x1a2626b3784ec2856c28ca04310cc4c154e89f4224d06a023a3a208adb20867547ac28bffbeb4467130e6b451a30066f18a5b13c751b3eaf565e39317fbfa6c66ccf8567bacacecwb, ""); --- gcc/testsuite/gcc.dg/c23-octal-constants-1.c.jj 2024-10-14 18:51:29.007529522 +0200 +++ gcc/testsuite/gcc.dg/c23-octal-constants-1.c 2024-10-14 18:52:36.996573833 +0200 @@ -0,0 +1,11 @@ +/* Test that octal constants are diagnosed in C23 mode: -pedantic. */ +/* { dg-do compile } */ +/* { dg-options "-std=c23 -pedantic" } */ + +int a = 0o7; /* { dg-warning "'0o' prefixed constants" } */ +#if 0o107 /* { dg-warning "'0o' prefixed constants" } */ +#endif + +int b = 0O7; /* { dg-warning "'0o' prefixed constants" } */ +#if 0O107 /* { dg-warning "'0o' prefixed constants" } */ +#endif --- gcc/testsuite/gcc.dg/c23-octal-constants-2.c.jj 2024-10-14 18:51:31.924488521 +0200 +++ gcc/testsuite/gcc.dg/c23-octal-constants-2.c 2024-10-14 18:53:12.635072879 +0200 @@ -0,0 +1,11 @@ +/* Test that octal constants are diagnosed in C23 mode: -pedantic-errors. */ +/* { dg-do compile } */ +/* { dg-options "-std=c23 -pedantic-errors" } */ + +int a = 0o7; /* { dg-error "'0o' prefixed constants" } */ +#if 0o107 /* { dg-error "'0o' prefixed constants" } */ +#endif + +int b = 0O7; /* { dg-error "'0o' prefixed constants" } */ +#if 0O107 /* { dg-error "'0o' prefixed constants" } */ +#endif --- gcc/testsuite/gcc.dg/c2y-octal-constants-1.c.jj 2024-10-14 18:48:16.043241934 +0200 +++ gcc/testsuite/gcc.dg/c2y-octal-constants-1.c 2024-10-14 18:48:37.884934914 +0200 @@ -0,0 +1,5 @@ +/* Test C2Y octal constants. Valid syntax and types. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2y -pedantic-errors" } */ + +#include "octal-constants-1.c" --- gcc/testsuite/gcc.dg/c2y-octal-constants-2.c.jj 2024-10-14 18:48:21.969158637 +0200 +++ gcc/testsuite/gcc.dg/c2y-octal-constants-2.c 2024-10-14 18:49:45.002991468 +0200 @@ -0,0 +1,11 @@ +/* Test that octal constants are accepted in C2Y mode: compat warnings. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2y -Wc23-c2y-compat" } */ + +int a = 0o7; /* { dg-warning "C2Y feature" } */ +#if 0o107 /* { dg-warning "C2Y feature" } */ +#endif + +int b = 0O7; /* { dg-warning "C2Y feature" } */ +#if 0O107 /* { dg-warning "C2Y feature" } */ +#endif --- gcc/testsuite/gcc.dg/c2y-octal-constants-3.c.jj 2024-10-14 18:48:24.854118083 +0200 +++ gcc/testsuite/gcc.dg/c2y-octal-constants-3.c 2024-10-14 18:50:44.167159824 +0200 @@ -0,0 +1,9 @@ +/* Test C2Y octal constants. Invalid constants. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2y -pedantic-errors" } */ + +int a = 0o; /* { dg-error "invalid suffix" } */ +int b = 0Oa; /* { dg-error "invalid suffix" } */ +int c = 0O08; /* { dg-error "invalid digit" } */ +int d = 0o1.1; /* { dg-error "invalid prefix" } */ +int e = 0O0p0; /* { dg-error "invalid suffix" } */ --- gcc/testsuite/gcc.dg/cpp/c23-delimited-escape-seq-1.c.jj 2024-10-14 17:58:54.436815339 +0200 +++ gcc/testsuite/gcc.dg/cpp/c23-delimited-escape-seq-1.c 2024-10-14 17:59:05.032666716 +0200 @@ -0,0 +1,87 @@ +/* P2290R3 - Delimited escape sequences */ +/* { dg-do compile } */ +/* { dg-require-effective-target wchar } */ +/* { dg-options "-std=c23 -pedantic -Wno-c++-compat" } */ + +#include +typedef __CHAR16_TYPE__ char16_t; +typedef __CHAR32_TYPE__ char32_t; + +const char32_t *a = U"\u{1234}\u{10fffd}\u{000000000000000000000000000000000000000000000000000000000001234}\u{10FFFD}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char32_t *b = U"\x{1234}\x{10fffd}\x{000000000000000000000000000000000000000000000000000000000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char32_t *c = U"\o{1234}\o{4177775}\o{000000000000000000000000000000000000000000000000000000000000000000000000004177775}";/* { dg-warning "delimited escape sequences are only valid in" } */ +const char16_t *d = u"\u{1234}\u{bFFd}\u{00000000000000000000000000000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char16_t *e = u"\x{1234}\x{BffD}\x{000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char16_t *f = u"\o{1234}\o{137775}\o{000000000000000137775}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const wchar_t *g = L"\u{1234}\u{bFFd}\u{00000000000000000000000000000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const wchar_t *h = L"\x{1234}\x{bFFd}\x{000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const wchar_t *i = L"\o{1234}\o{137775}\o{000000000000000137775}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char *k = "\x{34}\x{000000000000000003D}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char *l = "\o{34}\o{000000000000000176}"; /* { dg-warning "delimited escape sequences are only valid in" } */ + +#if U'\u{1234}' != U'\u1234' || U'\u{10fffd}' != U'\U0010FFFD' \ + || U'\x{00000001234}' != U'\x1234' || U'\x{010fffd}' != U'\x10FFFD' \ + || U'\o{1234}' != U'\x29c' || U'\o{004177775}' != U'\x10FFFD' \ + || u'\u{1234}' != u'\u1234' || u'\u{0bffd}' != u'\uBFFD' \ + || u'\x{00000001234}' != u'\x1234' || u'\x{0Bffd}' != u'\x0bFFD' \ + || u'\o{1234}' != u'\x29c' || u'\o{00137775}' != u'\xBFFD' \ + || L'\u{1234}' != L'\u1234' || L'\u{0bffd}' != L'\uBFFD' \ + || L'\x{00000001234}' != L'\x1234' || L'\x{0bffd}' != L'\x0bFFD' \ + || L'\o{1234}' != L'\x29c' || L'\o{00137775}' != L'\xBFFD' \ + || '\x{34}' != '\x034' || '\x{0003d}' != '\x003D' \ + || '\o{34}' != '\x1C' || '\o{176}' != '\x007E' +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +#error Bad +#endif + +int +main () +{ + if (a[0] != U'\u1234' || a[0] != U'\u{1234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || a[1] != U'\U0010FFFD' || a[1] != U'\u{000010fFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || a[2] != a[0] + || a[3] != a[1] + || b[0] != U'\x1234' || b[0] != U'\x{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || b[1] != U'\x10FFFD' || b[1] != U'\x{0010fFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || b[2] != b[0] + || c[0] != U'\x29c' || c[0] != U'\o{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || c[1] != U'\x10FFFD' || c[1] != U'\o{4177775}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || c[2] != c[1]) + __builtin_abort (); + if (d[0] != u'\u1234' || d[0] != u'\u{1234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || d[1] != u'\U0000BFFD' || d[1] != u'\u{00000bFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || d[2] != d[0] + || e[0] != u'\x1234' || e[0] != u'\x{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || e[1] != u'\xBFFD' || e[1] != u'\x{00bFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || e[2] != e[0] + || f[0] != u'\x29c' || f[0] != u'\o{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || f[1] != u'\xbFFD' || f[1] != u'\o{137775}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || f[2] != f[1]) + __builtin_abort (); + if (g[0] != L'\u1234' || g[0] != L'\u{1234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || g[1] != L'\U0000BFFD' || g[1] != L'\u{00000bFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || g[2] != g[0] + || h[0] != L'\x1234' || h[0] != L'\x{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || h[1] != L'\xBFFD' || h[1] != L'\x{00bFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || h[2] != h[0] + || i[0] != L'\x29c' || i[0] != L'\o{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || i[1] != L'\xbFFD' || i[1] != L'\o{137775}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || i[2] != i[1]) + __builtin_abort (); + if (k[0] != '\x034' || k[0] != '\x{0034}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || k[1] != '\x3D' || k[1] != '\x{3d}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || l[0] != '\x1c' || l[0] != '\o{0034}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || l[1] != '\x07e' || l[1] != '\o{176}' || l[1] != '\176') /* { dg-warning "delimited escape sequences are only valid in" } */ + __builtin_abort (); + return 0; +} --- gcc/testsuite/gcc.dg/cpp/c23-delimited-escape-seq-2.c.jj 2024-10-14 17:59:16.808501539 +0200 +++ gcc/testsuite/gcc.dg/cpp/c23-delimited-escape-seq-2.c 2024-10-14 17:59:28.721334439 +0200 @@ -0,0 +1,87 @@ +/* P2290R3 - Delimited escape sequences */ +/* { dg-do compile } */ +/* { dg-require-effective-target wchar } */ +/* { dg-options "-std=c23 -pedantic-errors -Wno-c++-compat" } */ + +#include +typedef __CHAR16_TYPE__ char16_t; +typedef __CHAR32_TYPE__ char32_t; + +const char32_t *a = U"\u{1234}\u{10fffd}\u{000000000000000000000000000000000000000000000000000000000001234}\u{10FFFD}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const char32_t *b = U"\x{1234}\x{10fffd}\x{000000000000000000000000000000000000000000000000000000000001234}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const char32_t *c = U"\o{1234}\o{4177775}\o{000000000000000000000000000000000000000000000000000000000000000000000000004177775}";/* { dg-error "delimited escape sequences are only valid in" } */ +const char16_t *d = u"\u{1234}\u{bFFd}\u{00000000000000000000000000000001234}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const char16_t *e = u"\x{1234}\x{BffD}\x{000001234}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const char16_t *f = u"\o{1234}\o{137775}\o{000000000000000137775}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const wchar_t *g = L"\u{1234}\u{bFFd}\u{00000000000000000000000000000001234}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const wchar_t *h = L"\x{1234}\x{bFFd}\x{000001234}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const wchar_t *i = L"\o{1234}\o{137775}\o{000000000000000137775}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const char *k = "\x{34}\x{000000000000000003D}"; /* { dg-error "delimited escape sequences are only valid in" } */ +const char *l = "\o{34}\o{000000000000000176}"; /* { dg-error "delimited escape sequences are only valid in" } */ + +#if U'\u{1234}' != U'\u1234' || U'\u{10fffd}' != U'\U0010FFFD' \ + || U'\x{00000001234}' != U'\x1234' || U'\x{010fffd}' != U'\x10FFFD' \ + || U'\o{1234}' != U'\x29c' || U'\o{004177775}' != U'\x10FFFD' \ + || u'\u{1234}' != u'\u1234' || u'\u{0bffd}' != u'\uBFFD' \ + || u'\x{00000001234}' != u'\x1234' || u'\x{0Bffd}' != u'\x0bFFD' \ + || u'\o{1234}' != u'\x29c' || u'\o{00137775}' != u'\xBFFD' \ + || L'\u{1234}' != L'\u1234' || L'\u{0bffd}' != L'\uBFFD' \ + || L'\x{00000001234}' != L'\x1234' || L'\x{0bffd}' != L'\x0bFFD' \ + || L'\o{1234}' != L'\x29c' || L'\o{00137775}' != L'\xBFFD' \ + || '\x{34}' != '\x034' || '\x{0003d}' != '\x003D' \ + || '\o{34}' != '\x1C' || '\o{176}' != '\x007E' +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-error "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +#error Bad +#endif + +int +main () +{ + if (a[0] != U'\u1234' || a[0] != U'\u{1234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || a[1] != U'\U0010FFFD' || a[1] != U'\u{000010fFfD}' /* { dg-error "delimited escape sequences are only valid in" } */ + || a[2] != a[0] + || a[3] != a[1] + || b[0] != U'\x1234' || b[0] != U'\x{001234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || b[1] != U'\x10FFFD' || b[1] != U'\x{0010fFfD}' /* { dg-error "delimited escape sequences are only valid in" } */ + || b[2] != b[0] + || c[0] != U'\x29c' || c[0] != U'\o{001234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || c[1] != U'\x10FFFD' || c[1] != U'\o{4177775}' /* { dg-error "delimited escape sequences are only valid in" } */ + || c[2] != c[1]) + __builtin_abort (); + if (d[0] != u'\u1234' || d[0] != u'\u{1234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || d[1] != u'\U0000BFFD' || d[1] != u'\u{00000bFfD}' /* { dg-error "delimited escape sequences are only valid in" } */ + || d[2] != d[0] + || e[0] != u'\x1234' || e[0] != u'\x{001234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || e[1] != u'\xBFFD' || e[1] != u'\x{00bFfD}' /* { dg-error "delimited escape sequences are only valid in" } */ + || e[2] != e[0] + || f[0] != u'\x29c' || f[0] != u'\o{001234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || f[1] != u'\xbFFD' || f[1] != u'\o{137775}' /* { dg-error "delimited escape sequences are only valid in" } */ + || f[2] != f[1]) + __builtin_abort (); + if (g[0] != L'\u1234' || g[0] != L'\u{1234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || g[1] != L'\U0000BFFD' || g[1] != L'\u{00000bFfD}' /* { dg-error "delimited escape sequences are only valid in" } */ + || g[2] != g[0] + || h[0] != L'\x1234' || h[0] != L'\x{001234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || h[1] != L'\xBFFD' || h[1] != L'\x{00bFfD}' /* { dg-error "delimited escape sequences are only valid in" } */ + || h[2] != h[0] + || i[0] != L'\x29c' || i[0] != L'\o{001234}' /* { dg-error "delimited escape sequences are only valid in" } */ + || i[1] != L'\xbFFD' || i[1] != L'\o{137775}' /* { dg-error "delimited escape sequences are only valid in" } */ + || i[2] != i[1]) + __builtin_abort (); + if (k[0] != '\x034' || k[0] != '\x{0034}' /* { dg-error "delimited escape sequences are only valid in" } */ + || k[1] != '\x3D' || k[1] != '\x{3d}' /* { dg-error "delimited escape sequences are only valid in" } */ + || l[0] != '\x1c' || l[0] != '\o{0034}' /* { dg-error "delimited escape sequences are only valid in" } */ + || l[1] != '\x07e' || l[1] != '\o{176}' || l[1] != '\176') /* { dg-error "delimited escape sequences are only valid in" } */ + __builtin_abort (); + return 0; +} --- gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-1.c.jj 2024-10-14 17:21:25.805396557 +0200 +++ gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-1.c 2024-10-14 17:21:21.009464008 +0200 @@ -0,0 +1,6 @@ +/* N3353 - Delimited escape sequences */ +/* { dg-do run } */ +/* { dg-require-effective-target wchar } */ +/* { dg-options "-std=c2y -pedantic-errors -Wno-c++-compat" } */ + +#include "../../c-c++-common/cpp/delimited-escape-seq-1.c" --- gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-2.c.jj 2024-10-14 17:21:54.203997156 +0200 +++ gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-2.c 2024-10-14 17:53:22.709468583 +0200 @@ -0,0 +1,5 @@ +/* N3353 - Delimited escape sequences */ +/* { dg-do compile } */ +/* { dg-options "-std=c2y -pedantic-errors -Wno-c++-compat" } */ + +#include "../../c-c++-common/cpp/delimited-escape-seq-2.c" --- gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-3.c.jj 2024-10-14 17:22:50.102210967 +0200 +++ gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-3.c 2024-10-14 17:54:10.714795032 +0200 @@ -0,0 +1,30 @@ +/* P2290R3 - Delimited escape sequences */ +/* { dg-do compile } */ +/* { dg-require-effective-target wchar } */ +/* { dg-options "-std=c2y -pedantic-errors -Wno-c++-compat" } */ + +typedef __CHAR32_TYPE__ char32_t; + +const char32_t *a = U"\u{}"; /* { dg-error "empty delimited escape sequence" } */ + /* { dg-error "is not a valid universal character" "" { target c } .-1 } */ +const char32_t *b = U"\u{12" "34}"; /* { dg-error "'\\\\u\\{' not terminated with '\\}' after" } */ +const char32_t *c = U"\u{0000ffffffff}"; /* { dg-error "is not a valid universal character" } */ +const char32_t *d = U"\u{010000edcb}"; /* { dg-error "is not a valid universal character" } */ +const char32_t *e = U"\u{02000000000000000000edcb}"; /* { dg-error "is not a valid universal character" } */ +const char32_t *f = U"\u{123ghij}"; /* { dg-error "'\\\\u\\{' not terminated with '\\}' after" } */ +const char32_t *g = U"\u{123.}"; /* { dg-error "'\\\\u\\{' not terminated with '\\}' after" } */ +const char32_t *h = U"\u{.}"; /* { dg-error "'\\\\u\\{' not terminated with '\\}' after" } */ +const char32_t *i = U"\x{}"; /* { dg-error "empty delimited escape sequence" } */ +const char32_t *j = U"\x{12" "34}"; /* { dg-error "'\\\\x\\{' not terminated with '\\}' after" } */ +const char32_t *k = U"\x{0000ffffffff}"; +const char32_t *l = U"\x{010000edcb}"; /* { dg-error "hex escape sequence out of range" } */ +const char32_t *m = U"\x{02000000000000000000edcb}"; /* { dg-error "hex escape sequence out of range" } */ +const char32_t *n = U"\x{123ghij}"; /* { dg-error "'\\\\x\\{' not terminated with '\\}' after" } */ +const char32_t *o = U"\x{123.}"; /* { dg-error "'\\\\x\\{' not terminated with '\\}' after" } */ +const char32_t *p = U"\o{}"; /* { dg-error "empty delimited escape sequence" } */ +const char32_t *q = U"\o{12" "34}"; /* { dg-error "'\\\\o\\{' not terminated with '\\}' after" } */ +const char32_t *r = U"\o{0000037777777777}"; +const char32_t *s = U"\o{040000166713}"; /* { dg-error "octal escape sequence out of range" } */ +const char32_t *t = U"\o{02000000000000000000000166713}";/* { dg-error "octal escape sequence out of range" } */ +const char32_t *u = U"\o{1238}"; /* { dg-error "'\\\\o\\{' not terminated with '\\}' after" } */ +const char32_t *v = U"\o{.}"; /* { dg-error "'\\\\o\\{' not terminated with '\\}' after" } */ --- gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-4.c.jj 2024-10-14 17:33:21.867325501 +0200 +++ gcc/testsuite/gcc.dg/cpp/c2y-delimited-escape-seq-4.c 2024-10-14 17:58:19.985298584 +0200 @@ -0,0 +1,87 @@ +/* P2290R3 - Delimited escape sequences */ +/* { dg-do compile } */ +/* { dg-require-effective-target wchar } */ +/* { dg-options "-std=c2y -Wc23-c2y-compat -Wno-c++-compat" } */ + +#include +typedef __CHAR16_TYPE__ char16_t; +typedef __CHAR32_TYPE__ char32_t; + +const char32_t *a = U"\u{1234}\u{10fffd}\u{000000000000000000000000000000000000000000000000000000000001234}\u{10FFFD}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char32_t *b = U"\x{1234}\x{10fffd}\x{000000000000000000000000000000000000000000000000000000000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char32_t *c = U"\o{1234}\o{4177775}\o{000000000000000000000000000000000000000000000000000000000000000000000000004177775}";/* { dg-warning "delimited escape sequences are only valid in" } */ +const char16_t *d = u"\u{1234}\u{bFFd}\u{00000000000000000000000000000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char16_t *e = u"\x{1234}\x{BffD}\x{000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char16_t *f = u"\o{1234}\o{137775}\o{000000000000000137775}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const wchar_t *g = L"\u{1234}\u{bFFd}\u{00000000000000000000000000000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const wchar_t *h = L"\x{1234}\x{bFFd}\x{000001234}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const wchar_t *i = L"\o{1234}\o{137775}\o{000000000000000137775}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char *k = "\x{34}\x{000000000000000003D}"; /* { dg-warning "delimited escape sequences are only valid in" } */ +const char *l = "\o{34}\o{000000000000000176}"; /* { dg-warning "delimited escape sequences are only valid in" } */ + +#if U'\u{1234}' != U'\u1234' || U'\u{10fffd}' != U'\U0010FFFD' \ + || U'\x{00000001234}' != U'\x1234' || U'\x{010fffd}' != U'\x10FFFD' \ + || U'\o{1234}' != U'\x29c' || U'\o{004177775}' != U'\x10FFFD' \ + || u'\u{1234}' != u'\u1234' || u'\u{0bffd}' != u'\uBFFD' \ + || u'\x{00000001234}' != u'\x1234' || u'\x{0Bffd}' != u'\x0bFFD' \ + || u'\o{1234}' != u'\x29c' || u'\o{00137775}' != u'\xBFFD' \ + || L'\u{1234}' != L'\u1234' || L'\u{0bffd}' != L'\uBFFD' \ + || L'\x{00000001234}' != L'\x1234' || L'\x{0bffd}' != L'\x0bFFD' \ + || L'\o{1234}' != L'\x29c' || L'\o{00137775}' != L'\xBFFD' \ + || '\x{34}' != '\x034' || '\x{0003d}' != '\x003D' \ + || '\o{34}' != '\x1C' || '\o{176}' != '\x007E' +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +/* { dg-warning "delimited escape sequences are only valid in" "" { target *-*-* } .-11 } */ +#error Bad +#endif + +int +main () +{ + if (a[0] != U'\u1234' || a[0] != U'\u{1234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || a[1] != U'\U0010FFFD' || a[1] != U'\u{000010fFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || a[2] != a[0] + || a[3] != a[1] + || b[0] != U'\x1234' || b[0] != U'\x{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || b[1] != U'\x10FFFD' || b[1] != U'\x{0010fFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || b[2] != b[0] + || c[0] != U'\x29c' || c[0] != U'\o{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || c[1] != U'\x10FFFD' || c[1] != U'\o{4177775}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || c[2] != c[1]) + __builtin_abort (); + if (d[0] != u'\u1234' || d[0] != u'\u{1234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || d[1] != u'\U0000BFFD' || d[1] != u'\u{00000bFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || d[2] != d[0] + || e[0] != u'\x1234' || e[0] != u'\x{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || e[1] != u'\xBFFD' || e[1] != u'\x{00bFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || e[2] != e[0] + || f[0] != u'\x29c' || f[0] != u'\o{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || f[1] != u'\xbFFD' || f[1] != u'\o{137775}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || f[2] != f[1]) + __builtin_abort (); + if (g[0] != L'\u1234' || g[0] != L'\u{1234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || g[1] != L'\U0000BFFD' || g[1] != L'\u{00000bFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || g[2] != g[0] + || h[0] != L'\x1234' || h[0] != L'\x{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || h[1] != L'\xBFFD' || h[1] != L'\x{00bFfD}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || h[2] != h[0] + || i[0] != L'\x29c' || i[0] != L'\o{001234}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || i[1] != L'\xbFFD' || i[1] != L'\o{137775}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || i[2] != i[1]) + __builtin_abort (); + if (k[0] != '\x034' || k[0] != '\x{0034}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || k[1] != '\x3D' || k[1] != '\x{3d}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || l[0] != '\x1c' || l[0] != '\o{0034}' /* { dg-warning "delimited escape sequences are only valid in" } */ + || l[1] != '\x07e' || l[1] != '\o{176}' || l[1] != '\176') /* { dg-warning "delimited escape sequences are only valid in" } */ + __builtin_abort (); + return 0; +} --- gcc/testsuite/gcc.dg/octal-constants-1.c.jj 2024-10-14 18:12:07.413692711 +0200 +++ gcc/testsuite/gcc.dg/octal-constants-1.c 2024-10-14 18:42:45.683885903 +0200 @@ -0,0 +1,311 @@ +/* Test for octal integer constants. */ + +/* Derived from: binary-constants-1.c, by Jakub Jelinek . */ +/* Origin: Joerg Wunsch . */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99" } */ + +#include + +/* Assertion that constant C is of type T. */ +#define ASSERT_CONST_TYPE(C, T) \ + do { \ + typedef T type; \ + typedef type **typepp; \ + typedef __typeof__((C)) ctype; \ + typedef ctype **ctypepp; \ + typepp x = 0; \ + ctypepp y = 0; \ + x = y; \ + y = x; \ + } while (0) + +/* (T *) if E is zero, (void *) otherwise. */ +#define type_if_not(T, E) __typeof__(0 ? (T *)0 : (void *)(E)) + +/* (T *) if E is nonzero, (void *) otherwise. */ +#define type_if(T, E) type_if_not(T, !(E)) + +/* Combine pointer types, all but one (void *). */ +#define type_comb2(T1, T2) __typeof__(0 ? (T1)0 : (T2)0) +#define type_comb3(T1, T2, T3) type_comb2(T1, type_comb2(T2, T3)) +#define type_comb4(T1, T2, T3, T4) \ + type_comb2(T1, type_comb2(T2, type_comb2(T3, T4))) +#define type_comb6(T1, T2, T3, T4, T5, T6) \ + type_comb2(T1, \ + type_comb2(T2, \ + type_comb2(T3, \ + type_comb2(T4, \ + type_comb2(T5, T6))))) + +/* (T1 *) if E1, otherwise (T2 *) if E2. */ +#define first_of2p(T1, E1, T2, E2) type_comb2(type_if(T1, (E1)), \ + type_if(T2, (!(E1) && (E2)))) +/* (T1 *) if E1, otherwise (T2 *) if E2, otherwise (T3 *) if E3. */ +#define first_of3p(T1, E1, T2, E2, T3, E3) \ + type_comb3(type_if(T1, (E1)), \ + type_if(T2, (!(E1) && (E2))), \ + type_if(T3, (!(E1) && !(E2) && (E3)))) +/* (T1 *) if E1, otherwise (T2 *) if E2, otherwise (T3 *) if E3, otherwise + (T4 *) if E4. */ +#define first_of4p(T1, E1, T2, E2, T3, E3, T4, E4) \ + type_comb4(type_if(T1, (E1)), \ + type_if(T2, (!(E1) && (E2))), \ + type_if(T3, (!(E1) && !(E2) && (E3))), \ + type_if(T4, (!(E1) && !(E2) && !(E3) && (E4)))) +/* (T1 *) if E1, otherwise (T2 *) if E2, otherwise (T3 *) if E3, otherwise + (T4 *) if E4, otherwise (T5 *) if E5, otherwise (T6 *) if E6. */ +#define first_of6p(T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6) \ + type_comb6(type_if(T1, (E1)), \ + type_if(T2, (!(E1) && (E2))), \ + type_if(T3, (!(E1) && !(E2) && (E3))), \ + type_if(T4, (!(E1) && !(E2) && !(E3) && (E4))), \ + type_if(T5, (!(E1) && !(E2) && !(E3) && !(E4) && (E5))), \ + type_if(T6, (!(E1) && !(E2) && !(E3) \ + && !(E4) && !(E5) && (E6)))) + +/* Likewise, but return the original type rather than a pointer type. */ +#define first_of2(T1, E1, T2, E2) \ + __typeof__(*((first_of2p(T1, (E1), T2, (E2)))0)) +#define first_of3(T1, E1, T2, E2, T3, E3) \ + __typeof__(*((first_of3p(T1, (E1), T2, (E2), T3, (E3)))0)) +#define first_of4(T1, E1, T2, E2, T3, E3, T4, E4) \ + __typeof__(*((first_of4p(T1, (E1), T2, (E2), T3, (E3), T4, (E4)))0)) +#define first_of6(T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6) \ + __typeof__(*((first_of6p(T1, (E1), T2, (E2), T3, (E3), \ + T4, (E4), T5, (E5), T6, (E6)))0)) + +/* Types of constants according to the C99 rules. */ +#define C99_UNSUF_TYPE(C) \ + first_of6(int, (C) <= INT_MAX, \ + unsigned int, (C) <= UINT_MAX, \ + long int, (C) <= LONG_MAX, \ + unsigned long int, (C) <= ULONG_MAX, \ + long long int, (C) <= LLONG_MAX, \ + unsigned long long int, (C) <= ULLONG_MAX) +#define C99_SUFu_TYPE(C) \ + first_of3(unsigned int, (C) <= UINT_MAX, \ + unsigned long int, (C) <= ULONG_MAX, \ + unsigned long long int, (C) <= ULLONG_MAX) +#define C99_SUFl_TYPE(C) \ + first_of4(long int, (C) <= LONG_MAX, \ + unsigned long int, (C) <= ULONG_MAX, \ + long long int, (C) <= LLONG_MAX, \ + unsigned long long int, (C) <= ULLONG_MAX) +#define C99_SUFul_TYPE(C) \ + first_of2(unsigned long int, (C) <= ULONG_MAX, \ + unsigned long long int, (C) <= ULLONG_MAX) +#define C99_SUFll_TYPE(C) \ + first_of2(long long int, (C) <= LLONG_MAX, \ + unsigned long long int, (C) <= ULLONG_MAX) + +/* Checks that constants have correct type. */ +#define CHECK_UNSUF_TYPE(C) \ + ASSERT_CONST_TYPE((C), C99_UNSUF_TYPE((C))) +#define CHECK_SUFu_TYPE(C) ASSERT_CONST_TYPE((C), C99_SUFu_TYPE((C))) +#define CHECK_SUFl_TYPE(C) \ + ASSERT_CONST_TYPE((C), C99_SUFl_TYPE((C))) +#define CHECK_SUFul_TYPE(C) ASSERT_CONST_TYPE((C), C99_SUFul_TYPE((C))) +#define CHECK_SUFll_TYPE(C) \ + ASSERT_CONST_TYPE((C), C99_SUFll_TYPE((C))) +#define CHECK_SUFull_TYPE(C) ASSERT_CONST_TYPE((C), unsigned long long int) + +/* Check an octal or hexadecimal value, with all suffixes. */ +#define CHECK_CONST(C) \ + CHECK_UNSUF_TYPE(C); \ + CHECK_SUFu_TYPE(C##u); \ + CHECK_SUFu_TYPE(C##U); \ + CHECK_SUFl_TYPE(C##l); \ + CHECK_SUFl_TYPE(C##L); \ + CHECK_SUFul_TYPE(C##ul); \ + CHECK_SUFul_TYPE(C##uL); \ + CHECK_SUFul_TYPE(C##Ul); \ + CHECK_SUFul_TYPE(C##UL); \ + CHECK_SUFll_TYPE(C##ll); \ + CHECK_SUFll_TYPE(C##LL); \ + CHECK_SUFull_TYPE(C##ull); \ + CHECK_SUFull_TYPE(C##uLL); \ + CHECK_SUFull_TYPE(C##Ull); \ + CHECK_SUFull_TYPE(C##ULL); + +#define CHECK_OCT_CONST(C) \ + CHECK_CONST(0o##C); \ + CHECK_CONST(0O##C); + +/* True iff "long long" is at least B bits. This presumes that (B-2)/3 is at + most 63. */ +#define LLONG_AT_LEAST(B) \ + (LLONG_MAX >> ((B)-2)/3 >> ((B)-2)/3 \ + >> ((B)-2 - ((B)-2)/3 - ((B)-2)/3)) + +#define LLONG_HAS_BITS(B) (LLONG_AT_LEAST((B)) && !LLONG_AT_LEAST((B) + 1)) + +#define FOO 0o1307 +#if !FOO +# error "preprocessor does not accept octal constants" +#endif + +void +foo (void) +{ + /* Check all 2^n and 2^n - 1 up to 2^72 - 1. */ + CHECK_OCT_CONST(1); + CHECK_OCT_CONST(2); + CHECK_OCT_CONST(3); + CHECK_OCT_CONST(4); + CHECK_OCT_CONST(7); + CHECK_OCT_CONST(10); + CHECK_OCT_CONST(17); + CHECK_OCT_CONST(20); + CHECK_OCT_CONST(37); + CHECK_OCT_CONST(40); + CHECK_OCT_CONST(77); + CHECK_OCT_CONST(100); + CHECK_OCT_CONST(177); + CHECK_OCT_CONST(200); + CHECK_OCT_CONST(377); + CHECK_OCT_CONST(400); + CHECK_OCT_CONST(777); + CHECK_OCT_CONST(1000); + CHECK_OCT_CONST(1777); + CHECK_OCT_CONST(2000); + CHECK_OCT_CONST(3777); + CHECK_OCT_CONST(4000); + CHECK_OCT_CONST(7777); + CHECK_OCT_CONST(10000); + CHECK_OCT_CONST(17777); + CHECK_OCT_CONST(20000); + CHECK_OCT_CONST(37777); + CHECK_OCT_CONST(40000); + CHECK_OCT_CONST(77777); + CHECK_OCT_CONST(100000); + CHECK_OCT_CONST(177777); + CHECK_OCT_CONST(200000); + CHECK_OCT_CONST(377777); + CHECK_OCT_CONST(400000); + CHECK_OCT_CONST(777777); + CHECK_OCT_CONST(1000000); + CHECK_OCT_CONST(1777777); + CHECK_OCT_CONST(2000000); + CHECK_OCT_CONST(3777777); + CHECK_OCT_CONST(4000000); + CHECK_OCT_CONST(7777777); + CHECK_OCT_CONST(10000000); + CHECK_OCT_CONST(17777777); + CHECK_OCT_CONST(20000000); + CHECK_OCT_CONST(37777777); + CHECK_OCT_CONST(40000000); + CHECK_OCT_CONST(77777777); + CHECK_OCT_CONST(100000000); + CHECK_OCT_CONST(177777777); + CHECK_OCT_CONST(200000000); + CHECK_OCT_CONST(377777777); + CHECK_OCT_CONST(400000000); + CHECK_OCT_CONST(777777777); + CHECK_OCT_CONST(1000000000); + CHECK_OCT_CONST(1777777777); + CHECK_OCT_CONST(2000000000); + CHECK_OCT_CONST(3777777777); + CHECK_OCT_CONST(4000000000); + CHECK_OCT_CONST(7777777777); + CHECK_OCT_CONST(10000000000); + CHECK_OCT_CONST(17777777777); + CHECK_OCT_CONST(20000000000); + CHECK_OCT_CONST(37777777777); + CHECK_OCT_CONST(40000000000); + CHECK_OCT_CONST(77777777777); + CHECK_OCT_CONST(100000000000); + CHECK_OCT_CONST(177777777777); + CHECK_OCT_CONST(200000000000); + CHECK_OCT_CONST(377777777777); + CHECK_OCT_CONST(400000000000); + CHECK_OCT_CONST(777777777777); + CHECK_OCT_CONST(1000000000000); + CHECK_OCT_CONST(1777777777777); + CHECK_OCT_CONST(2000000000000); + CHECK_OCT_CONST(3777777777777); + CHECK_OCT_CONST(4000000000000); + CHECK_OCT_CONST(7777777777777); + CHECK_OCT_CONST(10000000000000); + CHECK_OCT_CONST(17777777777777); + CHECK_OCT_CONST(20000000000000); + CHECK_OCT_CONST(37777777777777); + CHECK_OCT_CONST(40000000000000); + CHECK_OCT_CONST(77777777777777); + CHECK_OCT_CONST(100000000000000); + CHECK_OCT_CONST(177777777777777); + CHECK_OCT_CONST(200000000000000); + CHECK_OCT_CONST(377777777777777); + CHECK_OCT_CONST(400000000000000); + CHECK_OCT_CONST(777777777777777); + CHECK_OCT_CONST(1000000000000000); + CHECK_OCT_CONST(1777777777777777); + CHECK_OCT_CONST(2000000000000000); + CHECK_OCT_CONST(3777777777777777); + CHECK_OCT_CONST(4000000000000000); + CHECK_OCT_CONST(7777777777777777); + CHECK_OCT_CONST(10000000000000000); + CHECK_OCT_CONST(17777777777777777); + CHECK_OCT_CONST(20000000000000000); + CHECK_OCT_CONST(37777777777777777); + CHECK_OCT_CONST(40000000000000000); + CHECK_OCT_CONST(77777777777777777); + CHECK_OCT_CONST(100000000000000000); + CHECK_OCT_CONST(177777777777777777); + CHECK_OCT_CONST(200000000000000000); + CHECK_OCT_CONST(377777777777777777); + CHECK_OCT_CONST(400000000000000000); + CHECK_OCT_CONST(777777777777777777); + CHECK_OCT_CONST(1000000000000000000); + CHECK_OCT_CONST(1777777777777777777); + CHECK_OCT_CONST(2000000000000000000); + CHECK_OCT_CONST(3777777777777777777); + CHECK_OCT_CONST(4000000000000000000); + CHECK_OCT_CONST(7777777777777777777); + CHECK_OCT_CONST(10000000000000000000); + CHECK_OCT_CONST(17777777777777777777); + CHECK_OCT_CONST(20000000000000000000); + CHECK_OCT_CONST(37777777777777777777); + CHECK_OCT_CONST(40000000000000000000); + CHECK_OCT_CONST(77777777777777777777); + CHECK_OCT_CONST(100000000000000000000); + CHECK_OCT_CONST(177777777777777777777); + CHECK_OCT_CONST(200000000000000000000); + CHECK_OCT_CONST(377777777777777777777); + CHECK_OCT_CONST(400000000000000000000); + CHECK_OCT_CONST(777777777777777777777); + CHECK_OCT_CONST(1000000000000000000000); + CHECK_OCT_CONST(1777777777777777777777); +#if LLONG_AT_LEAST(65) + CHECK_OCT_CONST(2000000000000000000000); + CHECK_OCT_CONST(3777777777777777777777); +#endif +#if LLONG_AT_LEAST(66) + CHECK_OCT_CONST(4000000000000000000000); + CHECK_OCT_CONST(7777777777777777777777); +#endif +#if LLONG_AT_LEAST(67) + CHECK_OCT_CONST(10000000000000000000000); + CHECK_OCT_CONST(17777777777777777777777); +#endif +#if LLONG_AT_LEAST(68) + CHECK_OCT_CONST(20000000000000000000000); + CHECK_OCT_CONST(37777777777777777777777); +#endif +#if LLONG_AT_LEAST(69) + CHECK_OCT_CONST(40000000000000000000000); + CHECK_OCT_CONST(77777777777777777777777); +#endif +#if LLONG_AT_LEAST(70) + CHECK_OCT_CONST(100000000000000000000000); + CHECK_OCT_CONST(177777777777777777777777); +#endif +#if LLONG_AT_LEAST(71) + CHECK_OCT_CONST(200000000000000000000000); + CHECK_OCT_CONST(377777777777777777777777); +#endif +#if LLONG_AT_LEAST(72) + CHECK_OCT_CONST(400000000000000000000000); + CHECK_OCT_CONST(777777777777777777777777); +#endif +} --- gcc/testsuite/gcc.dg/octal-constants-2.c.jj 2024-10-14 18:12:33.292329850 +0200 +++ gcc/testsuite/gcc.dg/octal-constants-2.c 2024-10-14 18:44:54.220078934 +0200 @@ -0,0 +1,16 @@ +/* Test for octal integer constants: -pedantic warnings. */ + +/* Origin: Joerg Wunsch . */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic -ftrack-macro-expansion=0" } */ + +#define FOO 0o1307 + +int +foo (void) +{ +#if FOO /* { dg-warning "'0o' prefixed constants are a C2Y feature or GCC extension" } */ + return 23; +#endif + return 0o1307; /* { dg-warning "'0o' prefixed constants are a C2Y feature or GCC extension" } */ +} --- gcc/testsuite/gcc.dg/octal-constants-3.c.jj 2024-10-14 18:12:39.450243502 +0200 +++ gcc/testsuite/gcc.dg/octal-constants-3.c 2024-10-14 18:44:44.115220989 +0200 @@ -0,0 +1,16 @@ +/* Test for octal integer constants: -pedantic-errors. */ + +/* Origin: Joerg Wunsch . */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic-errors -ftrack-macro-expansion=0" } */ + +#define FOO 0o1307 + +int +foo (void) +{ +#if FOO /* { dg-error "'0o' prefixed constants are a C2Y feature or GCC extension" } */ + return 23; +#endif + return 0o1307; /* { dg-error "'0o' prefixed constants are a C2Y feature or GCC extension" } */ +} --- gcc/testsuite/gcc.dg/octal-constants-4.c.jj 2024-10-14 18:12:42.258204132 +0200 +++ gcc/testsuite/gcc.dg/octal-constants-4.c 2024-10-14 18:47:07.455206044 +0200 @@ -0,0 +1,18 @@ +/* Test for octal integer constants: random errors. */ + +/* Origin: Joerg Wunsch . */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99" } */ + +void +foo(void) +{ + double d; + int i; + + d = 0o1307; + d = 0o1307p1; /* { dg-error "invalid suffix 'p1' on integer constant" } */ + d = 0x1307p1; + i = 0oa011; /* { dg-error "invalid suffix 'oa011' on integer constant" } */ + i = 0o118; /* { dg-error "invalid digit '8' in octal constant" } */ +} --- gcc/testsuite/gcc.dg/system-octal-constants-1.c.jj 2024-10-14 18:53:39.686692627 +0200 +++ gcc/testsuite/gcc.dg/system-octal-constants-1.c 2024-10-14 18:54:39.343854054 +0200 @@ -0,0 +1,18 @@ +/* + Origin: Dodji Seketeli + { dg-options "-std=iso9899:1999 -pedantic" } + { dg-do compile } + */ + +#include "system-octal-constants-1.h" + +int +foo (void) +{ +#if OCTAL_INT_CONSTANT_IN_SYSTEM_HEADER /* A octal constant defined + in system header. No + warning. */ + return 23; +#endif + return 0o1307; /* { dg-warning "'0o' prefixed constants are a C2Y feature or GCC extension" } */ +} --- gcc/testsuite/gcc.dg/system-octal-constants-1.h.jj 2024-10-14 18:53:42.600651667 +0200 +++ gcc/testsuite/gcc.dg/system-octal-constants-1.h 2024-10-14 18:55:41.613978752 +0200 @@ -0,0 +1,3 @@ +#pragma GCC system_header + +#define OCTAL_INT_CONSTANT_IN_SYSTEM_HEADER 0o1307