This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Member initialization list warning flag


Hi Anthony,

Would you mind attaching your draft patch to the PR? You could also submit it to gcc-patches with a "[RFC, C++]" note in the subject to get some early feedback on it.

I think Martin Sebor has recently fixed the i(i) case (or improved it).

Cheers,

Manuel.

On 11/12/2015 10:12 PM, Anthony Brandon wrote:
Hi,

I found the code from when I worked on 19808.
With this input:

struct S
{
         int i, j;
         S() : i(j), j(1) {}
};

struct B
{
         int i, j;
         B() : i(j+i), j(j+1) {}
};

struct C
{
         int i, j;
         C() : i(i) {}
};

I get this output:

test.C:4:10: warning: âS::iâ is initialized with uninitialized field
âS::jâ [-Wuninitialized]
   S() : i(j), j(1) {}
           ^

test.C:10:10: warning: âB::iâ is initialized with uninitialized field
âB::jâ [-Wuninitialized]
   B() : i(j+i), j(j+1) {}
           ^

test.C:16:10: warning: âC::iâ is initialized with itself [-Winit-self]
   C() : i(i), j(1) {}
           ^
The main questions I have are what to do in cases like
i(i+j) and the like, or where multiple uninitialized values are used,
or i(i+1) for that matter.


On Tue, Nov 10, 2015 at 12:40 AM, Manuel LÃpez-IbÃÃez
<manuel.lopez-ibanez@manchester.ac.uk> wrote:
On 09/11/15 20:41, Zygmunt Ptak wrote:

Hi,

Is there any param in the gcc which will warn about not initialized
class member from the initialization list?


Unfortunately, no. We do not even warn for:

struct S
{
     int i, j;
     S() : i(j), j(1) {}
}

This is https://gcc.gnu.org/PR19808 and it should be not too difficult to
fix, it just needs someone with enough time and perseverance to fix it.
Anthony Brandon started working on it, but I'm not sure what is the status
now. Of course, anyone is more than welcome to pick it up.

There is also https://gcc.gnu.org/PR2972, which is probably closer to what
you want. The current patch
(https://gcc.gnu.org/ml/gcc-patches/2011-11/msg01068.html) will warn even if
the member is initialized within the constructor. But if this is what you
want, you could try updating the patch to the latest trunk, complete it and
submit it for approval.

Cheers,

Manuel.





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]