Skip to content

Duplicate and confusing warnings from -Wuninitialized #9998

@chandlerc

Description

@chandlerc
Bugzilla Link 9626
Resolution FIXED
Resolved on Apr 04, 2011 20:08
Version unspecified
OS All
CC @tkremenek

Extended Description

This is partially my fault. =[ But I'm not sure what exactly to do here. I added a special check for -Wuninitialized with self-initialization cases. The recent changes to the CFG-based uninitialized checker now warn for the same construct, resulting in this:

% cat x.cc
void test() {
int x = x + 42;
(void)x;
}

% ./bin/clang -fsyntax-only -Wuninitialized x.cc
x.cc:2:11: warning: variable 'x' is uninitialized when used within its own initialization [-Wuninitialized]
int x = x + 42;
~ ^
x.cc:2:11: warning: variable 'x' is possibly uninitialized when used here [-Wuninitialized]
int x = x + 42;
^
x.cc:2:3: note: variable 'x' is declared here
int x = x + 42;
^
x.cc:2:17: note: add initialization to silence this warning
int x = x + 42;
^
= 0
2 warnings generated.

At the very least we shouldn't generate two warnings here, but more-over:

  • The first is much more concise
  • The declaration note is general unhelpful when warning on the initializer
  • The fixit hint is just nuts here. =/

I wonder if we should stick to the custom logic for the initializer case for now? Or is there an easy way to fix these in the CFG?

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzillaclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions