summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-05-06 14:53:50 +0000
committerDaniel Jasper <djasper@google.com>2015-05-06 14:53:50 +0000
commit112b50e6b627f4780656a4f62f446848e46197b9 (patch)
treeb7494b63bece885c1f77b09dc1b7c5af3a1e318d /clang/lib/Format/TokenAnnotator.cpp
parente92bf6f14178e24c2be4812ddb772b01995f9c79 (diff)
downloadbcm5719-llvm-112b50e6b627f4780656a4f62f446848e46197b9.tar.gz
bcm5719-llvm-112b50e6b627f4780656a4f62f446848e46197b9.zip
clang-format: Allow ternary expressions inside template parameters if
the template parameters aren't inside an expression context. This fixes llvm.org/PR23270. llvm-svn: 236603
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index be29239c062..793746137a5 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -47,6 +47,11 @@ private:
FormatToken *Left = CurrentToken->Previous;
Left->ParentBracket = Contexts.back().ContextKind;
ScopedContextCreator ContextCreator(*this, tok::less, 10);
+
+ // If this angle is in the context of an expression, we need to be more
+ // hesitant to detect it as opening template parameters.
+ bool InExprContext = Contexts.back().IsExpression;
+
Contexts.back().IsExpression = false;
// If there's a template keyword before the opening angle bracket, this is a
// template parameter, not an argument.
@@ -70,8 +75,8 @@ private:
next();
continue;
}
- if (CurrentToken->isOneOf(tok::r_paren, tok::r_square, tok::r_brace,
- tok::colon, tok::question))
+ if (CurrentToken->isOneOf(tok::r_paren, tok::r_square, tok::r_brace) ||
+ (CurrentToken->isOneOf(tok::colon, tok::question) && InExprContext))
return false;
// If a && or || is found and interpreted as a binary operator, this set
// of angles is likely part of something like "a < b && c > d". If the
OpenPOWER on IntegriCloud