summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorPaul Hoad <mydeveloperday@gmail.com>2019-10-04 14:25:20 +0000
committerPaul Hoad <mydeveloperday@gmail.com>2019-10-04 14:25:20 +0000
commitcccf5aa0816648a7bf0ca17be529b69b05ada113 (patch)
tree986b0c7fb55c9ece217562f38fadf52e44c6583e /clang/lib/Format
parentba12cec21f55cae6aaae0b57d08cab0de9358d51 (diff)
downloadbcm5719-llvm-cccf5aa0816648a7bf0ca17be529b69b05ada113.tar.gz
bcm5719-llvm-cccf5aa0816648a7bf0ca17be529b69b05ada113.zip
[clang-format] C++11 braced lists should respect the SpacesInParentheses setting
Summary: According to the clang-format documentation, "Fundamentally, C++11 braced lists are formatted exactly like function calls would be formatted in their place. If the braced list follows a name (e.g. a type or variable name), clang-format formats as if the `{}` were the parentheses of a function call with that name." This patch furthers the treatment of C++11 braced list braces as parentheses by respecting the `SpacesInParentheses` setting. Reviewers: MyDeveloperDay, reuk, owenpan Reviewed By: MyDeveloperDay Subscribers: cfe-commits Tags: #clang-format, #clang Patch By: mitchell-stellar Differential Revision: https://reviews.llvm.org/D68415 llvm-svn: 373751
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 0c417238213..a1073c8d607 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2196,7 +2196,8 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) {
if (Current->is(TT_LineComment)) {
if (Current->Previous->BlockKind == BK_BracedInit &&
Current->Previous->opensScope())
- Current->SpacesRequiredBefore = Style.Cpp11BracedListStyle ? 0 : 1;
+ Current->SpacesRequiredBefore =
+ (Style.Cpp11BracedListStyle && !Style.SpacesInParentheses) ? 0 : 1;
else
Current->SpacesRequiredBefore = Style.SpacesBeforeTrailingComments;
@@ -2520,7 +2521,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
return Left.is(tok::hash);
if (Left.isOneOf(tok::hashhash, tok::hash))
return Right.is(tok::hash);
- if (Left.is(tok::l_paren) && Right.is(tok::r_paren))
+ if ((Left.is(tok::l_paren) && Right.is(tok::r_paren)) ||
+ (Left.is(tok::l_brace) && Left.BlockKind != BK_Block &&
+ Right.is(tok::r_brace) && Right.BlockKind != BK_Block))
return Style.SpaceInEmptyParentheses;
if (Left.is(tok::l_paren) || Right.is(tok::r_paren))
return (Right.is(TT_CastRParen) ||
@@ -2636,7 +2639,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
if ((Left.is(tok::l_brace) && Left.BlockKind != BK_Block) ||
(Right.is(tok::r_brace) && Right.MatchingParen &&
Right.MatchingParen->BlockKind != BK_Block))
- return !Style.Cpp11BracedListStyle;
+ return Style.Cpp11BracedListStyle ? Style.SpacesInParentheses : true;
if (Left.is(TT_BlockComment))
// No whitespace in x(/*foo=*/1), except for JavaScript.
return Style.Language == FormatStyle::LK_JavaScript ||
OpenPOWER on IntegriCloud