This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] c++/2972 warn when ctor-initializer leaves uninitialized data
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Mon, 7 Nov 2011 16:38:13 -0600
- Subject: Re: [patch] c++/2972 warn when ctor-initializer leaves uninitialized data
- References: <CAH6eHdRE9192yx6QU1GEQviQ5iSz5zUkNuaH8KJcoojmUDZnDQ@mail.gmail.com>
On Mon, Nov 7, 2011 at 3:43 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> 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. ?The 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
> {
> ?int i;
> ?C() = 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.
>
> ? ? ? ?* c-family/c.opt (Wmeminit): Add new option.
> ? ? ? ?* c-family/c-opts.c: Include it in Wecpp
> ? ? ? ?* cp/init.c: Implement Wmeminit.
> ? ? ? ?* doc/invoke.texi: document it.
>
> ? ? ? ?* testsuite/g++.dg/warn/Wmeminit.C: New.
>