Skip to content

Commit 32adc97

Browse files
committed
Corrected compare() in network::basic_string_view
- the code must check string lengths and not just the smallest common prefix - also, this change requires C++14 as I need two expressions in this constexpr function
1 parent fb4830f commit 32adc97

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ set(CMAKE_VERBOSE_MAKEFILE true)
1919

2020
if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
2121
INCLUDE(CheckCXXCompilerFlag)
22-
CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD11)
22+
CHECK_CXX_COMPILER_FLAG(-std=c++14 HAVE_STD11)
2323

2424
if (HAVE_STD11)
25-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
25+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
2626
else()
27-
message(FATAL_ERROR "No C++ 11 support (Compiler does not define -std=c++11).")
27+
message(FATAL_ERROR "No C++ 11 support (Compiler does not define -std=c++14).")
2828
endif()
2929

3030
if (Uri_FULL_WARNINGS)
@@ -37,7 +37,7 @@ if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
3737

3838
message("C++ Flags: ${CMAKE_CXX_FLAGS} link flags: ${CMAKE_CXX_LINK_FLAGS}")
3939
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
40-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
40+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
4141

4242
if (NOT Uri_DISABLE_LIBCXX)
4343
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")

include/network/string_view.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ class basic_string_view {
161161
}
162162

163163
constexpr int compare(basic_string_view s) const noexcept {
164-
return traits::compare(data(), s.data(), std::min(size(), s.size()));
164+
if (size() != s.size())
165+
return size() < s.size() ? -1 : 1;
166+
return traits::compare(data(), s.data(), size());
165167
}
166168

167169
constexpr int compare(size_type pos1, size_type n1,

0 commit comments

Comments
 (0)