Fix -Wimplicit-fallthrough for Clang.

WUFFS_BASE__FALLTHROUGH was not defined because the generated output is
C (so __cplusplus is never defined) and Clang was explicitly excluded
from the __attribute__ case (though it would have worked).

Instead test for the availability of the fallthrough attribute directly,
which should be more portable.

Bug: chromium:995993
This commit is contained in:
Peter Kasting committed 2021-06-26 17:12:56 -07:00
1 parent b2b8961126
commit c90cc7b657
3 files changed
+19 -11

No files matched your search

+8 -4
View File
@@ -10061,14 +10061,18 @@ extern "C" {
// Denote intentional fallthroughs for -Wimplicit-fallthrough.
//
// The order matters here. Clang also defines "__GNUC__".
#if defined(__clang__) && defined(__cplusplus) && (__cplusplus >= 201103L)
#define WUFFS_BASE__FALLTHROUGH [[clang::fallthrough]]
#elif !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 7)
// As noted on
// https:// gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html ,
// combining the two tests in one conditional would not be portable.
#if defined __has_attribute
#if __has_attribute(fallthrough)
#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))
#else
#define WUFFS_BASE__FALLTHROUGH
#endif
#else
#define WUFFS_BASE__FALLTHROUGH
#endif
// Use switch cases for coroutine suspension points, similar to the technique
// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html