diff options
author | Daniel Jasper <djasper@google.com> | 2013-05-15 14:09:55 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-05-15 14:09:55 +0000 |
commit | abca58c9ee1a562f43183bfc02f952cd0418ea4a (patch) | |
tree | 9032cbbfd9748fe24882b082e612af13f33813b9 /clang/lib/Format | |
parent | ca08b076f3784b7bcd9c5e7eeb166a91813267df (diff) | |
download | bcm5719-llvm-abca58c9ee1a562f43183bfc02f952cd0418ea4a.tar.gz bcm5719-llvm-abca58c9ee1a562f43183bfc02f952cd0418ea4a.zip |
Don't put short namespace on a single line.
Before:
namespace abc { class SomeClass; }
namespace def { void someFunction() {} }
After:
namespace abc {
class Def;
}
namespace def {
void someFunction() {}
}
Rationale:
a) Having anything other than forward declaration on the same line
as a namespace looks confusing.
b) Formatting namespace-forward-declaration-combinations different
from other stuff is inconsistent.
c) Wasting vertical space close to such forward declarations really
does not affect readability.
llvm-svn: 181887
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/Format.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 9e882157aa7..9fd8ac6916f 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1348,8 +1348,7 @@ private: if (I + 1 == E || (I + 1)->Type == LT_Invalid) return; - if (I->Last->is(tok::l_brace) && - Style.BreakBeforeBraces == FormatStyle::BS_Attach) { + if (I->Last->is(tok::l_brace)) { tryMergeSimpleBlock(I, E, Limit); } else if (I->First.is(tok::kw_if)) { tryMergeSimpleIf(I, E, Limit); @@ -1402,13 +1401,17 @@ private: void tryMergeSimpleBlock(std::vector<AnnotatedLine>::iterator &I, std::vector<AnnotatedLine>::iterator E, unsigned Limit) { + // No merging if the brace already is on the next line. + if (Style.BreakBeforeBraces != FormatStyle::BS_Attach) + return; + // First, check that the current line allows merging. This is the case if // we're not in a control flow statement and the last token is an opening // brace. AnnotatedLine &Line = *I; if (Line.First.isOneOf(tok::kw_if, tok::kw_while, tok::kw_do, tok::r_brace, tok::kw_else, tok::kw_try, tok::kw_catch, - tok::kw_for, + tok::kw_for, tok::kw_namespace, // This gets rid of all ObjC @ keywords and methods. tok::at, tok::minus, tok::plus)) return; |