Skip to content

Commit 4c312fc

Browse files
committed
Work around GCC 9 rejecting a legitimate pointer comparison in a constexpr context
1 parent f18c0b2 commit 4c312fc

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

include/boost/static_string/config.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,11 @@ using basic_string_view =
286286
#define BOOST_STATIC_STRING_GCC_NESTED_CLASS_WORKAROUND
287287
#endif
288288

289+
// GCC 9 incorrectly rejects the pointer equality comparison in
290+
// ptr_in_range() in constant expressions. GCC 10 and later handle
291+
// it correctly.
292+
#if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ == 9)
293+
#define BOOST_STATIC_STRING_CONSTEXPR_PTR_CMP_BROKEN
294+
#endif
295+
289296
#endif

test/constexpr_tests.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ testConstantEvaluation()
255255
a.replace(a.begin(), a.end(), a.begin(), a.end());
256256
a.replace(a.begin(), a.end(), {'a'});
257257

258-
#ifdef BOOST_STATIC_STRING_IS_CONST_EVAL
258+
#if defined(BOOST_STATIC_STRING_IS_CONST_EVAL) \
259+
&& !defined(BOOST_STATIC_STRING_CONSTEXPR_PTR_CMP_BROKEN)
259260
a.clear();
260261
a.replace(a.begin(), a.end(), "a");
261262
a.replace(a.begin(), a.end(), "a", 1);
@@ -443,7 +444,8 @@ testConstantEvaluation()
443444
a.replace(a.begin(), a.end(), a.begin(), a.end());
444445
a.replace(a.begin(), a.end(), {'a'});
445446

446-
#ifdef BOOST_STATIC_STRING_IS_CONST_EVAL
447+
#if defined(BOOST_STATIC_STRING_IS_CONST_EVAL) \
448+
&& !defined(BOOST_STATIC_STRING_CONSTEXPR_PTR_CMP_BROKEN)
447449
a.clear();
448450
a.replace(a.begin(), a.end(), "a");
449451
a.replace(a.begin(), a.end(), "a", 1);

0 commit comments

Comments
 (0)