From 630686f93f0018fa1ef128aa673fddd302cc83e1 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Mon, 22 Nov 2021 11:29:40 -0500 Subject: libcpp: Use [[likely]] conditionally Let's hide [[likely]] behind a macro, to suppress warnings if the compiler doesn't support it. Co-authored-by: Jonathan Wakely PR preprocessor/103355 libcpp/ChangeLog: * lex.c: Use ATTR_LIKELY instead of [[likely]]. * system.h (ATTR_LIKELY): Define. --- libcpp/system.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'libcpp/system.h') diff --git a/libcpp/system.h b/libcpp/system.h index ee5fbe2..f6fc583 100644 --- a/libcpp/system.h +++ b/libcpp/system.h @@ -422,6 +422,16 @@ extern void fancy_abort (const char *, int, const char *) ATTRIBUTE_NORETURN; #define gcc_checking_assert(EXPR) ((void)(0 && (EXPR))) #endif +#ifdef __has_cpp_attribute +# if __has_cpp_attribute(likely) +# define ATTR_LIKELY [[likely]] +# elif __has_cpp_attribute(__likely__) +# define ATTR_LIKELY [[__likely__]] +# else +# define ATTR_LIKELY +# endif +#endif + /* Poison identifiers we do not want to use. */ #if (GCC_VERSION >= 3000) #undef calloc -- cgit v1.1