[clang] [Clang] prevent incorrect rejection of auto with reordered declaration specifiers in C23 (PR #177865)

Oleksandr Tarasiuk via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 30 04:05:49 PST 2026


================
@@ -4093,7 +4093,26 @@ void Parser::ParseDeclarationSpecifiers(
       break;
     case tok::kw_auto:
       if (getLangOpts().CPlusPlus11 || getLangOpts().C23) {
-        if (isKnownToBeTypeSpecifier(GetLookAheadToken(1))) {
+        auto MayBeTypeSpecifier = [&]() {
+          if (getLangOpts().C23 && DS.hasTypeSpecifier() &&
+              DS.getTypeSpecType() != DeclSpec::TST_auto &&
+              DS.getConstexprSpecifier() == ConstexprSpecKind::Unspecified)
----------------
a-tarasyuk wrote:

What I noticed is that emitting the `previous` diagnostic assumes the specifier was parsed earlier, but that isn’t always guaranteed. Since we don’t verify this when choosing the diagnostic, the result can be misleading. Using a more general `invalid use of '%0' with '%1'` diagnostic may be safer...


https://github.com/llvm/llvm-project/pull/177865


More information about the cfe-commits mailing list