Skip to content

Commit 44d9b39

Browse files
authored
Merge pull request #217 from poor-circle/main
ctre::split a string ends with delimiter may cause undefined behavior, can we use std::to_address to fix it?
2 parents b377151 + 2a4d198 commit 44d9b39

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

include/ctre/return_type.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <string>
1010
#include <iterator>
1111
#include <iosfwd>
12+
#include <memory>
1213
#if __has_include(<charconv>)
1314
#include <charconv>
1415
#endif
@@ -71,11 +72,19 @@ template <size_t Id, typename Name = void> struct captured_content {
7172
if constexpr (std::is_same_v<Iterator, utf8_iterator>) {
7273
return _begin.ptr;
7374
} else {
75+
#if __cpp_lib_to_address >= 201711L
76+
return std::to_address(_begin);
77+
#else
7478
return &*_begin;
79+
#endif
7580
}
7681
#else
82+
#if __cpp_lib_to_address >= 201711L
83+
return std::to_address(_begin);
84+
#else
7785
return &*_begin;
7886
#endif
87+
#endif
7988
}
8089

8190
constexpr CTRE_FORCE_INLINE const auto * data() const noexcept {

single-header/ctre-unicode.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ Software.
240240
#include <cstddef>
241241
#include <string_view>
242242
#include <cstdint>
243+
#include <memory>
243244

244245
namespace ctll {
245246

@@ -2978,11 +2979,19 @@ template <size_t Id, typename Name = void> struct captured_content {
29782979
if constexpr (std::is_same_v<Iterator, utf8_iterator>) {
29792980
return _begin.ptr;
29802981
} else {
2982+
#if __cpp_lib_to_address >= 201711L
2983+
return std::to_address(_begin);
2984+
#else
29812985
return &*_begin;
2986+
#endif
29822987
}
29832988
#else
2989+
#if __cpp_lib_to_address >= 201711L
2990+
return std::to_address(_begin);
2991+
#else
29842992
return &*_begin;
29852993
#endif
2994+
#endif
29862995
}
29872996

29882997
constexpr CTRE_FORCE_INLINE const auto * data() const noexcept {

single-header/ctre.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ Software.
237237
#include <cstddef>
238238
#include <string_view>
239239
#include <cstdint>
240+
#include <memory>
240241

241242
namespace ctll {
242243

@@ -2975,11 +2976,19 @@ template <size_t Id, typename Name = void> struct captured_content {
29752976
if constexpr (std::is_same_v<Iterator, utf8_iterator>) {
29762977
return _begin.ptr;
29772978
} else {
2979+
#if __cpp_lib_to_address >= 201711L
2980+
return std::to_address(_begin);
2981+
#else
29782982
return &*_begin;
2983+
#endif
29792984
}
29802985
#else
2986+
#if __cpp_lib_to_address >= 201711L
2987+
return std::to_address(_begin);
2988+
#else
29812989
return &*_begin;
29822990
#endif
2991+
#endif
29832992
}
29842993

29852994
constexpr CTRE_FORCE_INLINE const auto * data() const noexcept {

0 commit comments

Comments
 (0)