From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id 333D63858D1E; Sat, 19 Nov 2022 09:57:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 333D63858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x62a.google.com with SMTP id m22so18458922eji.10; Sat, 19 Nov 2022 01:57:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DUp+BoHYAsCac2uBGwApYmF/KmiK/1axskUEzuKi05I=; b=JTavQtcISiLjnsJmAT8ufvIEho6Q/828FNpTAGVCIul0W3d8nh/Dy8ekFCo4t4SVFZ +CeVa4UmsIcY6LBFKR277K6SVQycQ/JQhApiw1hroUQOnzbg9IVTqb87Hxws3U68nwrf 8K3dSChti4GwtB3HtKxa0OxQYCMF646FfFvsmijkvoJ/CWflXJrSpyK6Gh91l/nvKgA1 VoBpQRErXbzwHSjqLBvVIlCMiUJIc07ES/Xgc5wecfrqEoInz1UdAz51QZGdQMPW7Dja L3l/vQ89xBhTDzl7DIH8kCypbe/Nz842zB+gxvBwwE2EHPU41IgFWzDgaZoCqRp+8zPn HNLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DUp+BoHYAsCac2uBGwApYmF/KmiK/1axskUEzuKi05I=; b=B3GDlw3V+u8ael8haqVKn9sV1hKDHx53S1k3o2OZuRvLqppN7sGnXLKvwUzEPPwarS eInBnC6E6r5RY3uFJRBN21SKgeKSKaTyuZnZXWWYEYYuyd1vYVTQUTQemLXUaoJYprGs 2NNOoYKCxOnZQqTMple7GmRClp3WM9IdbGgVTjCox9esA2ryauQyK1vi470n12QVK0KT aUFWRTfsd9rC4QYGBDI0fhB3d1TzxhpRJxWHezr7/Ggor5tsjjToiMpanylt38YhA9oF FZBUYdQ9ZvUvwhEF8zmZ0JqX8AqpO90uJixhHsj2md9ZH2i2JTBgx3Gfpt8nVdBsddzJ pNdQ== X-Gm-Message-State: ANoB5pk6VBjxMPVC+Wc1HMhS40xP7teaWYx5QIiQ8FMsmTnpHbWYA86Z 3OhlIRPjRi7Z6aR3EsQg/Cs= X-Google-Smtp-Source: AA0mqf75ynJI0VZgWp70BkUKrGvuKW3Hw5ylXnlwbqGDRhG8LtxLTH7DxzsBOiGur0oz2ebW1reuLg== X-Received: by 2002:a17:906:9d16:b0:7ae:c45b:98fb with SMTP id fn22-20020a1709069d1600b007aec45b98fbmr8894407ejc.478.1668851835791; Sat, 19 Nov 2022 01:57:15 -0800 (PST) Received: from nbbrfq ([2001:871:227:81c4:d7ff:3a0e:48da:5fe3]) by smtp.gmail.com with ESMTPSA id jr6-20020a170906514600b0078d21574986sm2696210ejc.203.2022.11.19.01.57.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 01:57:14 -0800 (PST) From: Bernhard Reutner-Fischer X-Google-Original-From: Bernhard Reutner-Fischer Received: from b by nbbrfq with local (Exim 4.96) (envelope-from ) id 1owKb4-000QWG-0Q; Sat, 19 Nov 2022 10:57:14 +0100 To: gcc-patches@gcc.gnu.org Cc: Bernhard Reutner-Fischer , Bernhard Reutner-Fischer , jason@redhat.com Subject: Re: [PATCH 2/5] c++: Set the locus of the function result decl Date: Sat, 19 Nov 2022 10:56:57 +0100 Message-Id: <20221119095657.101929-1-aldot@gcc.gnu.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <3e8757c8-cb16-9446-6953-5d6de9deeb5b@redhat.com> References: <3e8757c8-cb16-9446-6953-5d6de9deeb5b@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Jason! Possible test. An existing test might be to equip the existing warning for bool unsigned double meh(void) {return 0;} with a fix-it hint instead of the brief error: two or more data types in declaration of ‘meh’. Likewise for bool unsigned meh(void) {return 0;} error: ‘unsigned’ specified with ‘bool’ so we wouldn't need a plugin, and it might even be useful? ;) cheers, * g++.dg/plugin/plugin.exp: Add new test. * g++.dg/plugin/result-decl-plugin-test-1.C: New test. * g++.dg/plugin/result-decl-plugin-test-2.C: New test. * g++.dg/plugin/result_decl_plugin.C: New test. --- gcc/testsuite/g++.dg/plugin/plugin.exp | 3 + .../g++.dg/plugin/result-decl-plugin-test-1.C | 28 +++++++++ .../g++.dg/plugin/result-decl-plugin-test-2.C | 61 +++++++++++++++++++ .../g++.dg/plugin/result_decl_plugin.C | 57 +++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 gcc/testsuite/g++.dg/plugin/result-decl-plugin-test-1.C create mode 100644 gcc/testsuite/g++.dg/plugin/result-decl-plugin-test-2.C create mode 100644 gcc/testsuite/g++.dg/plugin/result_decl_plugin.C diff --git a/gcc/testsuite/g++.dg/plugin/plugin.exp b/gcc/testsuite/g++.dg/plugin/plugin.exp index b5fb42fa77a..f2b526b4704 100644 --- a/gcc/testsuite/g++.dg/plugin/plugin.exp +++ b/gcc/testsuite/g++.dg/plugin/plugin.exp @@ -80,6 +80,9 @@ set plugin_test_list [list \ show-template-tree-color-labels.C \ show-template-tree-color-no-elide-type.C } \ { comment_plugin.c comments-1.C } \ + { result_decl_plugin.C \ + result-decl-plugin-test-1.C \ + result-decl-plugin-test-2.C } \ ] foreach plugin_test $plugin_test_list { diff --git a/gcc/testsuite/g++.dg/plugin/result-decl-plugin-test-1.C b/gcc/testsuite/g++.dg/plugin/result-decl-plugin-test-1.C new file mode 100644 index 00000000000..bd323181d70 --- /dev/null +++ b/gcc/testsuite/g++.dg/plugin/result-decl-plugin-test-1.C @@ -0,0 +1,28 @@ +/* Verify that class member functions result decl have the correct location. */ +// { dg-options "-fdiagnostics-generate-patch" } +namespace std { template < typename, typename > struct pair; } +template < typename > struct __mini_vector +{ + int _M_finish; + const + unsigned long + __attribute__((deprecated)) + _M_space_left() + { return _M_finish != 0; } +}; + template class __mini_vector< std::pair< long, long > >; + template class __mini_vector< int >; +#if 0 +{ dg-begin-multiline-output "" } +@@ -5,7 +5,7 @@ template < typename > struct __mini_vect + { + int _M_finish; + const +- unsigned long ++ bool + __attribute__((deprecated)) + _M_space_left() + { return _M_finish != 0; } + +{ dg-end-multiline-output "" } +#endif diff --git a/gcc/testsuite/g++.dg/plugin/result-decl-plugin-test-2.C b/gcc/testsuite/g++.dg/plugin/result-decl-plugin-test-2.C new file mode 100644 index 00000000000..385a7ef482f --- /dev/null +++ b/gcc/testsuite/g++.dg/plugin/result-decl-plugin-test-2.C @@ -0,0 +1,61 @@ +/* Verify that template functions result decl have the correct location. */ +// { dg-options "-fdiagnostics-generate-patch" } +template +int +f() +{ + return 42; +} +int main() +{ + f(); +} +unsigned long long huh(void) +{ + return 1ULL; +} +#if 0 +{ dg-begin-multiline-output "" } +g++.dg/plugin/result-decl-plugin-test-2.C:4:1: warning: Function ‘f’ result location + 4 | int + | ^~~ + | bool +g++.dg/plugin/result-decl-plugin-test-2.C:9:1: warning: Function ‘main’ result location + 9 | int main() + | ^~~ + | bool +g++.dg/plugin/result-decl-plugin-test-2.C:13:28: warning: Function ‘huh’ result location + 13 | unsigned long long huh(void) + | ^ + | bool +g++.dg/plugin/result-decl-plugin-test-2.C: In instantiation of ‘int f() [with T = int]’: +g++.dg/plugin/result-decl-plugin-test-2.C:11:10: required from here +g++.dg/plugin/result-decl-plugin-test-2.C:4:1: warning: Function ‘f’ result location + 4 | int + | ^~~ + | bool +--- g++.dg/plugin/result-decl-plugin-test-2.C ++++ g++.dg/plugin/result-decl-plugin-test-2.C +@@ -1,16 +1,16 @@ + /* Verify that template functions result decl have the correct location. */ + // { dg-options "-fdiagnostics-generate-patch" } + template +-int ++bool + f() + { + return 42; + } +-int main() ++bool main() + { + f(); + } +-unsigned long long huh(void) ++unsigned long long huh(voidbool + { + return 1ULL; + } +{ dg-end-multiline-output "" } +#endif +// Note: f() should not +bbool with an off-by-one for the start 'b' ! diff --git a/gcc/testsuite/g++.dg/plugin/result_decl_plugin.C b/gcc/testsuite/g++.dg/plugin/result_decl_plugin.C new file mode 100644 index 00000000000..40f54a6acfe --- /dev/null +++ b/gcc/testsuite/g++.dg/plugin/result_decl_plugin.C @@ -0,0 +1,57 @@ +/* A plugin example that points at the location of function decl result decl */ +/* This file is part of GCC */ +/* { dg-options "-O" } */ +#include "gcc-plugin.h" +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tree.h" +#include "tree-pass.h" +#include "intl.h" +#include "diagnostic.h" +#include "gcc-rich-location.h" +#include "langhooks.h" +#include "plugin-version.h" + +static struct plugin_info _this_info = { + .version = "1", + .help = "None", +}; +/* Callback function to invoke after GCC finishes a declaration. */ + +static void plugin_finish_decl (void *event_data, void *data) +{ + tree decl = (tree) event_data; + if (!decl || TREE_CODE (decl) != FUNCTION_DECL) + return; + + tree logical_1_t = boolean_type_node; + tree logical_1_n = DECL_NAME (TYPE_NAME (logical_1_t)); + location_t result_loc = DECL_SOURCE_LOCATION (DECL_RESULT (decl)); + gcc_rich_location richloc (result_loc); + richloc.add_fixit_replace (result_loc, IDENTIFIER_POINTER (logical_1_n)); + + warning_at (&richloc, 0, G_("Function %qs result location"), + IDENTIFIER_POINTER (DECL_NAME (decl))); +} + +int +plugin_init (struct plugin_name_args *plugin_info, + struct plugin_gcc_version *version) +{ + if (!plugin_default_version_check (version, &gcc_version)) + { + error(G_("incompatible gcc/plugin versions")); + return 1; + } + + const char *plugin_name = plugin_info->base_name; + + register_callback(plugin_name, PLUGIN_INFO, NULL, &_this_info); + register_callback (plugin_name, PLUGIN_FINISH_PARSE_FUNCTION, + plugin_finish_decl, NULL); + return 0; +} + +/* Announce that we are GPL. */ +int plugin_is_GPL_compatible; -- 2.38.1