[clang] [clang][Parser] Allow private type aliases in out-of-line member function return types (PR #169272)
Vassil Vassilev via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 28 03:06:28 PST 2025
================
@@ -61,8 +61,26 @@ bool Parser::isCXXDeclarationStatement(
// token is also an identifier and assume a declaration.
// We cannot check if the scopes match because the declarations could
// involve namespaces and friend declarations.
- if (NextToken().is(tok::identifier))
+ //
+ // Also handle cases like "A::B *foo" or "A::B &foo" where the type
+ // is followed by ptr/ref declarator operators. These patterns are
+ // very likely to be declarations (e.g., out-of-line member function
+ // definitions with pointer/reference return types).
+ Token Next = NextToken();
+ if (Next.is(tok::identifier))
return true;
+ // Check for pointer/reference patterns: A::B *id, A::B &id, A::B &&id
+ // Also handles multiple indirections like A::B **id
+ if (Next.isOneOf(tok::star, tok::amp, tok::ampamp)) {
+ // Look ahead to see if there's an identifier after ptr/ref ops
+ RevertingTentativeParsingAction PA(*this);
+ ConsumeToken(); // consume the identifier (type name)
+ // Skip all consecutive *, &, && tokens (for cases like A::B **)
+ while (Tok.isOneOf(tok::star, tok::amp, tok::ampamp))
----------------
vgvassilev wrote:
I presume the c++ scope specifier has been parsed already. In this case we should call a parser function rather than implementing some parsing by ourselves. You can trace what clang does for out-of-line definitions after calling `ParseOptionalCXXScopeSpecifier`. We should do the same and if that fails we know that this is not a declaration, more parsing will be required otherwise.
https://github.com/llvm/llvm-project/pull/169272
More information about the cfe-commits
mailing list