From patchwork Fri Nov 13 22:46:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 1400172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CXtr13FKnz9sPB for ; Sat, 14 Nov 2020 09:46:41 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9087739518AA; Fri, 13 Nov 2020 22:46:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 6F2553854802 for ; Fri, 13 Nov 2020 22:46:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6F2553854802 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=joseph_myers@mentor.com IronPort-SDR: eG+oL5mABlYtqDtf98izm0KW4fbuz1lgcLJQolJ7D5eYXXMCqurn1Z+n6jaNoN3ws0NqqcvMqy mylYOmra/ZeXS2Fo7kc5U/7gQpmf4bQefuMkZntHZUXdU6vpEsDB6Pj3ndfjnud68pMJv19CaW fio+Iv0E7W8cVMeeACK3bZWqZpZezjkGsXM+EvOd3t5CU2N3H8o5ZTumDlSK3XlpNOFjZhO7jY 3u7419dnUijsebM4UA0TctxD0JsajWkP34mEDb9Q68v8joOe5n97UNSZzZ43deeXQ8+7/wEDQC tnM= X-IronPort-AV: E=Sophos;i="5.77,476,1596528000"; d="scan'208";a="55085583" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 13 Nov 2020 14:46:35 -0800 IronPort-SDR: cLT92LbnyaeL+GFEuEcAhMyyW6Cp3XfrDxXFnCDcYslwRLXE4sGOBItygJIsrVjxxlfzQ8ol7X Ht0WqqtETc9hCbWSC2LU6qwOYaPwuctqmpRUddTtJNcN3dLDWAJuOgDPB9S6IM7gJ2QxjOv8XD Lt2oJvrHN82XavELC/NmrGL3LG6cVSHv7B8PzxFyBxawqZbOpIF+G9tyPMdAgLAvLVEy52Jdpf riN3ywx8vrUXxsf++cUBXJtk+CfnbV3KFNKmd7cSbdfZkuBsECA+q4/dint9QjBbs3O5HIEggg edU= Date: Fri, 13 Nov 2020 22:46:30 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Subject: c: C2x binary constants Message-ID: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-08.mgc.mentorg.com (139.181.222.8) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-3130.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" C2x adds binary integer constants (approved at the last WG14 meeting, though not yet added to the working draft in git). Configure libcpp to consider these a standard feature in C2x mode, with appropriate updates to diagnostics including support for diagnosing them with -std=c2x -Wc11-c2x-compat. Bootstrapped with no regressions for x86_64-pc-linux-gnu. Applied to mainline. gcc/testsuite/ 2020-11-13 Joseph Myers * gcc.dg/binary-constants-2.c, gcc.dg/binary-constants-3.c, gcc.dg/system-binary-constants-1.c: Update expected diagnostics. * gcc.dg/c11-binary-constants-1.c, gcc.dg/c11-binary-constants-2.c, gcc.dg/c2x-binary-constants-1.c, gcc.dg/c2x-binary-constants-2.c, gcc.dg/c2x-binary-constants-3.c: New tests. libcpp/ 2020-11-13 Joseph Myers * expr.c (cpp_classify_number): Update diagnostic for binary constants for C. Also diagnose binary constants for -Wc11-c2x-compat. * init.c (lang_defaults): Enable binary constants for GNUC2X and STDC2X. diff --git a/gcc/testsuite/gcc.dg/binary-constants-2.c b/gcc/testsuite/gcc.dg/binary-constants-2.c index 6c3928aa2a0..5339d57b991 100644 --- a/gcc/testsuite/gcc.dg/binary-constants-2.c +++ b/gcc/testsuite/gcc.dg/binary-constants-2.c @@ -9,8 +9,8 @@ int foo (void) { -#if FOO /* { dg-warning "binary constants are a GCC extension" } */ +#if FOO /* { dg-warning "binary constants are a C2X feature or GCC extension" } */ return 23; #endif - return 0b1101; /* { dg-warning "binary constants are a GCC extension" } */ + return 0b1101; /* { dg-warning "binary constants are a C2X feature or GCC extension" } */ } diff --git a/gcc/testsuite/gcc.dg/binary-constants-3.c b/gcc/testsuite/gcc.dg/binary-constants-3.c index 410fc4cd725..5b49cb4efbb 100644 --- a/gcc/testsuite/gcc.dg/binary-constants-3.c +++ b/gcc/testsuite/gcc.dg/binary-constants-3.c @@ -9,8 +9,8 @@ int foo (void) { -#if FOO /* { dg-error "binary constants are a GCC extension" } */ +#if FOO /* { dg-error "binary constants are a C2X feature or GCC extension" } */ return 23; #endif - return 0b1101; /* { dg-error "binary constants are a GCC extension" } */ + return 0b1101; /* { dg-error "binary constants are a C2X feature or GCC extension" } */ } diff --git a/gcc/testsuite/gcc.dg/c11-binary-constants-1.c b/gcc/testsuite/gcc.dg/c11-binary-constants-1.c new file mode 100644 index 00000000000..fdc7df4bfad --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-binary-constants-1.c @@ -0,0 +1,11 @@ +/* Test that binary constants are diagnosed in C11 mode: -pedantic. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11 -pedantic" } */ + +int a = 0b1; /* { dg-warning "binary constants" } */ +#if 0b101 /* { dg-warning "binary constants" } */ +#endif + +int b = 0B1; /* { dg-warning "binary constants" } */ +#if 0B101 /* { dg-warning "binary constants" } */ +#endif diff --git a/gcc/testsuite/gcc.dg/c11-binary-constants-2.c b/gcc/testsuite/gcc.dg/c11-binary-constants-2.c new file mode 100644 index 00000000000..6b48a5d005b --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-binary-constants-2.c @@ -0,0 +1,11 @@ +/* Test that binary constants are diagnosed in C11 mode: -pedantic-errors. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +int a = 0b1; /* { dg-error "binary constants" } */ +#if 0b101 /* { dg-error "binary constants" } */ +#endif + +int b = 0B1; /* { dg-error "binary constants" } */ +#if 0B101 /* { dg-error "binary constants" } */ +#endif diff --git a/gcc/testsuite/gcc.dg/c2x-binary-constants-1.c b/gcc/testsuite/gcc.dg/c2x-binary-constants-1.c new file mode 100644 index 00000000000..bbb2bc842c9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-binary-constants-1.c @@ -0,0 +1,5 @@ +/* Test C2x binary constants. Valid syntax and types. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +#include "binary-constants-1.c" diff --git a/gcc/testsuite/gcc.dg/c2x-binary-constants-2.c b/gcc/testsuite/gcc.dg/c2x-binary-constants-2.c new file mode 100644 index 00000000000..4379427d6ce --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-binary-constants-2.c @@ -0,0 +1,11 @@ +/* Test that binary constants are accepted in C2X mode: compat warnings. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -Wc11-c2x-compat" } */ + +int a = 0b1; /* { dg-warning "C2X feature" } */ +#if 0b101 /* { dg-warning "C2X feature" } */ +#endif + +int b = 0B1; /* { dg-warning "C2X feature" } */ +#if 0B101 /* { dg-warning "C2X feature" } */ +#endif diff --git a/gcc/testsuite/gcc.dg/c2x-binary-constants-3.c b/gcc/testsuite/gcc.dg/c2x-binary-constants-3.c new file mode 100644 index 00000000000..7604791fa85 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-binary-constants-3.c @@ -0,0 +1,9 @@ +/* Test C2x binary constants. Invalid constants. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +int a = 0b; /* { dg-error "invalid suffix" } */ +int b = 0B2; /* { dg-error "invalid suffix" } */ +int c = 0B02; /* { dg-error "invalid digit" } */ +int d = 0b1.1; /* { dg-error "invalid prefix" } */ +int e = 0B0p0; /* { dg-error "invalid suffix" } */ diff --git a/gcc/testsuite/gcc.dg/system-binary-constants-1.c b/gcc/testsuite/gcc.dg/system-binary-constants-1.c index 921ee208635..ca162154fbe 100644 --- a/gcc/testsuite/gcc.dg/system-binary-constants-1.c +++ b/gcc/testsuite/gcc.dg/system-binary-constants-1.c @@ -14,5 +14,5 @@ foo (void) warning. */ return 23; #endif - return 0b1101; /* { dg-warning "binary constants are a GCC extension" } */ + return 0b1101; /* { dg-warning "binary constants are a C2X feature or GCC extension" } */ } diff --git a/libcpp/expr.c b/libcpp/expr.c index e01a47a8c34..b98c0386eb5 100644 --- a/libcpp/expr.c +++ b/libcpp/expr.c @@ -812,14 +812,21 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token, if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile)) cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0, "imaginary constants are a GCC extension"); - if (radix == 2 - && !CPP_OPTION (pfile, binary_constants) - && CPP_PEDANTIC (pfile)) - cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0, - CPP_OPTION (pfile, cplusplus) - ? N_("binary constants are a C++14 feature " - "or GCC extension") - : N_("binary constants are a GCC extension")); + if (radix == 2) + { + if (!CPP_OPTION (pfile, binary_constants) + && CPP_PEDANTIC (pfile)) + cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0, + CPP_OPTION (pfile, cplusplus) + ? N_("binary constants are a C++14 feature " + "or GCC extension") + : N_("binary constants are a C2X feature " + "or GCC extension")); + else if (CPP_OPTION (pfile, cpp_warn_c11_c2x_compat) > 0) + cpp_warning_with_line (pfile, CPP_W_C11_C2X_COMPAT, + virtual_location, 0, + "binary constants are a C2X feature"); + } if (radix == 10) result |= CPP_N_DECIMAL; diff --git a/libcpp/init.c b/libcpp/init.c index 1b43802c29c..76882bc5f1c 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -102,13 +102,13 @@ static const struct lang_flags lang_defaults[] = /* GNUC99 */ { 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0 }, /* GNUC11 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0 }, /* GNUC17 */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0 }, - /* GNUC2X */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1 }, + /* GNUC2X */ { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1 }, /* STDC89 */ { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, /* STDC94 */ { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, /* STDC99 */ { 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, /* STDC11 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, /* STDC17 */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }, - /* STDC2X */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1 }, + /* STDC2X */ { 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1 }, /* GNUCXX */ { 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0 }, /* CXX98 */ { 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0 }, /* GNUCXX11 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0 },