diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -528,6 +528,7 @@ case tok::kw_static_assert: case tok::kw__Atomic: case tok::kw___attribute: + case tok::kw___underlying_type: return true; default: return false; diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -247,7 +247,8 @@ Left->setType(TT_AttributeParen); } else if (PrevNonComment && PrevNonComment->isOneOf(TT_TypenameMacro, tok::kw_decltype, - tok::kw_typeof, tok::kw__Atomic)) { + tok::kw_typeof, tok::kw__Atomic, + tok::kw___underlying_type)) { Left->setType(TT_TypeDeclarationParen); // decltype() and typeof() usually contain expressions. if (PrevNonComment->isOneOf(tok::kw_decltype, tok::kw_typeof)) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -169,6 +169,7 @@ verifyFormat("::ns::SomeFunction(::ns::SomeOtherFunction())"); verifyFormat("static constexpr bool Bar = decltype(bar())::value;"); verifyFormat("static constexpr bool Bar = typeof(bar())::value;"); + verifyFormat("static constexpr bool Bar = __underlying_type(bar())::value;"); verifyFormat("static constexpr bool Bar = _Atomic(bar())::value;"); verifyFormat("bool a = 2 < ::SomeFunction();"); verifyFormat("ALWAYS_INLINE ::std::string getName();"); @@ -7908,6 +7909,7 @@ verifyFormat("[](const decltype(*a) &value) {}"); verifyFormat("[](const typeof(*a) &value) {}"); verifyFormat("[](const _Atomic(a *) &value) {}"); + verifyFormat("[](const __underlying_type(a) &value) {}"); verifyFormat("decltype(a * b) F();"); verifyFormat("typeof(a * b) F();"); verifyFormat("#define MACRO() [](A *a) { return 1; }"); @@ -7977,6 +7979,7 @@ verifyFormat("[](const decltype(*a)* ptr) {}", Left); verifyFormat("[](const typeof(*a)* ptr) {}", Left); verifyFormat("[](const _Atomic(a*)* ptr) {}", Left); + verifyFormat("[](const __underlying_type(a)* ptr) {}", Left); verifyFormat("typedef typeof /*comment*/ (int(int, int))* MyFuncPtr;", Left); verifyFormat("auto x(A&&, B&&, C&&) -> D;", Left); verifyFormat("auto x = [](A&&, B&&, C&&) -> D {};", Left); @@ -8075,6 +8078,7 @@ verifyFormat("decltype(*::std::declval()) void F();"); verifyFormat("typeof(*::std::declval()) void F();"); verifyFormat("_Atomic(*::std::declval()) void F();"); + verifyFormat("__underlying_type(*::std::declval()) void F();"); verifyFormat( "template ::value &&\n" @@ -8101,6 +8105,7 @@ verifyIndependentOfContext("MACRO(_Atomic(A) *a);"); verifyIndependentOfContext("MACRO(decltype(A) *a);"); verifyIndependentOfContext("MACRO(typeof(A) *a);"); + verifyIndependentOfContext("MACRO(__underlying_type(A) *a);"); verifyIndependentOfContext("MACRO(A *const a);"); verifyIndependentOfContext("MACRO(A *restrict a);"); verifyIndependentOfContext("MACRO(A *__restrict__ a);"); @@ -8655,6 +8660,8 @@ "LooooooooooooooooooooooooooooooooooongFunctionDefinition() {}"); verifyFormat("_Atomic(LooooooooooooooooooooooooooooooooooooooooongName)\n" "LooooooooooooooooooooooooooooooooooongFunctionDefinition() {}"); + verifyFormat("__underlying_type(LooooooooooooooooooooooooooooooongName)\n" + "LooooooooooooooooooooooooooooooooooongFunctionDefinition() {}"); verifyFormat("LoooooooooooooooooooooooooooooooooooooooongReturnType\n" "LooooooooooooooooooooooooooongFunctionDeclaration(T... t);"); verifyFormat("LoooooooooooooooooooooooooooooooooooooooongReturnType\n" @@ -11600,6 +11607,7 @@ verifyFormat("auto f(int x) -> decltype(x);", NoSpace); verifyFormat("auto f(int x) -> typeof(x);", NoSpace); verifyFormat("auto f(int x) -> _Atomic(x);", NoSpace); + verifyFormat("auto f(int x) -> __underlying_type(x);", NoSpace); verifyFormat("int f(T x) noexcept(x.create());", NoSpace); verifyFormat("alignas(128) char a[128];", NoSpace); verifyFormat("size_t x = alignof(MyType);", NoSpace); @@ -11650,6 +11658,7 @@ verifyFormat("auto f (int x) -> decltype (x);", Space); verifyFormat("auto f (int x) -> typeof (x);", Space); verifyFormat("auto f (int x) -> _Atomic (x);", Space); + verifyFormat("auto f (int x) -> __underlying_type (x);", Space); verifyFormat("int f (T x) noexcept (x.create ());", Space); verifyFormat("alignas (128) char a[128];", Space); verifyFormat("size_t x = alignof (MyType);", Space); @@ -11704,6 +11713,7 @@ verifyFormat("auto f (int x) -> decltype (x);", SomeSpace); verifyFormat("auto f (int x) -> typeof (x);", SomeSpace); verifyFormat("auto f (int x) -> _Atomic (x);", SomeSpace); + verifyFormat("auto f (int x) -> __underlying_type (x);", SomeSpace); verifyFormat("int f (T x) noexcept (x.create());", SomeSpace); verifyFormat("alignas (128) char a[128];", SomeSpace); verifyFormat("size_t x = alignof (MyType);", SomeSpace); @@ -14960,6 +14970,7 @@ " SomeFunction([](decltype(x), A *a) {});\n" " SomeFunction([](typeof(x), A *a) {});\n" " SomeFunction([](_Atomic(x), A *a) {});\n" + " SomeFunction([](__underlying_type(x), A *a) {});\n" "}"); verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" " [](const aaaaaaaaaa &a) { return a; });");