clang-format: Fix corner case in OpenMP pragma formatting.

Before:
  #pragma omp reduction( | : var)
After:
  #pragma omp reduction(| : var)

llvm-svn: 187892
This commit is contained in:
Daniel Jasper 2013-08-07 16:29:23 +00:00
parent 54533f73a8
commit 9613c81fd2
2 changed files with 7 additions and 1 deletions

View File

@ -1236,7 +1236,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
if (Tok.isOneOf(tok::arrowstar, tok::periodstar) ||
Tok.Previous->isOneOf(tok::arrowstar, tok::periodstar))
return false;
if (Tok.Type == TT_BinaryOperator || Tok.Previous->Type == TT_BinaryOperator)
if ((Tok.Type == TT_BinaryOperator && !Tok.Previous->is(tok::l_paren)) ||
Tok.Previous->Type == TT_BinaryOperator)
return true;
if (Tok.Previous->Type == TT_TemplateCloser && Tok.is(tok::l_paren))
return false;

View File

@ -5532,6 +5532,11 @@ TEST_F(FormatTest, AllmanBraceBreaking) {
BreakBeforeBrace);
}
TEST_F(FormatTest, UnderstandsPragmas) {
verifyFormat("#pragma omp reduction(| : var)");
verifyFormat("#pragma omp reduction(+ : var)");
}
bool allStylesEqual(ArrayRef<FormatStyle> Styles) {
for (size_t i = 1; i < Styles.size(); ++i)
if (!(Styles[0] == Styles[i]))