Skip to content

Commit 96a6377

Browse files
committed
Update distance-cpu.h
1 parent 42462e5 commit 96a6377

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/distance-cpu.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@
1515

1616
// Detect builtin bit_cast
1717
#ifndef HAVE_BUILTIN_BIT_CAST
18+
/* Only use __builtin_bit_cast if the compiler has it AND
19+
we're compiling as C++ (GCC 11+) or as a C standard that supports it (C23+). */
1820
#if defined(__has_builtin)
1921
#if __has_builtin(__builtin_bit_cast)
20-
#define HAVE_BUILTIN_BIT_CAST 1
22+
#if defined(__cplusplus) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L)
23+
#define HAVE_BUILTIN_BIT_CAST 1
24+
#endif
2125
#endif
2226
#endif
23-
/* GCC 11+ also has __builtin_bit_cast */
24-
#if !defined(HAVE_BUILTIN_BIT_CAST) && defined(__GNUC__) && !defined(__clang__)
27+
28+
/* GCC note: in GCC 11–13, __builtin_bit_cast exists for C++ but NOT for C. */
29+
#if !defined(HAVE_BUILTIN_BIT_CAST) && defined(__GNUC__) && !defined(__clang__) && defined(__cplusplus)
2530
#if __GNUC__ >= 11
2631
#define HAVE_BUILTIN_BIT_CAST 1
2732
#endif

0 commit comments

Comments
 (0)