[libcxx-commits] [libcxx] [libcxx] [regex] add `[[__fallthrough__]]` to suppress fallthrough warning (PR #100821)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 16 06:46:13 PDT 2024


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/100821

>From 1f231975f2f6b59375bbe88241e533ec18725aaa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Max=20=F0=9F=91=A8=F0=9F=8F=BD=E2=80=8D=F0=9F=92=BB=20Copl?=
 =?UTF-8?q?an?= <mchcopl at gmail.com>
Date: Fri, 26 Jul 2024 14:56:12 -0700
Subject: [PATCH 1/2] [libcxx][regex] add `[[__fallthrough__]]` to suppress
 fallthrough warning

Summary:
The diff #97926 is stacked on top of this patch because this file
reports an error when enabling `-Wimplicit-fallthrough` in `-Wextra`.

Test plan:

```sh
$ time (mkdir build_runtimes && cd build_runtimes && set -x && CC=../build/bin/clang CXX=../build/bin/clang++ cmake -G Ninja ../runtimes -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RUNTIMES='libcxx;libcxxabi;libunwind'  && ninja && bin/llvm-lit -sv ../libcxx/test/std/re )
```

note: whether I put a `break;` or fallthrough, the tests pass anyways
which is sus.
---
 libcxx/include/regex | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/regex b/libcxx/include/regex
index b8141351213212..17666fe4eaedf6 100644
--- a/libcxx/include/regex
+++ b/libcxx/include/regex
@@ -3921,7 +3921,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_escape(
       if (__hd == -1)
         __throw_regex_error<regex_constants::error_escape>();
       __sum = 16 * __sum + static_cast<unsigned>(__hd);
-      // fallthrough
+      [[__fallthrough__]];
     case 'x':
       ++__first;
       if (__first == __last)

>From 370c6e89eae0ad2b68b0a1eb5f88103d970fa8d2 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Fri, 16 Aug 2024 09:46:00 -0400
Subject: [PATCH 2/2] Use _LIBCPP_FALLTHROUGH

---
 libcxx/include/regex | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/regex b/libcxx/include/regex
index 17666fe4eaedf6..08aebc2266f5de 100644
--- a/libcxx/include/regex
+++ b/libcxx/include/regex
@@ -3921,7 +3921,7 @@ _ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_escape(
       if (__hd == -1)
         __throw_regex_error<regex_constants::error_escape>();
       __sum = 16 * __sum + static_cast<unsigned>(__hd);
-      [[__fallthrough__]];
+      _LIBCPP_FALLTHROUGH();
     case 'x':
       ++__first;
       if (__first == __last)



More information about the libcxx-commits mailing list