[PATCH] D133887: [Clang] Support label at end of compound statement

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 19 05:48:29 PDT 2022


aaron.ballman added a comment.

In D133887#3799347 <https://reviews.llvm.org/D133887#3799347>, @Izaron wrote:

> In D133887#3799310 <https://reviews.llvm.org/D133887#3799310>, @aaron.ballman wrote:
>
>> Thank you for working on this! I spotted an issue where we're not quite complete with this implementation work. I pushed up a new test case in https://github.com/llvm/llvm-project/commit/a244194f73788de6dfd6d753ff09be3625613f9f that shows it (and set the C status page back to Partial in case this takes a while to address), but `case` and `default` labels should be accepted the same as any other label at the end of a compound statement.
>>
>> Btw, when working on C standards features, I've started adding test coverage that demonstrates we fully implement the paper into the `clang/test/C/` directory, under the correct standard version. This helps us to track the status of proposals a bit more easily within the code base.
>
> Hi! Thanks for this information! How did you find out that we should accept labels at end of statement in **C**, but not in **C++**? That is not obvious for me unfortunately. If C supports it, why would C++ not support it?

I knew the answer for C off the top of my head, but was still looking up the info for C++. C++ does actually behave the same way:

https://eel.is/c++draft/stmt.label#1 -- `case` and `default` are both a `label`
https://eel.is/c++draft/stmt.block#1.sentence-2 -- all labels at the end of a compound statement are treated as if they are followed by a null statement
https://eel.is/c++draft/stmt.stmt#nt:selection-statement -- a `switch` is followed by a `statement`
https://eel.is/c++draft/stmt.stmt#stmt.pre-1 -- a `compound-statement` is a `statement`

I can fix up the C++ status page as well if you'd like, or I can hold off if you're already working on this, it's up to you!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133887/new/

https://reviews.llvm.org/D133887



More information about the cfe-commits mailing list