When I load the following original boost beast 1.84.0 server example into my IDE QT Creator 13.0 (C++20), I get the following warning with clang-tools 17.0.1. How can I fix/work around this and is this a bug/warning in the boost library/example that will be fixed?
Example: https://www.boost.org/doc/libs/1_84_0/libs/beast/example/advanced/server/
Warning in Line 167 in original example file (my line is different in 161):
Compiler-Call (cmake generated) (Ubuntu 13.2.0-4ubuntu3):
/usr/bin/x86_64-linux-gnu-g++-13 -DBOOST_SYSTEM_NO_LIB -DBOOST_THREAD_NO_LIB -isystem /home/xxx/projects_cpp/boost_beast_server/extlibs/boost/include -O3 -DNDEBUG -std=c++20 -fdiagnostics-color=always -Wall -Wextra -Wconversion -Wsign-conversion -Wfloat-equal -Wunreachable-code -Wunused-variable -Wshadow -Wcast-align -Werror -MD -MT CMakeFiles/BoostBeastServer.dir/main.cpp.o -MF CMakeFiles/BoostBeastServer.dir/main.cpp.o.d -o CMakeFiles/BoostBeastServer.dir/main.cpp.o -c /home/xxx/projects_cpp/boost_beast_server/main.cpp
Note that it compiles with gcc (-Werror active), only clangd thinks there is still a problem (Why does clangd consider the boost header code?).
CMake (Used version 3.29.1):
cmake_minimum_required(VERSION 3.20)
project(BoostBeastServer)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(BOOST_ROOT "${CMAKE_SOURCE_DIR}/extlibs/boost")
if(POLICY CMP0144)
cmake_policy(SET CMP0144 NEW)
endif()
set(Boost_NO_SYSTEM_PATHS ON)
find_package(Boost 1.84.0 REQUIRED COMPONENTS system thread)
if(NOT Boost_FOUND)
message(FATAL_ERROR "Boost not found")
endif()
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
add_executable(${PROJECT_NAME} main.cpp)
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall
-Wextra
-Wconversion
-Wsign-conversion
-Wfloat-equal
-Wunreachable-code
-Wunused-variable
-Wshadow
-Wcast-align
-Werror
)
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${Boost_LIBRARIES})
Possible solution:
To get rid of the warning, the following could help,
but please review, as I only have dangerous half-knowledge here.
After this at least the warning will go away:
[include/boost/core/detail/string_view.hpp]
Opened the following issue for this: https://github.com/boostorg/core/issues/170
@AlanBirtles's analysis is spot on, the warning is due to a sloppy conversion inside Boost Core std::string_view
. Note that this is not a real issue unless you can deal with strings over 2^63 characters long.
You can make a PR like https://github.com/sehe/core/commit/0d757123f136aff8f8ebed2c876ce7a2ccd28445 or just report the issue.
Another solution is to make the include a system include, which makes the warnings silent.