From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 105685 invoked by alias); 11 Nov 2015 20:07:11 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 105669 invoked by uid 89); 11 Nov 2015 20:07:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qg0-f43.google.com Received: from mail-qg0-f43.google.com (HELO mail-qg0-f43.google.com) (209.85.192.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 11 Nov 2015 20:07:09 +0000 Received: by qgad10 with SMTP id d10so31963491qga.3 for ; Wed, 11 Nov 2015 12:07:07 -0800 (PST) X-Received: by 10.140.46.119 with SMTP id j110mr12844259qga.77.1447272427431; Wed, 11 Nov 2015 12:07:07 -0800 (PST) Received: from [192.168.0.26] (97-124-162-152.hlrn.qwest.net. [97.124.162.152]) by smtp.gmail.com with ESMTPSA id y95sm3213154qgd.27.2015.11.11.12.07.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Nov 2015 12:07:06 -0800 (PST) Message-ID: <56439FE8.4090004@gmail.com> Date: Wed, 11 Nov 2015 20:07:00 -0000 From: Martin Sebor User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Gcc Patch List CC: Jason Merrill Subject: [PATCH] correct -Wself-init diagnostic location Content-Type: multipart/mixed; boundary="------------030900020508070003090201" X-IsSubscribed: yes X-SW-Source: 2015-11/txt/msg01420.txt.bz2 This is a multi-part message in MIME format. --------------030900020508070003090201 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-length: 902 GCC warns for class members that are initialized with themselves, and with c++/64667 fixed, this includes references. Unfortunately, the diagnostic that's printed is inconsistent between pointers and references, and other members. For the first two kinds, it's missing the caret, and for others it points to the ctor rather than to the member-initializer (see bellow). The attached patch fixes it so that all such diagnostics consistently point to the member-initializer, and adds a test to verify gcc does so. Martin struct S { int m; int &r; int *p; S (): m (m), r (r), p (p) { } }; u.cpp: In constructor ‘S::S()’: u.cpp:5:5: warning: ‘S::m’ is initialized with itself [-Winit-self] S (): ^ u.cpp:5:5: warning: ‘S::r’ is initialized with itself [-Winit-self] u.cpp:5:5: warning: ‘S::p’ is initialized with itself [-Winit-self] --------------030900020508070003090201 Content-Type: text/x-patch; name="gcc-68208.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gcc-68208.patch" Content-length: 1531 gcc/cp/ 2015-11-11 Martin Sebor PR c++/68208 * init.c (perform_member_init): Use location of member-initializer in -Wself-init rather than that of the ctor. gcc/testsuite/ 2015-11-11 Martin Sebor PR c++/68208 * b/gcc/testsuite/g++.dg/warn/Winit-self-4.C: New test. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 2e11acb..055e9d9 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -638,7 +638,7 @@ perform_member_init (tree member, tree init) val = TREE_OPERAND (val, 0); if (TREE_CODE (val) == COMPONENT_REF && TREE_OPERAND (val, 1) == member && TREE_OPERAND (val, 0) == current_class_ref) - warning_at (DECL_SOURCE_LOCATION (current_function_decl), + warning_at (EXPR_LOC_OR_LOC (val, input_location), OPT_Winit_self, "%qD is initialized with itself", member); } diff --git a/gcc/testsuite/g++.dg/warn/Winit-self-4.C b/gcc/testsuite/g++.dg/warn/Winit-self-4.C new file mode 100644 index 0000000..0e61abf --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Winit-self-4.C @@ -0,0 +1,16 @@ +// PR c++/68208 +// { dg-options "-Winit-self" } + +// Verify that -Winit-self warning issued for reference and pointer +// members points to the member-initializer and not to the constructor. +struct S +{ + int i; + int *p; + int &r; + S (): + i (i), // { dg-warning "initialized with itself" } + p (p), // { dg-warning "initialized with itself" } + r (r) // { dg-warning "initialized with itself" } + { } +}; --------------030900020508070003090201--