[clang] [Clang] Don't treat a declaration that declares nothing as an invalid statement (PR #224682)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 28 11:00:02 PDT 2026
================
@@ -231,6 +231,11 @@ StmtResult Parser::ParseStatementOrDeclarationAfterAttributes(
GNUAttrs.Range.getBegin());
} else if (GNUAttrs.Range.getBegin().isValid())
DeclStart = GNUAttrs.Range.getBegin();
+ // A declaration that declares nothing (`int;`) yields no Decl but still
+ // occupies the statement position; unlike a pragma, ParseStatement() must
+ // not skip it.
+ if (!Decl)
+ return Actions.ActOnNullStmt(PrevTokLocation);
----------------
AaronBallman wrote:
> I tried EmptyDecl, but it can't appear inside a function or class today.
`EmptyDecl` would be wrong anyway, that's modeling this: https://eel.is/c++draft/dcl#nt:empty-declaration
> An invalid unnamed decl would make any struct containing `int;`
Ah, that's a good point, drat.
> So I'd like to keep this PR as the crash fix.
@efriedma-quic is there some better way to signal to CodeGen "don't emit code for this AST node?" so that we could keep a declaration AST node?
https://github.com/llvm/llvm-project/pull/224682
More information about the cfe-commits
mailing list