From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4560 invoked by alias); 7 Nov 2011 22:38:30 -0000 Received: (qmail 4477 invoked by uid 22791); 7 Nov 2011 22:38:28 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-fx0-f47.google.com (HELO mail-fx0-f47.google.com) (209.85.161.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 07 Nov 2011 22:38:14 +0000 Received: by faat2 with SMTP id t2so3774841faa.20 for ; Mon, 07 Nov 2011 14:38:13 -0800 (PST) MIME-Version: 1.0 Received: by 10.152.134.77 with SMTP id pi13mr7641881lab.21.1320705493232; Mon, 07 Nov 2011 14:38:13 -0800 (PST) Received: by 10.152.8.162 with HTTP; Mon, 7 Nov 2011 14:38:13 -0800 (PST) In-Reply-To: References: Date: Mon, 07 Nov 2011 22:42:00 -0000 Message-ID: Subject: Re: [patch] c++/2972 warn when ctor-initializer leaves uninitialized data From: Gabriel Dos Reis To: Jonathan Wakely Cc: gcc-patches , Jason Merrill Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes 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 X-SW-Source: 2011-11/txt/msg01089.txt.bz2 On Mon, Nov 7, 2011 at 3:43 PM, Jonathan Wakely wro= te: > This is a new version of my -Wmeminit patch, first posted to PR c++/2972. > > Jason suggested combining the Wmeminit warning with the adjacent > Weffc++ one which I agree with. =A0The advice in the Effective C++ book > actually says not to leave members uninitialized, rather than saying > *all* members must have a mem-initializer (which is just annoying in > many cases if the type has a safe default constructor), and my patch > provides a better check for that by only warning when data is left > uninitialized. > > Unfortunately this doesn't work very well in C++11 mode, as defaulted > constructors don't cause warnings when they should do e.g. > > struct C > { > =A0int i; > =A0C() =3D default; > }; > > This doesn't produce the same warning as C() {} even though that's > what the defaulted constructor is equivalent to. so the defaulted constructor does not initialize C::i? > > I'm posting it for comment and in case anyone else has time to work on it. > > =A0 =A0 =A0 =A0* c-family/c.opt (Wmeminit): Add new option. > =A0 =A0 =A0 =A0* c-family/c-opts.c: Include it in Wecpp > =A0 =A0 =A0 =A0* cp/init.c: Implement Wmeminit. > =A0 =A0 =A0 =A0* doc/invoke.texi: document it. > > =A0 =A0 =A0 =A0* testsuite/g++.dg/warn/Wmeminit.C: New. >