Skip to content

Commit 4549604

Browse files
committed
fix(*): fix all compile errors
1 parent 799b173 commit 4549604

22 files changed

+285
-267
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.24)
55
#
66
project(
77
stdsharp
8-
VERSION 0.8.8
8+
VERSION 0.9.0
99
LANGUAGES CXX)
1010

1111
include(cmake/Utils.cmake)

cmake/Utils.cmake

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ option(
55

66
set(CMAKE_COLOR_DIAGNOSTICS ON)
77

8-
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
8+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
99
add_compile_options(-fdiagnostics-show-template-tree)
1010
endif()
1111

12-
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
12+
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
1313
add_compile_options(/utf-8 /diagnostics:caret)
1414
endif()
1515

@@ -37,9 +37,7 @@ function(target_include_as_system target_name)
3737
${included})
3838
endfunction()
3939

40-
#
4140
# Create static or shared library, setup header and source files
42-
#
4341
function(config_lib lib_name lib_type)
4442
message("Configuring target library ${lib_name}")
4543

@@ -85,7 +83,7 @@ function(config_lib lib_name lib_type)
8583

8684
if(ARG_STD)
8785
target_compile_features(${lib_name} ${inc_tag} cxx_std_${ARG_STD})
88-
message(STATUS "Using c++ ${ARG_STD}.\n")
86+
message(STATUS "Using c++ ${ARG_STD}")
8987
endif()
9088

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

102-
#
103100
# Create executable, setup header and source files
104-
#
105101
function(config_exe exe_name)
106102
cmake_parse_arguments(ARG "" "STD;VER" "EXE_SRC" ${ARGN})
107103

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

120116
if(ARG_STD)
121117
target_compile_features(${exe_name} PUBLIC cxx_std_${ARG_STD})
122-
message(STATUS "Using c++ ${ARG_STD}.\n")
118+
message(STATUS "Using c++ ${ARG_STD}.")
123119
endif()
124120
endfunction()
125121

126-
#
127-
# Create executable, setup header and source files
128-
#
122+
# install library
129123
function(target_install target)
130124
include(CMakePackageConfigHelpers)
131125
include(GNUInstallDirs)
@@ -235,33 +229,44 @@ include($\{CMAKE_CURRENT_LIST_DIR}/${target}Targets.cmake)"
235229
COMPONENT "${target}_Development")
236230
endfunction()
237231

238-
function(target_enable_clang_tidy target)
232+
function(target_clang_tidy target)
239233
find_program(CLANG_TIDY clang-tidy)
240-
if(CLANG_TIDY)
241-
message(STATUS "found clang-tidy: ${CLANG_TIDY}")
242234

243-
get_target_property(bin_dir ${target} BINARY_DIR)
244-
set(report_folder "${bin_dir}/clang-tidy-report")
235+
if(NOT EXISTS "${CLANG_TIDY}")
236+
message(STATUS "clang-tidy not found")
237+
return()
238+
endif()
245239

246-
set_target_properties(
247-
${target}
248-
PROPERTIES
249-
CXX_CLANG_TIDY
250-
"${CLANG_TIDY};--enable-check-profile;--store-check-profile=${report_folder}"
251-
)
240+
message(STATUS "found clang-tidy: ${CLANG_TIDY}")
252241

253-
add_custom_target(
254-
${target}ClangTidyClean ALL
255-
COMMAND ${CMAKE_COMMAND} -E rm -rf ${report_folder}/
256-
USES_TERMINAL)
242+
get_target_property(bin_dir ${target} BINARY_DIR)
243+
set(report_folder "${bin_dir}/clang-tidy-report")
257244

258-
add_dependencies(${target} ${target}ClangTidyClean)
259-
else()
260-
message(STATUS "clang-tidy not found")
245+
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
246+
message(STATUS "Add extra MSVC arg for clang-tidy")
247+
set(MSVC_TIDY
248+
";--extra-arg=/EHsc;--extra-arg=/std:c++latest;--extra-arg=-Wno-unknown-warning-option"
249+
)
261250
endif()
251+
252+
set_target_properties(
253+
${target}
254+
PROPERTIES
255+
CXX_CLANG_TIDY
256+
"${CLANG_TIDY};
257+
--enable-check-profile;
258+
--store-check-profile=${report_folder}
259+
${MSVC_TIDY}")
260+
261+
add_custom_target(
262+
${target}ClangTidyClean ALL
263+
COMMAND ${CMAKE_COMMAND} -E rm -rf ${report_folder}/
264+
USES_TERMINAL)
265+
266+
add_dependencies(${target} ${target}ClangTidyClean)
262267
endfunction()
263268

264-
function(target_enable_clang_sanitizer target type)
269+
function(target_clang_sanitizer target type)
265270
cmake_parse_arguments(ARG "" "" "SANITIZER" ${ARGN})
266271

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

282-
function(target_coverage target_name)
287+
function(target_llvm_coverage target_name)
283288
message(STATUS "enable code coverage for ${target_name}")
284289
find_program(llvm_profdata "llvm-profdata")
285290
find_program(llvm_cov "llvm-cov")
286291

287-
if(NOT (${CMAKE_CXX_COMPILER_ID} MATCHES "(Apple)?[Cc]lang"))
292+
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
288293
message(
289294
STATUS
290-
"C++ Compiler should be Clang, ${CMAKE_CXX_COMPILER_ID} is not supported.\n"
295+
"C++ Compiler should be Clang, ${CMAKE_CXX_COMPILER_ID} is not supported."
291296
)
292297
return()
293298
endif()
294299

295300
if(NOT EXISTS "${llvm_profdata}" OR NOT EXISTS "${llvm_cov}")
296-
message(STATUS "llvm-profdata or llvm-cov not found.\n")
301+
message(STATUS "llvm-profdata or llvm-cov not found.")
297302
return()
298303
endif()
299304

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

303-
cmake_parse_arguments(ARG "" "FORMAT;PROFILE_FILE" "DEPENDS" ${ARGN})
308+
cmake_parse_arguments(ARG "" "FORMAT" "DEPENDS" ${ARGN})
309+
310+
set(profile_file "${target_name}.profraw")
311+
312+
# Run first to generate profraw file
313+
add_custom_command(
314+
OUTPUT ${profile_file}
315+
DEPENDS ${target_name}
316+
COMMAND ${CMAKE_COMMAND} -E env LLVM_PROFILE_FILE=${profile_file}
317+
$<TARGET_FILE:${target_name}> || exit 0)
304318

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

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

312326
if(${ARG_FORMAT} STREQUAL text)
313-
set(coverage_file json)
327+
set(coverage_file_ext json)
314328
elseif(${ARG_FORMAT} STREQUAL lcov)
315-
set(coverage_file lcov)
329+
set(coverage_file_ext lcov)
316330
else()
317331
message(FATAL_ERROR "unknown format ${ARG_FORMAT}")
318332
endif()
319333

320-
if(NOT DEFINED ARG_PROFILE_FILE)
321-
set(ARG_PROFILE_FILE "$ENV{LLVM_PROFILE_FILE}")
322-
endif()
323-
324-
set(coverage_file "${target_name}Coverage.${coverage_file}")
334+
set(coverage_file_ext "${target_name}Coverage.${coverage_file_ext}")
325335

326336
add_custom_target(
327337
${target_name}CoverageReport ALL
328-
DEPENDS ${target_name} ${ARG_DEPENDS}
329-
COMMAND ${CMAKE_COMMAND} -E rm -f "${profdata_file_name}" "${coverage_file}"
338+
DEPENDS ${profile_file}
330339
COMMAND "${llvm_profdata}" merge --sparse -o="${profdata_file_name}"
331-
"${ARG_PROFILE_FILE}"
340+
"${profile_file}"
332341
COMMAND
333342
"${llvm_cov}" export -format=${ARG_FORMAT}
334343
-object="$<TARGET_FILE:${target_name}>"
335-
-instr-profile="${profdata_file_name}" > "${coverage_file}"
344+
-instr-profile="${profdata_file_name}" > "${coverage_file_ext}"
336345
USES_TERMINAL)
337346
endfunction()

include/stdsharp/containers/concepts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ namespace stdsharp::details
450450

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

453-
return res;
453+
return res;
454454
}(std::make_index_sequence<sizeof...(Optional)>{});
455455
};
456456
}

include/stdsharp/default_operator.h

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ namespace stdsharp::default_operator
6262
}
6363
};
6464

65-
#define STDSHARP_ARITH_OP(name, op) \
66-
struct name##_commutative \
67-
{ \
68-
[[nodiscard]] friend constexpr decltype(auto) operator op( \
69-
not_decay_derived<name##_commutative> auto&& u, \
70-
decay_derived<name##_commutative> auto&& t \
71-
) noexcept(noexcept(cpp_forward(t) op cpp_forward(u))) \
72-
requires requires { cpp_forward(t) op cpp_forward(u); } \
73-
{ \
74-
return cpp_forward(t) op cpp_forward(u); \
75-
} \
65+
#define STDSHARP_ARITH_OP(name, op) \
66+
struct name##_commutative \
67+
{ \
68+
template<not_decay_derived<name##_commutative> T> \
69+
[[nodiscard]] friend constexpr decltype(auto \
70+
) operator op(T&& u, decay_derived<name##_commutative> auto&& t) \
71+
noexcept(noexcept(cpp_forward(t) op cpp_forward(u))) \
72+
requires requires { cpp_forward(t) op cpp_forward(u); } \
73+
{ \
74+
return cpp_forward(t) op cpp_forward(u); \
75+
} \
7676
}
7777

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

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

107108
struct arrow
108109
{
109-
[[nodiscard]] constexpr auto* operator->(this dereferenceable auto&& t)
110+
template<dereferenceable T>
111+
[[nodiscard]] constexpr auto* operator->(this T&& t)
110112
noexcept(noexcept(std::addressof(*cpp_forward(t))))
111113
{
112114
return std::addressof(*cpp_forward(t));
113115
}
114116

115-
[[nodiscard]] constexpr auto operator->*(this dereferenceable auto&& t, auto&& ptr)
116-
noexcept(noexcept((*cpp_forward(t)).*cpp_forward(ptr)))
117-
requires requires { (*cpp_forward(t)).*cpp_forward(ptr); }
117+
template<dereferenceable T>
118+
[[nodiscard]] constexpr auto operator->*(this T&& t, auto&& ptr)
119+
noexcept(noexcept((*cpp_forward(t)).*(cpp_forward(ptr))))
120+
requires requires { (*cpp_forward(t)).*(cpp_forward(ptr)); }
118121
{
119-
return (*cpp_forward(t)).*cpp_forward(ptr);
122+
return (*cpp_forward(t)).*(cpp_forward(ptr));
120123
}
121124
};
122125
}

include/stdsharp/functional/invocables.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,17 @@ namespace stdsharp::details
4646
return forward_cast<Self, invocables, indexed_invocable<J, type<J>>>(self).get();
4747
}
4848

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

55-
template<std::size_t J, typename Self, typename SelfT = const Self&>
56-
constexpr forward_cast_t<SelfT, type<J>> cget(this const Self& self) noexcept
55+
template<std::size_t J, typename Self>
56+
constexpr decltype(auto) cget(this const Self& self) noexcept
5757
{
58-
return forward_cast<SelfT, invocables, indexed_invocable<J, type<J>>>(self).cget();
58+
return forward_cast<const Self&, invocables, indexed_invocable<J, type<J>>>(self).cget(
59+
);
5960
}
6061
};
6162
}

include/stdsharp/functional/pipeable.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,30 @@ namespace stdsharp
1616
};
1717

1818
template<pipe_mode Mode = pipe_mode::left>
19-
struct pipeable_base
19+
struct pipeable_base;
20+
21+
template<>
22+
struct pipeable_base<pipe_mode::left>
2023
{
21-
static constexpr auto pipe_mode = Mode;
24+
static constexpr auto pipe_mode = pipe_mode::left;
2225

2326
private:
2427
template<typename Arg, std::invocable<Arg> Pipe>
25-
requires(Mode == pipe_mode::left)
28+
requires decay_derived<Pipe, pipeable_base>
2629
friend constexpr decltype(auto) operator|(Arg&& arg, Pipe&& pipe)
2730
noexcept(nothrow_invocable<Pipe, Arg>)
2831
{
2932
return invoke(cpp_forward(pipe), cpp_forward(arg));
3033
}
34+
};
35+
36+
template<>
37+
struct pipeable_base<pipe_mode::right>
38+
{
39+
static constexpr auto pipe_mode = pipe_mode::right;
3140

3241
template<typename Arg, std::invocable<Arg> Pipe>
33-
requires(Mode == pipe_mode::right)
34-
friend constexpr decltype(auto) operator|(Pipe&& pipe, Arg&& arg)
42+
constexpr decltype(auto) operator|(this Pipe&& pipe, Arg&& arg)
3543
noexcept(nothrow_invocable<Pipe, Arg>)
3644
{
3745
return invoke(cpp_forward(pipe), cpp_forward(arg));

0 commit comments

Comments
 (0)