[clang-format] Parse restrict as a pointer qualifier

Before: void f() { MACRO(A * restrict a); }
After:  void f() { MACRO(A *restrict a); }

Also check that the __restrict and __restrict__ aliases are handled.

Reviewed By: JakeMerdichAMD

Differential Revision: https://reviews.llvm.org/D86710
This commit is contained in:
Alex Richardson 2020-08-28 11:02:56 +01:00
parent 1908da2658
commit 4f10369564
3 changed files with 6 additions and 1 deletions

View File

@ -2739,6 +2739,7 @@ LangOptions getFormattingLangOpts(const FormatStyle &Style) {
LangOpts.ObjC = 1;
LangOpts.MicrosoftExt = 1; // To get kw___try, kw___finally.
LangOpts.DeclSpecKeyword = 1; // To get __declspec.
LangOpts.C99 = 1; // To get kw_restrict for non-underscore-prefixed restrict.
return LangOpts;
}

View File

@ -1891,7 +1891,8 @@ private:
const FormatToken *NextToken = Tok.getNextNonComment();
if (!NextToken ||
NextToken->isOneOf(tok::arrow, tok::equal, tok::kw_const,
tok::kw_volatile, tok::kw_noexcept) ||
tok::kw_restrict, tok::kw_volatile,
tok::kw_noexcept) ||
(NextToken->is(tok::l_brace) && !NextToken->getNextNonComment()))
return TT_PointerOrReference;

View File

@ -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 *restrict a);");
verifyIndependentOfContext("MACRO(A *__restrict__ a);");
verifyIndependentOfContext("MACRO(A *__restrict a);");
verifyIndependentOfContext("MACRO(A *volatile a);");
verifyIndependentOfContext("MACRO(A *__volatile a);");
verifyIndependentOfContext("MACRO(A *__volatile__ a);");