diff options
author | Matt Beaumont-Gay <matthewbg@google.com> | 2011-10-19 18:53:03 +0000 |
---|---|---|
committer | Matt Beaumont-Gay <matthewbg@google.com> | 2011-10-19 18:53:03 +0000 |
commit | 0d381810da19dd7677b9a79fca516d298fa5addb (patch) | |
tree | 1474f30a05a13b053a81eff64f667c64343eae7d /lib/Sema/AnalysisBasedWarnings.cpp | |
parent | 83da2e711902c4c54f5601c9000d646dfff06aea (diff) |
Only warn at self-initialization if some later use is always uninitialized.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142538 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/AnalysisBasedWarnings.cpp')
-rw-r--r-- | lib/Sema/AnalysisBasedWarnings.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index babb8af18b..a8ee0b8617 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -586,9 +586,10 @@ public: // Specially handle the case where we have uses of an uninitialized // variable, but the root cause is an idiomatic self-init. We want // to report the diagnostic at the self-init since that is the root cause. - if (!vec->empty() && hasSelfInit) + if (!vec->empty() && hasSelfInit && hasAlwaysUninitializedUse(vec)) DiagnoseUninitializedUse(S, vd, vd->getInit()->IgnoreParenCasts(), - true, /* alwaysReportSelfInit */ true); + /* isAlwaysUninit */ true, + /* alwaysReportSelfInit */ true); else { // Sort the uses by their SourceLocations. While not strictly // guaranteed to produce them in line/column order, this will provide @@ -610,6 +611,16 @@ public: } delete uses; } + +private: + static bool hasAlwaysUninitializedUse(const UsesVec* vec) { + for (UsesVec::const_iterator i = vec->begin(), e = vec->end(); i != e; ++i) { + if (i->second) { + return true; + } + } + return false; +} }; } |