[clang] d304360 - [clang-format] Parse nullability attributes as a pointer qualifier
Alex Richardson via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 28 03:32:11 PDT 2020
Author: Alex Richardson
Date: 2020-08-28T11:31:47+01:00
New Revision: d304360decefae3fa5c807a8cd0d7d4501a1cc4b
URL: https://github.com/llvm/llvm-project/commit/d304360decefae3fa5c807a8cd0d7d4501a1cc4b
DIFF: https://github.com/llvm/llvm-project/commit/d304360decefae3fa5c807a8cd0d7d4501a1cc4b.diff
LOG: [clang-format] Parse nullability attributes as a pointer qualifier
Before:
void f() { MACRO(A * _Nonnull a); }
void f() { MACRO(A * _Nullable a); }
void f() { MACRO(A * _Null_unspecified a); }
After:
void f() { MACRO(A *_Nonnull a); }
void f() { MACRO(A *_Nullable a); }
void f() { MACRO(A *_Null_unspecified a); }
Reviewed By: JakeMerdichAMD
Differential Revision: https://reviews.llvm.org/D86713
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 e5c0a7cb033c..3e25ef6b9774 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1890,9 +1890,10 @@ class AnnotatingParser {
const FormatToken *NextToken = Tok.getNextNonComment();
if (!NextToken ||
- NextToken->isOneOf(tok::arrow, tok::equal, tok::kw_const,
- tok::kw_restrict, tok::kw_volatile,
- tok::kw___attribute, tok::kw_noexcept) ||
+ NextToken->isOneOf(
+ tok::arrow, tok::equal, tok::kw_const, tok::kw_restrict,
+ tok::kw_volatile, tok::kw___attribute, tok::kw__Nonnull,
+ tok::kw__Nullable, tok::kw__Null_unspecified, 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 1234462a47ec..7e505c2401e9 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8025,6 +8025,10 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyFormat("vector<int *const> v;");
verifyFormat("vector<int *const **const *> v;");
verifyFormat("vector<int *volatile> v;");
+ verifyFormat("vector<a *_Nonnull> v;");
+ verifyFormat("vector<a *_Nullable> v;");
+ verifyFormat("vector<a *_Null_unspecified> v;");
+ verifyFormat("vector<a * _NotAQualifier> v;");
verifyFormat("vector<a * b> v;");
verifyFormat("foo<b && false>();");
verifyFormat("foo<b & 1>();");
@@ -8059,6 +8063,9 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyIndependentOfContext("MACRO(A *volatile a);");
verifyIndependentOfContext("MACRO(A *__volatile a);");
verifyIndependentOfContext("MACRO(A *__volatile__ a);");
+ verifyIndependentOfContext("MACRO(A *_Nonnull a);");
+ verifyIndependentOfContext("MACRO(A *_Nullable a);");
+ verifyIndependentOfContext("MACRO(A *_Null_unspecified a);");
verifyIndependentOfContext("MACRO(A *__attribute__((foo)) a);");
verifyIndependentOfContext("MACRO(A *__attribute((foo)) a);");
verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
More information about the cfe-commits
mailing list