Closed mblanz1 closed 1 year ago
I can't reproduce it with my tests after enabling warnings (see ee90a4a5286699b9ea13e527ca0694d871835d38 ).
Would you post an example of code that causes warnings?
I created a simple client project where warnings can be produced. It consists of two files plus sub directory containing utfcpp (commit hash ee90a4a5286699b9ea13e527ca0694d871835d38). First file is CMakeLists.txt:
cmake_minimum_required(VERSION VERSION 3.15.3)
PROJECT(MyExecutable LANGUAGES CXX)
file(GLOB SOURCES
"src/*.cpp"
"src/*.hpp"
)
add_subdirectory(libs/utfcpp)
set(MYEXECUTABLE_TARGET_NAME ${PROJECT_NAME})
add_executable(${MYEXECUTABLE_TARGET_NAME} ${SOURCES})
set_target_properties (${PROJECT_NAME} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED TRUE
CXX_EXTENSIONS FALSE
COMPILE_FLAGS "-std=c++17"
)
SET(compile_options
"-Wall"
"-Wconversion"
)
TARGET_COMPILE_OPTIONS("${PROJECT_NAME}" PRIVATE ${compile_options})
target_link_libraries(${MYEXECUTABLE_TARGET_NAME}
PRIVATE
utf8cpp
)
Second file is Main.cpp:
#include <iostream>
#include <string_view>
#include <utf8.h>
using namespace utf8;
int main(int /*argc*/, char ** /*argv*/) {
std::cout << "MyExecutable" << std::endl;
std::string_view msg = "Test";
std::string result;
utf8::replace_invalid(msg.begin(), msg.end(), back_inserter(result));
std::cout << result << std::endl;
}
Project directory structure: ./CMakeLists.txt ./src/Main.cpp ./libs/utfcpp
I built the project with following cmake (version 3.24.3) calls on an Ubuntu 20.04 LTS system:
cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang-10 -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/clang++-10 ..
cmake --build .
Maybe important for reproduction are the compile option -Wconversion and CMake arguments -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang-10 -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/clang++-10
Yes, it's -Wconversion. When I add that I got the warnings even in my existing tests. I'll think about it.
aa3b12c52b2f96a8c2b7873e9b4e061c9e534aa4 addresses a couple of warnings. Unfortunately, I am not aware of a way to fix the main culprits at function append() without affecting portability.
I have some ideas. Re-opening
Fixed e3e57c811aa4cd12153f920a45ff2157427977da
When compiling client project using utfcpp with compiler Clang 10.0.0 then warnings concerning "implicit conversion changes signedness" are displayed, e.g. libs/utfcpp/source/utf8/cpp17.h:73:73: error: operand of ? changes signedness: 'long' to 'unsigned long' [-Werror,-Wsign-conversion] [build] return (invalid == s.end()) ? std::string_view::npos : (invalid - s.begin());
See attached log file for details
utfcpp_Clang10_Warnings.txt