@@ -3882,6 +3882,9 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
38823882 const FormatToken &InitialToken = *FormatTok;
38833883 nextToken ();
38843884
3885+ auto IsNonMacroIdentifier = [](const FormatToken *Tok) {
3886+ return Tok->is (tok::identifier) && Tok->TokenText != Tok->TokenText .upper ();
3887+ };
38853888 // The actual identifier can be a nested name specifier, and in macros
38863889 // it is often token-pasted.
38873890 // An [[attribute]] can be before the identifier.
@@ -3903,27 +3906,26 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
39033906 }
39043907 if (FormatTok->is (tok::l_square) && handleCppAttributes ())
39053908 continue ;
3906- bool IsNonMacroIdentifier =
3907- FormatTok->is (tok::identifier) &&
3908- FormatTok->TokenText != FormatTok->TokenText .upper ();
39093909 nextToken ();
39103910 // We can have macros in between 'class' and the class name.
3911- if (!IsNonMacroIdentifier && FormatTok->is (tok::l_paren))
3911+ if (!IsNonMacroIdentifier (FormatTok->Previous ) &&
3912+ FormatTok->is (tok::l_paren)) {
39123913 parseParens ();
3914+ }
39133915 }
39143916
3915- // Note that parsing away template declarations here leads to incorrectly
3916- // accepting function declarations as record declarations.
3917- // In general, we cannot solve this problem. Consider:
3918- // class A<int> B() {}
3919- // which can be a function definition or a class definition when B() is a
3920- // macro. If we find enough real-world cases where this is a problem, we
3921- // can parse for the 'template' keyword in the beginning of the statement,
3922- // and thus rule out the record production in case there is no template
3923- // (this would still leave us with an ambiguity between template function
3924- // and class declarations).
39253917 if (FormatTok->isOneOf (tok::colon, tok::less)) {
3918+ int AngleNestingLevel = 0 ;
39263919 do {
3920+ if (FormatTok->is (tok::less))
3921+ ++AngleNestingLevel;
3922+ else if (FormatTok->is (tok::greater))
3923+ --AngleNestingLevel;
3924+
3925+ if (AngleNestingLevel == 0 && FormatTok->is (tok::l_paren) &&
3926+ IsNonMacroIdentifier (FormatTok->Previous )) {
3927+ break ;
3928+ }
39273929 if (FormatTok->is (tok::l_brace)) {
39283930 calculateBraceTypes (/* ExpectClassBody=*/ true );
39293931 if (!tryToParseBracedList ())
0 commit comments