summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2017-02-17 10:44:07 +0000
committerDaniel Jasper <djasper@google.com>2017-02-17 10:44:07 +0000
commit23c2b5ae7e26d1feea4df51438c515ee0e8823fa (patch)
tree931db4b4e513e9dc2f4ec774b0079ba440e47f2a /clang/lib/Format
parenta272fa8fff0674a2435603d5e8e7c095d6095483 (diff)
downloadbcm5719-llvm-23c2b5ae7e26d1feea4df51438c515ee0e8823fa.tar.gz
bcm5719-llvm-23c2b5ae7e26d1feea4df51438c515ee0e8823fa.zip
clang-format: Don't remove existing spaces between identifier and ::.
This can lead to bad behavior with macros that are used to annotate functions (e.g. ALWAYS_INLINE). Before, this: ALWAYS_INLINE ::std::string getName() ... was turned into: ALWAYS_INLINE::std::string getName() ... If it turns out that clang-format is failing to clean up a lot of the existing spaces now, we can add more analyses of the identifier. It should not currently. Cases where clang-format breaks nested name specifiers should be fine as clang-format wraps after the "::". Thus, a line getting longer and then shorter again should lead to the same original code. llvm-svn: 295437
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index ac3c9df5fa6..840fad0c33b 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2343,12 +2343,16 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
if (!Style.SpaceBeforeAssignmentOperators &&
Right.getPrecedence() == prec::Assignment)
return false;
+ if (Right.is(tok::coloncolon) && Left.is(tok::identifier))
+ // Generally don't remove existing spaces between an identifier and "::".
+ // The identifier might actually be a macro name such as ALWAYS_INLINE. If
+ // this turns out to be too lenient, add analysis of the identifier itself.
+ return Right.WhitespaceRange.getBegin() != Right.WhitespaceRange.getEnd();
if (Right.is(tok::coloncolon) && !Left.isOneOf(tok::l_brace, tok::comment))
return (Left.is(TT_TemplateOpener) &&
Style.Standard == FormatStyle::LS_Cpp03) ||
- !(Left.isOneOf(tok::identifier, tok::l_paren, tok::r_paren,
- tok::l_square) ||
- Left.isOneOf(TT_TemplateCloser, TT_TemplateOpener));
+ !(Left.isOneOf(tok::l_paren, tok::r_paren, tok::l_square,
+ TT_TemplateCloser, TT_TemplateOpener));
if ((Left.is(TT_TemplateOpener)) != (Right.is(TT_TemplateCloser)))
return Style.SpacesInAngles;
if ((Right.is(TT_BinaryOperator) && !Left.is(tok::l_paren)) ||
OpenPOWER on IntegriCloud