Format */& as binary operator if followed by a unary operator.
This fixes llvm.org/PR14687.
Also fixes segfault for lines starting with * or &.
Before:
a *~b;
*a = 1; // <- this segfaulted
After:
a * ~b;
*a = 1; // no segfault :-)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171396 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index daae94b..574d685 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -28,6 +28,7 @@
CharSourceRange::getCharRange(Start, Start.getLocWithOffset(Length)));
LangOptions LangOpts;
LangOpts.CPlusPlus = 1;
+ LangOpts.CPlusPlus11 = 1;
Lexer Lex(ID, Context.Sources.getBuffer(ID), Context.Sources, LangOpts);
tooling::Replacements Replace =
reformat(Style, Lex, Context.Sources, Ranges);
@@ -676,7 +677,9 @@
verifyFormat("a-- > b;");
verifyFormat("b ? -a : c;");
verifyFormat("n * sizeof char16;");
+ verifyFormat("n * alignof char16;");
verifyFormat("sizeof(char);");
+ verifyFormat("alignof(char);");
verifyFormat("return -1;");
verifyFormat("switch (a) {\n"
@@ -724,6 +727,13 @@
verifyFormat("return a & ~b;");
verifyFormat("f(b ? *c : *d);");
verifyFormat("int a = b ? *c : *d;");
+ verifyFormat("*b = a;");
+ verifyFormat("a * ~b;");
+ verifyFormat("a * !b;");
+ verifyFormat("a * +b;");
+ verifyFormat("a * -b;");
+ verifyFormat("a * ++b;");
+ verifyFormat("a * --b;");
// FIXME: Is this desired for LLVM? Fix if not.
verifyFormat("A<int *> a;");