-
Notifications
You must be signed in to change notification settings - Fork 263
Add a mechanism to suppress std::source_location #1260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kennykerr
merged 7 commits into
microsoft:master
from
dmachaj:user/dmachaj/source-location-disable
Jan 9, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6f4ff4d
First draft of suppressing source location
dmachaj 53a54d1
Add project in two places I missed
dmachaj 5bec5af
Fix some oopsies the new test found
dmachaj 87562e7
Fix new test now that it is confirmed as failing as intented
dmachaj 03b6b39
Fix up missed cmake locations
dmachaj 470f436
Try to fix clang
dmachaj e697887
Merge branch 'master' into user/dmachaj/source-location-disable
dmachaj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| set(CMAKE_CXX_STANDARD 20) | ||
| if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
| # std::format, std::ranges::is_heap, std::views::reverse, std::ranges::max | ||
| # are experimental in libc++ as of Clang 15. | ||
| # FIXME: Should probably use compile test instead? | ||
| set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexperimental-library") | ||
| endif() | ||
|
|
||
| if(ENABLE_TEST_SANITIZERS) | ||
| # As of LLVM 15, custom_error.cpp doesn't build with ASAN due to: | ||
| # error: cannot make section .ASAN$GL associative with sectionless symbol _ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE4nposE | ||
| set_source_files_properties(custom_error.cpp PROPERTIES COMPILE_OPTIONS "-fno-sanitize=address") | ||
| set_source_files_properties(custom_error.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS true) | ||
| endif() | ||
|
|
||
| file(GLOB TEST_SRCS | ||
| LIST_DIRECTORIES false | ||
| CONFIGURE_DEPENDS | ||
| *.cpp | ||
| ) | ||
| list(FILTER TEST_SRCS EXCLUDE REGEX "/(main|pch)\\.cpp") | ||
|
|
||
|
|
||
| list(APPEND BROKEN_TESTS | ||
| # No broken tests. | ||
| ) | ||
|
|
||
| # Exclude broken tests | ||
| foreach(TEST_SRCS_EXCLUDE_ITEM IN LISTS BROKEN_TESTS) | ||
| list(FILTER TEST_SRCS EXCLUDE REGEX "/${TEST_SRCS_EXCLUDE_ITEM}\\.cpp") | ||
| endforeach() | ||
|
|
||
| add_executable(test_cpp20_no_sourcelocation main.cpp ${TEST_SRCS}) | ||
|
|
||
| target_compile_definitions(test_cpp20_no_sourcelocation PRIVATE WINRT_NO_SOURCE_LOCATION) | ||
|
|
||
| target_precompile_headers(test_cpp20_no_sourcelocation PRIVATE pch.h) | ||
| set_source_files_properties( | ||
| main.cpp | ||
| PROPERTIES SKIP_PRECOMPILE_HEADERS true | ||
| ) | ||
|
|
||
| add_dependencies(test_cpp20_no_sourcelocation build-cppwinrt-projection) | ||
|
|
||
| add_test( | ||
| NAME test_cpp20_no_sourcelocation | ||
| COMMAND "$<TARGET_FILE:test_cpp20_no_sourcelocation>" ${TEST_COLOR_ARG} | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #include "pch.h" | ||
|
|
||
| using namespace winrt; | ||
| using namespace Windows::Foundation; | ||
|
|
||
| namespace | ||
| { | ||
| static bool s_loggerCalled = false; | ||
|
|
||
| // Note that we are checking that the source line number matches expectations. If lines above this are changed | ||
| // then this value needs to change as well. | ||
| void FailOnLine15() | ||
| { | ||
| // Validate that handler translated exception | ||
| REQUIRE_THROWS_AS(check_hresult(0x80000018), hresult_illegal_delegate_assignment); | ||
| } | ||
|
|
||
| static struct { | ||
| uint32_t lineNumber; | ||
| char const* fileName; | ||
| char const* functionName; | ||
| void* returnAddress; | ||
| winrt::hresult result; | ||
| } s_loggerArgs{}; | ||
|
|
||
| void __stdcall logger(uint32_t lineNumber, char const* fileName, char const* functionName, void* returnAddress, winrt::hresult const result) noexcept | ||
| { | ||
| s_loggerArgs = { | ||
| .lineNumber = lineNumber, | ||
| .fileName = fileName, | ||
| .functionName = functionName, | ||
| .returnAddress = returnAddress, | ||
| .result = result, | ||
| }; | ||
| s_loggerCalled = true; | ||
| } | ||
| } | ||
|
|
||
| TEST_CASE("custom_error_logger") | ||
| { | ||
| // Set up global handler | ||
| REQUIRE(!s_loggerCalled); | ||
| REQUIRE(!winrt_throw_hresult_handler); | ||
| winrt_throw_hresult_handler = logger; | ||
|
|
||
| FailOnLine15(); | ||
| REQUIRE(s_loggerCalled); | ||
| // In C++20 these fields should be filled in by std::source_location. However, this binary has | ||
| // specified WINRT_NO_SOURCE_LOCATION so that support should be removed. As a result these should | ||
| // return the same (empty) values as C++17. | ||
| REQUIRE(s_loggerArgs.lineNumber == 0); | ||
| REQUIRE(s_loggerArgs.fileName == nullptr); | ||
| REQUIRE(s_loggerArgs.functionName == nullptr); | ||
|
|
||
| REQUIRE(s_loggerArgs.returnAddress); | ||
| REQUIRE(s_loggerArgs.result == 0x80000018); // E_ILLEGAL_DELEGATE_ASSIGNMENT) | ||
|
|
||
| // Remove global handler | ||
| winrt_throw_hresult_handler = nullptr; | ||
| s_loggerCalled = false; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #include <crtdbg.h> | ||
| #define CATCH_CONFIG_RUNNER | ||
|
|
||
| // Force reportFatal to be available on mingw-w64 | ||
| #define CATCH_CONFIG_WINDOWS_SEH | ||
|
|
||
| #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); | ||
| _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); | ||
| _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE); | ||
| _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); | ||
| return Catch::Session().run(argc, argv); | ||
| } | ||
|
|
||
| CATCH_TRANSLATE_EXCEPTION(hresult_error const& e) | ||
| { | ||
| return to_string(e.message()); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| #include "pch.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #pragma once | ||
|
|
||
| #pragma warning(4: 4458) // ensure we compile clean with this warning enabled | ||
|
|
||
| #define WINRT_LEAN_AND_MEAN | ||
| #include <unknwn.h> | ||
| #include "winrt/Windows.Data.Json.h" | ||
| #include "winrt/Windows.Foundation.h" | ||
| #include "winrt/Windows.Foundation.Collections.h" | ||
| #include "winrt/Windows.Foundation.Numerics.h" | ||
| #include <winstring.h> | ||
| #include "catch.hpp" | ||
|
|
||
| #include <string_view> | ||
|
|
||
| using namespace std::literals; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.