diff options
author | Dmitri Gribenko <gribozavr@gmail.com> | 2012-02-14 22:14:32 +0000 |
---|---|---|
committer | Dmitri Gribenko <gribozavr@gmail.com> | 2012-02-14 22:14:32 +0000 |
commit | 625bb569df0c34feec0d52c0ec5215f21ef2e054 (patch) | |
tree | 9f7a16fe5b6215a62dcd9b2cd40f1f6ba9833c1a /include/clang/Sema/ScopeInfo.h | |
parent | 66c40400e7d6272b0cd675ada18dd62c1f0362c7 (diff) |
Generalize -Wempty-body: warn when statement body is empty (closes: PR11329)
* if, switch, range-based for: warn if semicolon is on the same line.
* for, while: warn if semicolon is on the same line and either next
statement is compound statement or next statement has more
indentation.
Replacing the semicolon with {} or moving the semicolon to the next
line will always silence the warning.
Tests from SemaCXX/if-empty-body.cpp merged into SemaCXX/warn-empty-body.cpp.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150515 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Sema/ScopeInfo.h')
-rw-r--r-- | include/clang/Sema/ScopeInfo.h | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/include/clang/Sema/ScopeInfo.h b/include/clang/Sema/ScopeInfo.h index 46b97e7113..2ccb37010c 100644 --- a/include/clang/Sema/ScopeInfo.h +++ b/include/clang/Sema/ScopeInfo.h @@ -32,6 +32,22 @@ class VarDecl; namespace sema { +/// \brief Contains information about the compound statement currently being +/// parsed. +class CompoundScopeInfo { +public: + CompoundScopeInfo() + : HasEmptyLoopBodies(false) { } + + /// \brief Whether this compound stamement contains `for' or `while' loops + /// with empty bodies. + bool HasEmptyLoopBodies; + + void setHasEmptyLoopBodies() { + HasEmptyLoopBodies = true; + } +}; + class PossiblyUnreachableDiag { public: PartialDiagnostic PD; @@ -79,7 +95,11 @@ public: /// block, if there is any chance of applying the named return value /// optimization. SmallVector<ReturnStmt*, 4> Returns; - + + /// \brief The stack of currently active compound stamement scopes in the + /// function. + SmallVector<CompoundScopeInfo, 4> CompoundScopes; + /// \brief A list of PartialDiagnostics created but delayed within the /// current function scope. These diagnostics are vetted for reachability /// prior to being emitted. |