Skip to content

Commit

Permalink
fix(*): fix all compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
c0nstexpr committed Apr 17, 2024
1 parent 799b173 commit 4549604
Show file tree
Hide file tree
Showing 22 changed files with 285 additions and 267 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.24)
#
project(
stdsharp
VERSION 0.8.8
VERSION 0.9.0
LANGUAGES CXX)

include(cmake/Utils.cmake)
Expand Down
101 changes: 55 additions & 46 deletions cmake/Utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ option(

set(CMAKE_COLOR_DIAGNOSTICS ON)

if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-fdiagnostics-show-template-tree)
endif()

if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/utf-8 /diagnostics:caret)
endif()

Expand Down Expand Up @@ -37,9 +37,7 @@ function(target_include_as_system target_name)
${included})
endfunction()

#
# Create static or shared library, setup header and source files
#
function(config_lib lib_name lib_type)
message("Configuring target library ${lib_name}")

Expand Down Expand Up @@ -85,7 +83,7 @@ function(config_lib lib_name lib_type)

if(ARG_STD)
target_compile_features(${lib_name} ${inc_tag} cxx_std_${ARG_STD})
message(STATUS "Using c++ ${ARG_STD}.\n")
message(STATUS "Using c++ ${ARG_STD}")
endif()

target_include_directories(
Expand All @@ -99,9 +97,7 @@ function(config_lib lib_name lib_type)
set_target_properties(${lib_name} PROPERTIES VERSION "${ARG_VER}")
endfunction()

#
# Create executable, setup header and source files
#
function(config_exe exe_name)
cmake_parse_arguments(ARG "" "STD;VER" "EXE_SRC" ${ARGN})

Expand All @@ -119,13 +115,11 @@ function(config_exe exe_name)

if(ARG_STD)
target_compile_features(${exe_name} PUBLIC cxx_std_${ARG_STD})
message(STATUS "Using c++ ${ARG_STD}.\n")
message(STATUS "Using c++ ${ARG_STD}.")
endif()
endfunction()

#
# Create executable, setup header and source files
#
# install library
function(target_install target)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
Expand Down Expand Up @@ -235,33 +229,44 @@ include($\{CMAKE_CURRENT_LIST_DIR}/${target}Targets.cmake)"
COMPONENT "${target}_Development")
endfunction()

function(target_enable_clang_tidy target)
function(target_clang_tidy target)
find_program(CLANG_TIDY clang-tidy)
if(CLANG_TIDY)
message(STATUS "found clang-tidy: ${CLANG_TIDY}")

get_target_property(bin_dir ${target} BINARY_DIR)
set(report_folder "${bin_dir}/clang-tidy-report")
if(NOT EXISTS "${CLANG_TIDY}")
message(STATUS "clang-tidy not found")
return()
endif()

set_target_properties(
${target}
PROPERTIES
CXX_CLANG_TIDY
"${CLANG_TIDY};--enable-check-profile;--store-check-profile=${report_folder}"
)
message(STATUS "found clang-tidy: ${CLANG_TIDY}")

add_custom_target(
${target}ClangTidyClean ALL
COMMAND ${CMAKE_COMMAND} -E rm -rf ${report_folder}/
USES_TERMINAL)
get_target_property(bin_dir ${target} BINARY_DIR)
set(report_folder "${bin_dir}/clang-tidy-report")

add_dependencies(${target} ${target}ClangTidyClean)
else()
message(STATUS "clang-tidy not found")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
message(STATUS "Add extra MSVC arg for clang-tidy")
set(MSVC_TIDY
";--extra-arg=/EHsc;--extra-arg=/std:c++latest;--extra-arg=-Wno-unknown-warning-option"
)
endif()

set_target_properties(
${target}
PROPERTIES
CXX_CLANG_TIDY
"${CLANG_TIDY};
--enable-check-profile;
--store-check-profile=${report_folder}
${MSVC_TIDY}")

add_custom_target(
${target}ClangTidyClean ALL
COMMAND ${CMAKE_COMMAND} -E rm -rf ${report_folder}/
USES_TERMINAL)

add_dependencies(${target} ${target}ClangTidyClean)
endfunction()

function(target_enable_clang_sanitizer target type)
function(target_clang_sanitizer target type)
cmake_parse_arguments(ARG "" "" "SANITIZER" ${ARGN})

foreach(sanitizer ${ARG_SANITIZER})
Expand All @@ -279,28 +284,37 @@ function(target_enable_clang_sanitizer target type)
"SHELL: $<${clang_debug_only}:${sanitizer_options}>")
endfunction()

function(target_coverage target_name)
function(target_llvm_coverage target_name)
message(STATUS "enable code coverage for ${target_name}")
find_program(llvm_profdata "llvm-profdata")
find_program(llvm_cov "llvm-cov")

if(NOT (${CMAKE_CXX_COMPILER_ID} MATCHES "(Apple)?[Cc]lang"))
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
message(
STATUS
"C++ Compiler should be Clang, ${CMAKE_CXX_COMPILER_ID} is not supported.\n"
"C++ Compiler should be Clang, ${CMAKE_CXX_COMPILER_ID} is not supported."
)
return()
endif()

if(NOT EXISTS "${llvm_profdata}" OR NOT EXISTS "${llvm_cov}")
message(STATUS "llvm-profdata or llvm-cov not found.\n")
message(STATUS "llvm-profdata or llvm-cov not found.")
return()
endif()

message(STATUS "found llvm-profdata at: ${llvm_profdata}")
message(STATUS "found llvm-cov at: ${llvm_cov}")

cmake_parse_arguments(ARG "" "FORMAT;PROFILE_FILE" "DEPENDS" ${ARGN})
cmake_parse_arguments(ARG "" "FORMAT" "DEPENDS" ${ARGN})

set(profile_file "${target_name}.profraw")

# Run first to generate profraw file
add_custom_command(
OUTPUT ${profile_file}
DEPENDS ${target_name}
COMMAND ${CMAKE_COMMAND} -E env LLVM_PROFILE_FILE=${profile_file}
$<TARGET_FILE:${target_name}> || exit 0)

set(options -fprofile-instr-generate -fcoverage-mapping)

Expand All @@ -310,28 +324,23 @@ function(target_coverage target_name)
set(profdata_file_name "${target_name}.profdata")

if(${ARG_FORMAT} STREQUAL text)
set(coverage_file json)
set(coverage_file_ext json)
elseif(${ARG_FORMAT} STREQUAL lcov)
set(coverage_file lcov)
set(coverage_file_ext lcov)
else()
message(FATAL_ERROR "unknown format ${ARG_FORMAT}")
endif()

if(NOT DEFINED ARG_PROFILE_FILE)
set(ARG_PROFILE_FILE "$ENV{LLVM_PROFILE_FILE}")
endif()

set(coverage_file "${target_name}Coverage.${coverage_file}")
set(coverage_file_ext "${target_name}Coverage.${coverage_file_ext}")

add_custom_target(
${target_name}CoverageReport ALL
DEPENDS ${target_name} ${ARG_DEPENDS}
COMMAND ${CMAKE_COMMAND} -E rm -f "${profdata_file_name}" "${coverage_file}"
DEPENDS ${profile_file}
COMMAND "${llvm_profdata}" merge --sparse -o="${profdata_file_name}"
"${ARG_PROFILE_FILE}"
"${profile_file}"
COMMAND
"${llvm_cov}" export -format=${ARG_FORMAT}
-object="$<TARGET_FILE:${target_name}>"
-instr-profile="${profdata_file_name}" > "${coverage_file}"
-instr-profile="${profdata_file_name}" > "${coverage_file_ext}"
USES_TERMINAL)
endfunction()
2 changes: 1 addition & 1 deletion include/stdsharp/containers/concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ namespace stdsharp::details

if constexpr(count > 0) res = res && self(std::make_index_sequence<count - 1>{});

return res;
return res;
}(std::make_index_sequence<sizeof...(Optional)>{});
};
}
Expand Down
35 changes: 19 additions & 16 deletions include/stdsharp/default_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ namespace stdsharp::default_operator
}
};

#define STDSHARP_ARITH_OP(name, op) \
struct name##_commutative \
{ \
[[nodiscard]] friend constexpr decltype(auto) operator op( \
not_decay_derived<name##_commutative> auto&& u, \
decay_derived<name##_commutative> auto&& t \
) noexcept(noexcept(cpp_forward(t) op cpp_forward(u))) \
requires requires { cpp_forward(t) op cpp_forward(u); } \
{ \
return cpp_forward(t) op cpp_forward(u); \
} \
#define STDSHARP_ARITH_OP(name, op) \
struct name##_commutative \
{ \
template<not_decay_derived<name##_commutative> T> \
[[nodiscard]] friend constexpr decltype(auto \
) operator op(T&& u, decay_derived<name##_commutative> auto&& t) \
noexcept(noexcept(cpp_forward(t) op cpp_forward(u))) \
requires requires { cpp_forward(t) op cpp_forward(u); } \
{ \
return cpp_forward(t) op cpp_forward(u); \
} \
}

STDSHARP_ARITH_OP(plus, +);
Expand All @@ -90,6 +90,7 @@ namespace stdsharp::default_operator

struct subscript
{
// TODO: multidimensional subscript
#if __cpp_multidimensional_subscript >= 202110L
[[nodiscard]] constexpr decltype(auto
) operator[](this auto&& t, auto&& first_arg, auto&&... args)
Expand All @@ -106,17 +107,19 @@ namespace stdsharp::default_operator

struct arrow
{
[[nodiscard]] constexpr auto* operator->(this dereferenceable auto&& t)
template<dereferenceable T>
[[nodiscard]] constexpr auto* operator->(this T&& t)
noexcept(noexcept(std::addressof(*cpp_forward(t))))
{
return std::addressof(*cpp_forward(t));
}

[[nodiscard]] constexpr auto operator->*(this dereferenceable auto&& t, auto&& ptr)
noexcept(noexcept((*cpp_forward(t)).*cpp_forward(ptr)))
requires requires { (*cpp_forward(t)).*cpp_forward(ptr); }
template<dereferenceable T>
[[nodiscard]] constexpr auto operator->*(this T&& t, auto&& ptr)
noexcept(noexcept((*cpp_forward(t)).*(cpp_forward(ptr))))
requires requires { (*cpp_forward(t)).*(cpp_forward(ptr)); }
{
return (*cpp_forward(t)).*cpp_forward(ptr);
return (*cpp_forward(t)).*(cpp_forward(ptr));
}
};
}
11 changes: 6 additions & 5 deletions include/stdsharp/functional/invocables.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ namespace stdsharp::details
return forward_cast<Self, invocables, indexed_invocable<J, type<J>>>(self).get();
}

template<std::size_t J, typename Self, typename SelfT = const Self>
template<std::size_t J, typename Self>
constexpr decltype(auto) cget(this const Self&& self) noexcept
{
return forward_cast<SelfT, invocables, indexed_invocable<J, type<J>>>(self).cget();
return forward_cast<const Self, invocables, indexed_invocable<J, type<J>>>(self).cget();
}

template<std::size_t J, typename Self, typename SelfT = const Self&>
constexpr forward_cast_t<SelfT, type<J>> cget(this const Self& self) noexcept
template<std::size_t J, typename Self>
constexpr decltype(auto) cget(this const Self& self) noexcept
{
return forward_cast<SelfT, invocables, indexed_invocable<J, type<J>>>(self).cget();
return forward_cast<const Self&, invocables, indexed_invocable<J, type<J>>>(self).cget(
);
}
};
}
Expand Down
18 changes: 13 additions & 5 deletions include/stdsharp/functional/pipeable.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,30 @@ namespace stdsharp
};

template<pipe_mode Mode = pipe_mode::left>
struct pipeable_base
struct pipeable_base;

template<>
struct pipeable_base<pipe_mode::left>
{
static constexpr auto pipe_mode = Mode;
static constexpr auto pipe_mode = pipe_mode::left;

private:
template<typename Arg, std::invocable<Arg> Pipe>
requires(Mode == pipe_mode::left)
requires decay_derived<Pipe, pipeable_base>
friend constexpr decltype(auto) operator|(Arg&& arg, Pipe&& pipe)
noexcept(nothrow_invocable<Pipe, Arg>)
{
return invoke(cpp_forward(pipe), cpp_forward(arg));
}
};

template<>
struct pipeable_base<pipe_mode::right>
{
static constexpr auto pipe_mode = pipe_mode::right;

template<typename Arg, std::invocable<Arg> Pipe>
requires(Mode == pipe_mode::right)
friend constexpr decltype(auto) operator|(Pipe&& pipe, Arg&& arg)
constexpr decltype(auto) operator|(this Pipe&& pipe, Arg&& arg)
noexcept(nothrow_invocable<Pipe, Arg>)
{
return invoke(cpp_forward(pipe), cpp_forward(arg));
Expand Down
Loading

0 comments on commit 4549604

Please sign in to comment.