[clang-format] Fix build on gcc < 7 introduced in rG9363aa9.
authorMarek Kurdej <marek.kurdej+llvm.org@gmail.com>
Thu, 29 Apr 2021 07:56:11 +0000 (09:56 +0200)
committerMarek Kurdej <marek.kurdej+llvm.org@gmail.com>
Thu, 29 Apr 2021 07:57:34 +0000 (09:57 +0200)
This fixes a bogus build error on gcc, e.g. https://lab.llvm.org/buildbot/#/builders/110/builds/2973.

/home/ssglocal/clang-cmake-x86_64-avx2-linux/clang-cmake-x86_64-avx2-linux/llvm/clang/lib/Format/TokenAnnotator.cpp:3097:53: error: binding ‘const clang::SourceRange’ to reference of type ‘clang::SourceRange&’ discards qualifiers
   auto HasExistingWhitespace = [&Whitespace = Right.WhitespaceRange]() {
                                                     ^

clang/lib/Format/TokenAnnotator.cpp

index f20640a..3fe62bc 100755 (executable)
@@ -3094,8 +3094,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
 bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
                                          const FormatToken &Right) {
   const FormatToken &Left = *Right.Previous;
-  auto HasExistingWhitespace = [&Whitespace = Right.WhitespaceRange]() {
-    return Whitespace.getBegin() != Whitespace.getEnd();
+  auto HasExistingWhitespace = [&Right]() {
+    return Right.WhitespaceRange.getBegin() != Right.WhitespaceRange.getEnd();
   };
   if (Right.Tok.getIdentifierInfo() && Left.Tok.getIdentifierInfo())
     return true; // Never ever merge two identifiers.