From 1908da2658fc26154e4103a50faeeca804c7c57d Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Fri, 28 Aug 2020 11:02:51 +0100 Subject: [PATCH] [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 --- clang/lib/Format/TokenAnnotator.cpp | 2 +- clang/unittests/Format/FormatTest.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 11acb59..bcd0bf91 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1891,7 +1891,7 @@ private: 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 dcd9da7..7ea00ff 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? -- 2.7.4