// Handle AttributeMacro, e.g. `if (x) UNLIKELY`.
if (FormatTok->is(TT_AttributeMacro))
nextToken();
- handleCppAttributes();
+ if (FormatTok->is(tok::l_square))
+ handleCppAttributes();
}
bool UnwrappedLineParser::handleCppAttributes() {
// Handle [[likely]] / [[unlikely]] attributes.
- if (FormatTok->is(tok::l_square) && tryToParseSimpleAttribute()) {
- parseSquare();
- return true;
- }
- return false;
+ assert(FormatTok->is(tok::l_square));
+ if (!tryToParseSimpleAttribute())
+ return false;
+ parseSquare();
+ return true;
}
/// Returns whether \c Tok begins a block.
void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
const FormatToken &InitialToken = *FormatTok;
nextToken();
- handleAttributes();
// The actual identifier can be a nested name specifier, and in macros
// it is often token-pasted.
+ // An [[attribute]] can be before the identifier.
while (FormatTok->isOneOf(tok::identifier, tok::coloncolon, tok::hashhash,
tok::kw___attribute, tok::kw___declspec,
- tok::kw_alignas) ||
+ tok::kw_alignas, tok::l_square) ||
((Style.Language == FormatStyle::LK_Java || Style.isJavaScript()) &&
FormatTok->isOneOf(tok::period, tok::comma))) {
if (Style.isJavaScript() &&
continue;
}
}
+ if (FormatTok->is(tok::l_square) && handleCppAttributes())
+ continue;
bool IsNonMacroIdentifier =
FormatTok->is(tok::identifier) &&
FormatTok->TokenText != FormatTok->TokenText.upper();
nextToken();
// We can have macros in between 'class' and the class name.
- if (!IsNonMacroIdentifier) {
- if (FormatTok->is(tok::l_paren)) {
- parseParens();
- }
- }
+ if (!IsNonMacroIdentifier && FormatTok->is(tok::l_paren))
+ parseParens();
}
// Note that parsing away template declarations here leads to incorrectly
auto Tokens = annotate("struct S {};");
EXPECT_EQ(Tokens.size(), 6u) << Tokens;
EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_StructLBrace);
+
+ Tokens = annotate("struct EXPORT_MACRO [[nodiscard]] C { int i; };");
+ EXPECT_EQ(Tokens.size(), 15u) << Tokens;
+ EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_StructLBrace);
+
+ Tokens = annotate("struct [[deprecated]] [[nodiscard]] C { int i; };");
+ EXPECT_EQ(Tokens.size(), 19u) << Tokens;
+ EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_StructLBrace);
}
TEST_F(TokenAnnotatorTest, UnderstandsUnions) {