Skip to content

Commit f36a48a

Browse files
committed
[Clang] Repair the functionrParenEndsCast to make incorrect judgments in template variable cases
1 parent db2307d commit f36a48a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ static bool mustBreakAfterAttributes(const FormatToken &Tok,
3838

3939
namespace {
4040

41+
SmallVector<llvm::StringRef, 100> castIdentifiers{"__type_identity_t",
42+
"remove_reference_t"};
43+
4144
/// Returns \c true if the line starts with a token that can start a statement
4245
/// with an initializer.
4346
static bool startsWithInitStatement(const AnnotatedLine &Line) {
@@ -2474,6 +2477,9 @@ class AnnotatingParser {
24742477
Current.getNextNonComment()->isOneOf(tok::comma, tok::r_brace)) {
24752478
Current.setType(TT_StringInConcatenation);
24762479
}
2480+
} else if (Current.is(tok::kw_using)) {
2481+
if (Current.Next->Next->Next->isTypeName(LangOpts))
2482+
castIdentifiers.push_back(Current.Next->TokenText);
24772483
} else if (Current.is(tok::l_paren)) {
24782484
if (lParenStartsCppCast(Current))
24792485
Current.setType(TT_CppCastLParen);
@@ -2831,8 +2837,18 @@ class AnnotatingParser {
28312837
IsQualifiedPointerOrReference(BeforeRParen, LangOpts);
28322838
bool ParensCouldEndDecl =
28332839
AfterRParen->isOneOf(tok::equal, tok::semi, tok::l_brace, tok::greater);
2834-
if (ParensAreType && !ParensCouldEndDecl)
2840+
if (ParensAreType && !ParensCouldEndDecl) {
2841+
if (BeforeRParen->is(TT_TemplateCloser)) {
2842+
auto *Prev = BeforeRParen->MatchingParen->getPreviousNonComment();
2843+
if (Prev) {
2844+
for (auto &name : castIdentifiers)
2845+
if (Prev->TokenText == name)
2846+
return true;
2847+
return false;
2848+
}
2849+
}
28352850
return true;
2851+
}
28362852

28372853
// At this point, we heuristically assume that there are no casts at the
28382854
// start of the line. We assume that we have found most cases where there

0 commit comments

Comments
 (0)