================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to