[clang] [clang][Sema] Preserve the initializer of invalid VarDecls (PR #88645)

Nathan Ridge via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 15 00:14:46 PDT 2024


HighCommander4 wrote:

> I added a new test case. However, the patch currently fails two existing test cases:
> 
> Clang :: Parser/cxx-class.cpp
> Clang :: SemaCXX/cxx1z-init-statement.cpp
> 
> I will leave the PR as a Draft while I investigate these failures.

The latest version of the patch fixes these failures.

I'm slightly uncertain about the change to `JumpDiagnostics.cpp`, whose purpose is to fix the `cxx1z-init-statement.cpp` test failure. 

The affected code looks like this:

```c++
  switch (int x, y = 0; y) { // expected-note 2 {{previous definition is here}}
    case 0:
      int x = 0; // expected-error {{redefinition of 'x'}}
    case 1:
      int y = 0; // expected-error {{redefinition of 'y'}}
  }
```

and without the `JumpDiagnostics.cpp` change, we get an extra diagnostic:

```
error: cannot jump from switch statement to this case label
    5 |     case 1:
      |     ^
note: jump bypasses variable initialization
    4 |       int x = 0; // expected-error {{redefinition of 'x'}}
      |
```

but maybe that's actually fine and we should just update the test to expect this diagnostic instead?

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


More information about the cfe-commits mailing list