Skip to content

Commit 0c495ce

Browse files
authored
[clang-format] Handle function decls with MS calling conventions (#143083)
1 parent eed98e1 commit 0c495ce

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,15 @@ class AnnotatingParser {
17691769
Keywords.kw___has_include_next)) {
17701770
parseHasInclude();
17711771
}
1772-
if (Style.isCSharp()) {
1772+
if (IsCpp) {
1773+
if (Next && Next->is(tok::l_paren) && Prev &&
1774+
Prev->isOneOf(tok::kw___cdecl, tok::kw___stdcall,
1775+
tok::kw___fastcall, tok::kw___thiscall,
1776+
tok::kw___regcall, tok::kw___vectorcall)) {
1777+
Tok->setFinalizedType(TT_FunctionDeclarationName);
1778+
Next->setFinalizedType(TT_FunctionDeclarationLParen);
1779+
}
1780+
} else if (Style.isCSharp()) {
17731781
if (Tok->is(Keywords.kw_where) && Next && Next->isNot(tok::l_paren)) {
17741782
Tok->setType(TT_CSharpGenericTypeConstraint);
17751783
parseCSharpGenericTypeConstraint();

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsFunctionDeclarationNames) {
22732273
EXPECT_TOKEN(Tokens[16], tok::l_paren, TT_FunctionDeclarationLParen);
22742274
EXPECT_TOKEN(Tokens[18], tok::arrow, TT_TrailingReturnArrow);
22752275

2276+
Tokens = annotate("void __stdcall f();");
2277+
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
2278+
EXPECT_TOKEN(Tokens[2], tok::identifier, TT_FunctionDeclarationName);
2279+
EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_FunctionDeclarationLParen);
2280+
22762281
Tokens = annotate("int iso_time(time_t);");
22772282
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
22782283
EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);

0 commit comments

Comments
 (0)