r187892 - clang-format: Fix corner case in OpenMP pragma formatting.
Daniel Jasper
djasper at google.com
Wed Aug 7 09:29:24 PDT 2013
Author: djasper
Date: Wed Aug 7 11:29:23 2013
New Revision: 187892
URL: http://llvm.org/viewvc/llvm-project?rev=187892&view=rev
Log:
clang-format: Fix corner case in OpenMP pragma formatting.
Before:
#pragma omp reduction( | : var)
After:
#pragma omp reduction(| : var)
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=187892&r1=187891&r2=187892&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Aug 7 11:29:23 2013
@@ -1236,7 +1236,8 @@ bool TokenAnnotator::spaceRequiredBefore
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;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=187892&r1=187891&r2=187892&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Aug 7 11:29:23 2013
@@ -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]))
More information about the cfe-commits
mailing list