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 <jwakely@redhat.com>

	PR preprocessor/103355

libcpp/ChangeLog:

	* lex.c: Use ATTR_LIKELY instead of [[likely]].
	* system.h (ATTR_LIKELY): Define.
This commit is contained in:
Marek Polacek 2021-11-22 11:29:40 -05:00
parent e888bea238
commit 630686f93f
2 changed files with 11 additions and 1 deletions

View File

@ -1286,7 +1286,7 @@ namespace bidi {
case kind::RTL:
/* These aren't popped by a PDF/PDI. */
break;
[[likely]] case kind::NONE:
ATTR_LIKELY case kind::NONE:
break;
default:
abort ();

View File

@ -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