Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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 @@ -102,7 +102,7 @@ jobs:
compiler: [MSVC, clang-cl]
arch: [x86, x64, arm64]
config: [Debug, Release]
test_exe: [test, test_cpp20, test_cpp20_no_sourcelocation, test_fast, test_slow, test_old, test_module_lock_custom, test_module_lock_none]
test_exe: [test, 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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ project(cppwinrt LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set(CPPWINRT_BUILD_VERSION "2.3.4.5" CACHE STRING "The version string used for cppwinrt.")
if(CPPWINRT_BUILD_VERSION STREQUAL "2.3.4.5" OR CPPWINRT_BUILD_VERSION STREQUAL "0.0.0.0")
set(CPPWINRT_BUILD_VERSION "1.2.3.4" CACHE STRING "The version string used for cppwinrt.")
if(CPPWINRT_BUILD_VERSION STREQUAL "1.2.3.4" OR CPPWINRT_BUILD_VERSION STREQUAL "0.0.0.0")
message(WARNING "CPPWINRT_BUILD_VERSION has been set to a dummy version string. Do not use in production!")
endif()
message(STATUS "Using version string: ${CPPWINRT_BUILD_VERSION}")
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.Props
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</PropertyGroup>

<PropertyGroup>
<CppWinRTBuildVersion Condition="'$(CppWinRTBuildVersion)'==''">2.3.4.5</CppWinRTBuildVersion>
<CppWinRTBuildVersion Condition="'$(CppWinRTBuildVersion)'==''">1.2.3.4</CppWinRTBuildVersion>
<CppWinRTPlatform>$(Platform)</CppWinRTPlatform>
<CppWinRTPlatform Condition="'$(Platform)'=='Win32'">x86</CppWinRTPlatform>
<OutDir>$(SolutionDir)_build\$(CppWinRTPlatform)\$(Configuration)\</OutDir>
Expand Down
1 change: 1 addition & 0 deletions build_test_all.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ call msbuild /p:Configuration=%target_configuration%,Platform=%target_platform%,
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.slnx /t:test\test
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.slnx /t:test\test_cpp20
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.slnx /t:test\test_cpp20_no_sourcelocation
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.slnx /t:test\test_cpp23
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.slnx /t:test\test_fast
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.slnx /t:test\test_slow
call msbuild /m /p:Configuration=%target_configuration%,Platform=%target_platform%,CppWinRTBuildVersion=%target_version% cppwinrt.slnx /t:test\test_module_lock_custom
Expand Down
4 changes: 4 additions & 0 deletions cppwinrt.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
<BuildDependency Project="cppwinrt/cppwinrt.vcxproj" />
<BuildDependency Project="test/test_component/test_component.vcxproj" />
</Project>
<Project Path="test/test_cpp23/test_cpp23.vcxproj">
<BuildDependency Project="cppwinrt/cppwinrt.vcxproj" />
<BuildDependency Project="test/test_component/test_component.vcxproj" />
</Project>
<Project Path="test/test_cpp20_no_sourcelocation/test_cpp20_no_sourcelocation.vcxproj">
<BuildDependency Project="cppwinrt/cppwinrt.vcxproj" />
<BuildDependency Project="test/test_component/test_component.vcxproj" />
Expand Down
2 changes: 1 addition & 1 deletion cppwinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2646,7 +2646,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_cpp20
call :run_test test_cpp20_no_sourcelocation
call :run_test test_cpp23
call :run_test test_fast
call :run_test test_slow
call :run_test test_old
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 @@ WINRT_EXPORT 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_cpp20)
add_subdirectory(test_cpp20_no_sourcelocation)
add_subdirectory(test_cpp23)

if(HAS_WINDOWSNUMERICS)
add_subdirectory(old_tests)
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
48 changes: 0 additions & 48 deletions test/test_cpp20/test_cpp20.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,6 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand All @@ -130,14 +122,6 @@
<Link>
<SubSystem>Console</SubSystem>
</Link>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<ClCompile>
Expand All @@ -152,14 +136,6 @@
<Link>
<SubSystem>Console</SubSystem>
</Link>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
Expand All @@ -174,14 +150,6 @@
<Link>
<SubSystem>Console</SubSystem>
</Link>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
Expand All @@ -200,14 +168,6 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<ClCompile>
Expand All @@ -226,14 +186,6 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<PreBuildEvent>
<Command>
</Command>
</PreBuildEvent>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
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}
)
129 changes: 129 additions & 0 deletions test/test_cpp23/delegate_deducing_this.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#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);
}

#if !(defined(_M_IX86) && !defined(_M_X64) && defined(__clang__))
// Clang 20 target x86 generates incorrect code for this test.
// In observed_sender ctor (#1), this = X; in assignment operator (#2), this = X+16 (bytes).
// FIXME: Enable the test after Clang is fixed
TEST_CASE("observablevector_vectorchanged")
{
IObservableVector<int> vector = single_threaded_observable_vector<int>();

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

auto token = vector.VectorChanged([&](this auto, IObservableVector<int> sender, IVectorChangedEventArgs args)
{
++called;
observed_sender = sender; // #2
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

#endif
Loading