From patchwork Wed Aug 28 15:11:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1977948 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=FiP+TJok; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Wv7MQ4Gn3z1yXd for ; Thu, 29 Aug 2024 01:17:54 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6AC25385C6C7 for ; Wed, 28 Aug 2024 15:17:52 +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.133.124]) by sourceware.org (Postfix) with ESMTP id 70C9E3858C66 for ; Wed, 28 Aug 2024 15:17:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 70C9E3858C66 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 70C9E3858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724858248; cv=none; b=YepKLi8ao4oWQkIXrhTSfdrFPBbnlkYDeSRaA7tuqDAkGyvzVHTV8K3EJ3D5HFkFg/1HBdWqeTaWacEt8VYzCndf/EpgqHgGkH84yTdswmxj6RS03+Zz8wrh/W9gn0sV+vk4+B2hQ+0QT/XlPJ6luWqFSoR14GcuPU675o+UoQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724858248; c=relaxed/simple; bh=MgI+Jk4ke+wrWheFWWG2Nu6rrEUddJGntwr39UH4bUU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ilZDGAd7FfiKrl20BNWsSuLFIcNlMpWMy7W9PxvF50rFcrVqTKMP4XucvzJQTm8IRHjt7jvfD2GlPPJQ62iVQaCnGKZTXfOzVPN36Rvo4lrD2DcRe06zS2wNI/L9+Kf4Jx6OV7QtD05R6B/UbNF3UI9J6XbFJabD7b2fx6uZnoE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724858237; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YRDH6rQqgjFt7O513rwlsFMorNEUB9RYJ6YxDpPxlSI=; b=FiP+TJokUWLAj+Hk3NXcb6x/dHFz4VPtFBv1dpUIyLZTU5Tvykn04qC2IT2NgQcQY238iJ MrX6ZLuH5j5zsVDqKgXo988CQgZySraP/6CjttekibKTOzA2mKjvjg1OJQMYbSalxrh/TU 7tXafuUe9HRabYE6oe1gXtIINhP8sfc= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-604-NAVUrD_VOK-axc0tQrHKcA-1; Wed, 28 Aug 2024 11:17:16 -0400 X-MC-Unique: NAVUrD_VOK-axc0tQrHKcA-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6c15405f51dso84468256d6.3 for ; Wed, 28 Aug 2024 08:17:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724858235; x=1725463035; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YRDH6rQqgjFt7O513rwlsFMorNEUB9RYJ6YxDpPxlSI=; b=unSL/RJk40i7FwbvMtD4WR9RdT2PQ1/2GJzu57Em8kI4ne/yoA1PiUaGvXRVBE9h4o BLIipTsngBoX2lM7QV7sypqOd5OZO5NlcMsX05hdxFIg/1MrD7IEbUONy8iEeekPUuWC Mexm2XrpjggUcd4BGFoiKv9WmZguB5dPPmi5Tlc9B0lbBGpYZZu7T4LLBKEINzAevW6Q KjuiRP565DP+ykbUBG7JVQ9gQhPJyo5gu4FRVedjeeVtg0LY7Tt2w2UqvTsmsTAOw80Z 83M+L0cur9N5mlUIRfvCLuwhnaJi3MdOo909wYe987FvmSBXVB3sJ3hvlbTCNYobLCZN x5+A== X-Gm-Message-State: AOJu0YyhoOK8DKSRSAjIFUjvUjXQvvfnSmkgtf2Az4HngQmJH+8sA1SM BtTrp/79ojIVowqnOLaD8ypBIizEXp96tdElvGlyVKCDfWBFyIkbqXEf1pkLxbUp10aXYAEchxf Sg0f5TTzo5pPDoMGKOOpI2UoL7AWUluQ8TnGWVt0nnpr5tVI+yjCwD31YiHaLGLu4wWRaKfQs7q 6Vm6To0P2AqSo6tdmyIKhT/V3Ob6eAHVWKCT4= X-Received: by 2002:a05:6214:3990:b0:6b5:a81b:b974 with SMTP id 6a1803df08f44-6c16dc94e0amr199901396d6.7.1724858235076; Wed, 28 Aug 2024 08:17:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEoPucC1vGbr9hp1Ck6aAondi9o76JSjZ68cNIHySZd8H36uLIop+UaFvS+WuSRBYCefQQq9A== X-Received: by 2002:a05:6214:3990:b0:6b5:a81b:b974 with SMTP id 6a1803df08f44-6c16dc94e0amr199900886d6.7.1724858234484; Wed, 28 Aug 2024 08:17:14 -0700 (PDT) Received: from jason-thinkpadp1gen4i.rmtusma.csb (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6c162d49e1asm66292776d6.34.2024.08.28.08.17.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 08:17:13 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Cc: jakub@redhat.com, josmyers@redhat.com Subject: [PATCH RFC] libcpp: adjust pedwarn handling Date: Wed, 28 Aug 2024 11:11:19 -0400 Message-ID: <20240828151712.1744654-1-jason@redhat.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-pc-linux-gnu. Any objections? Should I change all the other instances of if (CPP_PEDANTIC... cpp_error (...CPP_DL_PEDWARN the same way? -- 8< -- Using CPP_W_PEDANTIC lets users suppress these diagnostics with #pragma GCC diagnostic ignored "-Wpedantic". libcpp/ChangeLog: * expr.cc (cpp_classify_number): Use cpp_pedwarning_with_line instead of cpp_error_with_line for pedwarns. gcc/testsuite/ChangeLog: * c-c++-common/pragma-diag-17.c: New test. --- gcc/testsuite/c-c++-common/pragma-diag-17.c | 14 ++++++ libcpp/expr.cc | 53 +++++++++++---------- 2 files changed, 41 insertions(+), 26 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/pragma-diag-17.c base-commit: 4246cf4f18053eeb47cb2a241fffa9a41573916e diff --git a/gcc/testsuite/c-c++-common/pragma-diag-17.c b/gcc/testsuite/c-c++-common/pragma-diag-17.c new file mode 100644 index 00000000000..3a7e09ca982 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pragma-diag-17.c @@ -0,0 +1,14 @@ +/* Test silencing the numeric constant extension pedwarns. */ +/* { dg-additional-options -fext-numeric-literals { target c++ } } */ + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" + +void f() +{ + 2.0j; + 1.0dd; + 1.0d; + 0b0100; + 1.0K; /* { dg-bogus {fixed-point types not supported in C\+\+} "" { xfail c++ } } */ +} /* { dg-error {fixed-point types not supported for this target} "" { target { c && { ! fixed_point } } } .-1 } */ diff --git a/libcpp/expr.cc b/libcpp/expr.cc index 815eb137a99..a7780ab50b7 100644 --- a/libcpp/expr.cc +++ b/libcpp/expr.cc @@ -662,9 +662,9 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token, if (radix == 8) radix = 10; - if (CPP_PEDANTIC (pfile)) - cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0, - "fixed-point constants are a GCC extension"); + cpp_pedwarning_with_line + (pfile, CPP_W_PEDANTIC, virtual_location, 0, + "fixed-point constants are a GCC extension"); goto syntax_ok; } else @@ -766,9 +766,10 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token, /* A suffix for double is a GCC extension via decimal float support. If the suffix also specifies an imaginary value we'll catch that later. */ - if ((result == CPP_N_MEDIUM) && CPP_PEDANTIC (pfile)) - cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0, - "suffix for double constant is a GCC extension"); + if (result == CPP_N_MEDIUM) + cpp_pedwarning_with_line + (pfile, CPP_W_PEDANTIC, virtual_location, 0, + "suffix for double constant is a GCC extension"); /* Radix must be 10 for decimal floats. */ if ((result & CPP_N_DFLOAT) && radix != 10) @@ -779,15 +780,16 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token, return CPP_N_INVALID; } - if ((result & (CPP_N_FRACT | CPP_N_ACCUM)) && CPP_PEDANTIC (pfile)) - cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0, - "fixed-point constants are a GCC extension"); + if (result & (CPP_N_FRACT | CPP_N_ACCUM)) + cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC, virtual_location, 0, + "fixed-point constants are a GCC extension"); if (result & CPP_N_DFLOAT) { - if (CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, dfp_constants)) - cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0, - "decimal float constants are a C23 feature"); + if (!CPP_OPTION (pfile, dfp_constants)) + cpp_pedwarning_with_line + (pfile, CPP_W_PEDANTIC, virtual_location, 0, + "decimal float constants are a C23 feature"); else if (CPP_OPTION (pfile, cpp_warn_c11_c23_compat) > 0) cpp_warning_with_line (pfile, CPP_W_C11_C23_COMPAT, virtual_location, 0, @@ -870,12 +872,12 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token, cpp_warning_with_line (pfile, CPP_W_C11_C23_COMPAT, virtual_location, 0, message); } - else if (CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, true_false)) + else if (!CPP_OPTION (pfile, true_false)) { const char *message = N_("ISO C does not support literal " "% suffixes before C23"); - cpp_error_with_line (pfile, CPP_DL_PEDWARN, virtual_location, 0, - message); + cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC, + virtual_location, 0, message); } } @@ -883,19 +885,18 @@ cpp_classify_number (cpp_reader *pfile, const cpp_token *token, } syntax_ok: - 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 (result & CPP_N_IMAGINARY) + cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC, virtual_location, 0, + "imaginary 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 C23 feature " - "or GCC extension")); + if (!CPP_OPTION (pfile, binary_constants)) + cpp_pedwarning_with_line (pfile, CPP_W_PEDANTIC, virtual_location, 0, + CPP_OPTION (pfile, cplusplus) + ? N_("binary constants are a C++14 feature " + "or GCC extension") + : N_("binary constants are a C23 feature " + "or GCC extension")); else if (CPP_OPTION (pfile, cpp_warn_c11_c23_compat) > 0) cpp_warning_with_line (pfile, CPP_W_C11_C23_COMPAT, virtual_location, 0,