[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:00:34 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:

@AaronBallman, thanks for the feedback. The current implementation doesn’t handle auto-ordering. In cases like:

```cpp
void f() {
  constexpr [/*1*/|int|] [|/*2*/auto]] c2 = 0;
}
```

the code path sets the `TypeSpecType` (as a result, diagnostics can differ)

https://github.com/llvm/llvm-project/blob/10afcd405ed44e69c25f7239e94b93e6368a5043/clang/lib/Parse/ParseDecl.cpp#L4103-L4104

instead of 

https://github.com/llvm/llvm-project/blob/10afcd405ed44e69c25f7239e94b93e6368a5043/clang/lib/Parse/ParseDecl.cpp#L4097-L4101

which leads to different diagnostics and, in some cases, odd results. I believe that’s incorrect, so I removed the `DS.getConstexprSpecifier() == ConstexprSpecKind::Unspecified` check. For example, in the following code, the diagnostic should point to `constexpr`, not at `int`:

```cpp
void f() {
  constexpr int auto c2 = 0;
}
```

because this code is accepted
```cpp
void f() {
  int auto c2 = 0;
}
```
WDYT?



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


More information about the cfe-commits mailing list