New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 822097 link

Starred by 2 users

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Chrome
Pri: 3
Type: Bug



Sign in to add a comment

Add a warning when a non-POD class has an uninitialized field

Project Member Reported by dcheng@chromium.org, Mar 15 2018

Issue description

This is something that's come up a number of times: a new POD field is added, but not all the constructors initialize it.

A simple heuristic which should hopefully work is:
If a class is a non-POD, for each constructor, emit a warning for each POD field which does not have an initializer (either in-class or in the initializer list).

I asked about putting a warning like this in clang, and support was lukewarm: in particular, there was concern that this warning would force pointless initialization of large arrays. For now, maybe we can prototype it as a plugin warning.
 

Comment 1 by thakis@chromium.org, Mar 15 2018

There's been lots of design work for this on an internal bug a few years ago (searching b for "thakis eisinger chandlerc" might find it), and some prototyping. The biggest issue is false positives. One good idea was to add an explicit __uninit that classes that intentionally don't want to init fields would use to "initialize" the uninitialized fields.

Comment 2 by dcheng@chromium.org, Mar 15 2018

Ah indeed: I found the internal bug, and found that there's issue 587624 for copy constructors as well. I'll keep this separate, since it's a slightly different, but I'll drop a link to this bug in that one as well.

Sign in to add a comment