[clang] 1908da2 - [clang-format] Parse volatile as a pointer qualifier
Alex Richardson via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 28 03:32:06 PDT 2020
Author: Alex Richardson
Date: 2020-08-28T11:31:47+01:00
New Revision: 1908da2658fc26154e4103a50faeeca804c7c57d
URL: https://github.com/llvm/llvm-project/commit/1908da2658fc26154e4103a50faeeca804c7c57d
DIFF: https://github.com/llvm/llvm-project/commit/1908da2658fc26154e4103a50faeeca804c7c57d.diff
LOG: [clang-format] Parse volatile as a pointer qualifier
Before: void f() { MACRO(A * volatile a); }
After: void f() { MACRO(A *volatile a); }
Also check that the __volatile and __volatile__ aliases are handled.
Reviewed By: JakeMerdichAMD
Differential Revision: https://reviews.llvm.org/D86708
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 11acb597aa40..bcd0bf913ecb 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1891,7 +1891,7 @@ class AnnotatingParser {
const FormatToken *NextToken = Tok.getNextNonComment();
if (!NextToken ||
NextToken->isOneOf(tok::arrow, tok::equal, tok::kw_const,
- tok::kw_noexcept) ||
+ tok::kw_volatile, tok::kw_noexcept) ||
(NextToken->is(tok::l_brace) && !NextToken->getNextNonComment()))
return TT_PointerOrReference;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index dcd9da77a390..7ea00ff33ca0 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8053,6 +8053,9 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyIndependentOfContext("MACRO(auto *a);");
verifyIndependentOfContext("MACRO(const A *a);");
verifyIndependentOfContext("MACRO(A *const a);");
+ verifyIndependentOfContext("MACRO(A *volatile a);");
+ verifyIndependentOfContext("MACRO(A *__volatile a);");
+ verifyIndependentOfContext("MACRO(A *__volatile__ a);");
verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
verifyFormat("void f() { f(float{1}, a * a); }");
// FIXME: Is there a way to make this work?
More information about the cfe-commits
mailing list