Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
compiler: [MSVC, clang-cl]
arch: [x86, x64, arm64]
config: [Debug, Release]
test_exe: [test, test_nocoro, test_cpp20, test_cpp20_no_sourcelocation, test_fast, test_slow, test_old, test_module_lock_custom, test_module_lock_none]
test_exe: [test, test_nocoro, test_cpp20, test_cpp20_no_sourcelocation, test_cpp23, test_fast, test_slow, test_old, test_module_lock_custom, test_module_lock_none]
exclude:
- arch: arm64
config: Debug
Expand Down
1 change: 1 addition & 0 deletions build_test_all.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ call msbuild /p:Configuration=%target_configuration%,Platform=%target_platform%,
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\test
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\test_nocoro
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\test_cpp20
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\test_cpp23
Comment thread
YexuanXiao marked this conversation as resolved.
Outdated
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\test_cpp20_no_sourcelocation
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\test_fast
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.sln /t:test\test_slow
Expand Down
19 changes: 19 additions & 0 deletions cppwinrt.sln
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_module_lock_custom", "
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{3C7EA5F8-6E8C-4376-B499-2CAF596384B0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_cpp23", "test\test_cpp23\test_cpp23.vcxproj", "{04E0D58C-4F4F-4A50-A1D0-EDCE1CB8E0EF}"
ProjectSection(ProjectDependencies) = postProject
{A91B8BF3-28E4-4D9E-8DBA-64B70E4F0270} = {A91B8BF3-28E4-4D9E-8DBA-64B70E4F0270}
{D613FB39-5035-4043-91E2-BAB323908AF4} = {D613FB39-5035-4043-91E2-BAB323908AF4}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_cpp20", "test\test_cpp20\test_cpp20.vcxproj", "{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}"
ProjectSection(ProjectDependencies) = postProject
{A91B8BF3-28E4-4D9E-8DBA-64B70E4F0270} = {A91B8BF3-28E4-4D9E-8DBA-64B70E4F0270}
Expand Down Expand Up @@ -387,6 +393,18 @@ Global
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Release|x64.Build.0 = Release|x64
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Release|x86.ActiveCfg = Release|Win32
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA}.Release|x86.Build.0 = Release|Win32
{04E0D58C-4F4F-4A50-A1D0-EDCE1CB8E0EF}.Debug|ARM64.ActiveCfg = Debug|ARM64
{04E0D58C-4F4F-4A50-A1D0-EDCE1CB8E0EF}.Debug|ARM64.Build.0 = Debug|ARM64
{04E0D58C-4F4F-4A50-A1D0-EDCE1CB8E0EF}.Debug|x64.ActiveCfg = Debug|x64
{04E0D58C-4F4F-4A50-A1D0-EDCE1CB8E0EF}.Debug|x64.Build.0 = Debug|x64
{04E0D58C-4F4F-4A50-A1D0-EDCE1CB8E0EF}.Debug|x86.ActiveCfg = Debug|Win32
{04E0D58C-4F4F-4A50-A1D0-EDCE1CB8E0EF}.Debug|x86.Build.0 = Debug|Win32
{04E0D58C-4F4F-4A50-A1D0-EDCE1CB8E0EF}.Release|ARM64.ActiveCfg = Release|ARM64
{04E0D58C-4F4F-4A50-A1D0-EDCE1CB8E0EF}.Release|ARM64.Build.0 = Release|ARM64
{04E0D58C-4F4F-4A50-A1D0-EDCE1CB8E0EF}.Release|x64.ActiveCfg = Release|x64
{04E0D58C-4F4F-4A50-A1D0-EDCE1CB8E0EF}.Release|x64.Build.0 = Release|x64
{04E0D58C-4F4F-4A50-A1D0-EDCE1CB8E0EF}.Release|x86.ActiveCfg = Release|Win32
{04E0D58C-4F4F-4A50-A1D0-EDCE1CB8E0EF}.Release|x86.Build.0 = Release|Win32
{D4C8F881-84D5-4A7B-8BDE-AB4E34A05374}.Debug|ARM64.ActiveCfg = Debug|ARM64
{D4C8F881-84D5-4A7B-8BDE-AB4E34A05374}.Debug|ARM64.Build.0 = Debug|ARM64
{D4C8F881-84D5-4A7B-8BDE-AB4E34A05374}.Debug|x64.ActiveCfg = Debug|x64
Expand Down Expand Up @@ -433,6 +451,7 @@ Global
{D48A96C2-8512-4CC3-B6E4-7CFF07ED8ED3} = {3C7EA5F8-6E8C-4376-B499-2CAF596384B0}
{08C40663-B6A3-481E-8755-AE32BAD99501} = {3C7EA5F8-6E8C-4376-B499-2CAF596384B0}
{5FF6CD6C-515A-4D55-97B6-62AD9BCB77EA} = {3C7EA5F8-6E8C-4376-B499-2CAF596384B0}
{04E0D58C-4F4F-4A50-A1D0-EDCE1CB8E0EF} = {3C7EA5F8-6E8C-4376-B499-2CAF596384B0}
{D4C8F881-84D5-4A7B-8BDE-AB4E34A05374} = {3C7EA5F8-6E8C-4376-B499-2CAF596384B0}
{9E392830-805A-4AAF-932D-C493143EFACA} = {3C7EA5F8-6E8C-4376-B499-2CAF596384B0}
EndGlobalSection
Expand Down
2 changes: 1 addition & 1 deletion cppwinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2616,7 +2616,7 @@ struct WINRT_IMPL_EMPTY_BASES produce_dispatch_to_overridable<T, D, %>
type,
bind<write_abi_params>(signature),
bind<write_produce_cleanup>(signature),
bind<write_produce_upcall>("(*this)", signature));
bind<write_produce_upcall>("static_cast<H&>(*this)", signature));
}

static void write_delegate_definition(writer& w, TypeDef const& type)
Expand Down
1 change: 1 addition & 0 deletions run_tests.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if "%target_configuration%"=="" set target_configuration=Debug
call :run_test test
call :run_test test_nocoro
call :run_test test_cpp20
call :run_test test_cpp23
Comment thread
YexuanXiao marked this conversation as resolved.
Outdated
call :run_test test_cpp20_no_sourcelocation
call :run_test test_fast
call :run_test test_slow
Expand Down
4 changes: 2 additions & 2 deletions strings/base_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ namespace winrt::impl
{
if constexpr (std::is_void_v<R>)
{
(*this)(args...);
static_cast<H&>(*this)(args...);
}
else
{
return (*this)(args...);
return static_cast<H&>(*this)(args...);
}
}

Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ set(SKIP_LARGE_PCH FALSE CACHE BOOL "Skip building large precompiled headers.")
add_subdirectory(test)
add_subdirectory(test_nocoro)
add_subdirectory(test_cpp20)
add_subdirectory(test_cpp23)
Comment thread
YexuanXiao marked this conversation as resolved.
Outdated
add_subdirectory(test_cpp20_no_sourcelocation)

if(HAS_WINDOWSNUMERICS)
Expand Down
12 changes: 6 additions & 6 deletions test/catch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,12 +677,12 @@ namespace Catch {
auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&;
auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&;

constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
constexpr auto operator ""_sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
return StringRef( rawChars, size );
}
} // namespace Catch

constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef {
constexpr auto operator ""_catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef {
return Catch::StringRef( rawChars, size );
}

Expand Down Expand Up @@ -3177,8 +3177,8 @@ namespace Detail {
} // end namespace Detail

namespace literals {
Detail::Approx operator "" _a(long double val);
Detail::Approx operator "" _a(unsigned long long val);
Detail::Approx operator ""_a(long double val);
Detail::Approx operator ""_a(unsigned long long val);
} // end namespace literals

template<>
Expand Down Expand Up @@ -7922,10 +7922,10 @@ namespace Detail {
} // end namespace Detail

namespace literals {
Detail::Approx operator "" _a(long double val) {
Detail::Approx operator ""_a(long double val) {
return Detail::Approx(val);
}
Detail::Approx operator "" _a(unsigned long long val) {
Detail::Approx operator ""_a(unsigned long long val) {
return Detail::Approx(val);
}
} // end namespace literals
Expand Down
23 changes: 23 additions & 0 deletions test/test_cpp23/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set(CMAKE_CXX_STANDARD 23)

file(GLOB TEST_SRCS
LIST_DIRECTORIES false
CONFIGURE_DEPENDS
*.cpp
)
list(FILTER TEST_SRCS EXCLUDE REGEX "/(main|pch)\\.cpp")

add_executable(test_cpp23 main.cpp ${TEST_SRCS})

target_precompile_headers(test_cpp23 PRIVATE pch.h)
set_source_files_properties(
main.cpp
PROPERTIES SKIP_PRECOMPILE_HEADERS true
)

add_dependencies(test_cpp23 build-cppwinrt-projection)

add_test(
NAME test_cpp23
COMMAND "$<TARGET_FILE:test_cpp23>" ${TEST_COLOR_ARG}
)
123 changes: 123 additions & 0 deletions test/test_cpp23/delegate_deducing_this.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#include "pch.h"

using namespace winrt;
using namespace Windows::Foundation::Collections;

#if defined(__cpp_explicit_this_parameter) && __cpp_explicit_this_parameter >= 202110L

TEST_CASE("delegate")
{
// <>
{
bool invoked = false;
delegate<> d = [&](this auto) { invoked = true; };
d();
REQUIRE(invoked);
}

// <int>
{
int result = 0;
delegate<int> d = [&](this auto, int a) { result = a; };
d(123);
REQUIRE(result == 123);
}

// <int,int>
{
int result = 0;
delegate<int, int> d = [&](this auto, int a, int b) { result = a + b; };
d(4,5);
REQUIRE(result == 9);
}

// void()
{
bool invoked = false;
delegate<void()> d = [&](this auto) { invoked = true; };
d();
REQUIRE(invoked);
}

// void(int)
{
int result = 0;
delegate<void(int)> d = [&](this auto, int a) { result = a; };
d(123);
REQUIRE(result == 123);
}

// void(int,int)
{
int result = 0;
delegate<void(int,int)> d = [&](this auto, int a, int b) { result = a + b; };
d(4, 5);
REQUIRE(result == 9);
}

// int()
{
delegate<int()> d = [](this auto) { return 123; };
REQUIRE(d() == 123);
}

// int(int)
{
delegate<int(int)> d = [](this auto, int a) { return a; };
REQUIRE(d(123) == 123);
}

// int(int,int)
{
delegate<int(int, int)> d = [](this auto, int a, int b) { return a + b; };
REQUIRE(d(4, 5) == 9);
}
}

TEST_CASE("typedeventhandler")
{
using Handler = winrt::Windows::Foundation::TypedEventHandler<int, int>;

int called{};
int sum{};

Handler handler = [&called, &sum](this auto, int sender, int args)
{
++called;
sum = sender + args;
};

handler(1, 2);

REQUIRE(called == 1);
REQUIRE(sum == 3);
}

TEST_CASE("observablevector_vectorchanged")
{
IObservableVector<int> vector = single_threaded_observable_vector<int>();

int called{};
IObservableVector<int> observed_sender{ nullptr };
CollectionChange change{};
uint32_t index{};

auto token = vector.VectorChanged([&](this auto, IObservableVector<int> sender, IVectorChangedEventArgs args)
{
++called;
observed_sender = sender;
change = args.CollectionChange();
index = args.Index();
});

vector.Append(123);

REQUIRE(called == 1);
REQUIRE(observed_sender == vector);
REQUIRE(change == CollectionChange::ItemInserted);
REQUIRE(index == 0);

vector.VectorChanged(token);
}

#endif
30 changes: 30 additions & 0 deletions test/test_cpp23/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <crtdbg.h>
#define CATCH_CONFIG_RUNNER

// Force reportFatal to be available on mingw-w64
#define CATCH_CONFIG_WINDOWS_SEH

#if defined(_MSC_VER)
#pragma warning(disable : 5311)
#endif

#include "catch.hpp"
#include "winrt/base.h"

using namespace winrt;

int main(int const argc, char** argv)
{
init_apartment();
std::set_terminate([] { reportFatal("Abnormal termination"); ExitProcess(1); });
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
(void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
(void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
return Catch::Session().run(argc, argv);
}

CATCH_TRANSLATE_EXCEPTION(hresult_error const& e)
{
return to_string(e.message());
}
2 changes: 2 additions & 0 deletions test/test_cpp23/pch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "pch.h"

10 changes: 10 additions & 0 deletions test/test_cpp23/pch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#pragma warning(4: 4458) // ensure we compile clean with this warning enabled

#define WINRT_LEAN_AND_MEAN
#include "winrt/Windows.Foundation.h"
#include "winrt/Windows.Foundation.Collections.h"
#include "catch.hpp"

using namespace std::literals;
Loading