[clang] 511868d - [clang-format] [PR45626] SpacesInAngles does not insert or preserve leading space before :: operator
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 30 13:48:15 PDT 2020
Author: mydeveloperday
Date: 2020-04-30T21:47:19+01:00
New Revision: 511868dcf3b9d4fdeb817763165b9a830e9ab9a1
URL: https://github.com/llvm/llvm-project/commit/511868dcf3b9d4fdeb817763165b9a830e9ab9a1
DIFF: https://github.com/llvm/llvm-project/commit/511868dcf3b9d4fdeb817763165b9a830e9ab9a1.diff
LOG: [clang-format] [PR45626] SpacesInAngles does not insert or preserve leading space before :: operator
Summary:
See https://bugs.llvm.org/show_bug.cgi?id=45626
Ensure space between < and ::
(void)static_cast<::std::uint32_t >(1);
Reviewers: krasimir, mitchell-stellar
Reviewed By: krasimir
Subscribers: cfe-commits
Tags: #clang, #clang-format
Differential Revision: https://reviews.llvm.org/D79172
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 7623c8344a32..6671284a4734 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3270,12 +3270,13 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
return Right.WhitespaceRange.getBegin() != Right.WhitespaceRange.getEnd();
if (Right.is(tok::coloncolon) &&
!Left.isOneOf(tok::l_brace, tok::comment, tok::l_paren))
+ // Put a space between < and :: in vector< ::std::string >
return (Left.is(TT_TemplateOpener) &&
- Style.Standard < FormatStyle::LS_Cpp11) ||
+ (Style.Standard < FormatStyle::LS_Cpp11 || Style.SpacesInAngles)) ||
!(Left.isOneOf(tok::l_paren, tok::r_paren, tok::l_square,
- tok::kw___super, TT_TemplateCloser,
- TT_TemplateOpener)) ||
- (Left.is(tok ::l_paren) && Style.SpacesInParentheses);
+ tok::kw___super, TT_TemplateOpener,
+ TT_TemplateCloser)) ||
+ (Left.is(tok::l_paren) && Style.SpacesInParentheses);
if ((Left.is(TT_TemplateOpener)) != (Right.is(TT_TemplateCloser)))
return Style.SpacesInAngles;
// Space before TT_StructuredBindingLSquare.
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 7e9c2083c31d..9fdf2e728472 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8526,6 +8526,20 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
verifyFormat("vector< int > x{ };", SpaceBetweenBraces);
}
+TEST_F(FormatTest, FormatSpacesInAngles) {
+ FormatStyle SpaceInAngles = getLLVMStyle();
+ SpaceInAngles.SpacesInAngles = true;
+ verifyFormat("vector< ::std::string > x1;", SpaceInAngles);
+ verifyFormat("Foo< int, Bar > x2;", SpaceInAngles);
+ verifyFormat("Foo< ::int, ::Bar > x3;", SpaceInAngles);
+
+ SpaceInAngles.SpacesInAngles = false;
+ verifyFormat("vector<::std::string> x4;", SpaceInAngles);
+ verifyFormat("vector<int> x5;", SpaceInAngles);
+ verifyFormat("Foo<int, Bar> x6;", SpaceInAngles);
+ verifyFormat("Foo<::int, ::Bar> x7;", SpaceInAngles);
+}
+
TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
verifyFormat("vector<int> x = {1, 22, 333, 4444, 55555, 666666, 7777777,\n"
" 1, 22, 333, 4444, 55555, 666666, 7777777,\n"
More information about the cfe-commits
mailing list