-
Notifications
You must be signed in to change notification settings - Fork 255
Cleaning up some warnings for Clang and GCC #1255
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
Changes from all commits
4288671
1e9fec6
dabb76c
bc7b775
dc09603
ea1a53a
9fe0157
03226e3
42b2e63
7389961
39c332c
f9bf404
a30f893
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -345,6 +345,26 @@ WINRT_EXPORT namespace winrt | |
this->m_size = size; | ||
} | ||
} | ||
|
||
std::pair<uint32_t, impl::arg_out<T>> detach_abi() noexcept | ||
{ | ||
#ifdef _MSC_VER | ||
// https://github.com/microsoft/cppwinrt/pull/1165 | ||
std::pair<uint32_t, impl::arg_out<T>> result; | ||
memset(&result, 0, sizeof(result)); | ||
result.first = this->size(); | ||
result.second = *reinterpret_cast<impl::arg_out<T>*>(this); | ||
memset(this, 0, sizeof(com_array<T>)); | ||
#else | ||
std::pair<uint32_t, impl::arg_out<T>> result(this->size(), *reinterpret_cast<impl::arg_out<T>*>(this)); | ||
this->m_data = nullptr; | ||
this->m_size = 0; | ||
#endif | ||
return result; | ||
} | ||
|
||
template <typename U> | ||
friend std::pair<uint32_t, impl::arg_out<U>> detach_abi(com_array<U>& object) noexcept; | ||
}; | ||
|
||
template <typename C> com_array(uint32_t, C const&) -> com_array<std::decay_t<C>>; | ||
|
@@ -418,14 +438,9 @@ WINRT_EXPORT namespace winrt | |
} | ||
|
||
template <typename T> | ||
auto detach_abi(com_array<T>& object) noexcept | ||
std::pair<uint32_t, impl::arg_out<T>> detach_abi(com_array<T>& object) noexcept | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. This change undoes an intentional change made to address a customer-reported issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you recall the issue? We should have a test to avoid such a regression, but all tests pass on this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, you're referring to #1165 - that was itself to suppress a compiler warning. 🙄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, we can avoid the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks to me like the original change was to suppress a warning in MSVC and this change is to suppress a warning in GCC. So if nobody objects, I'll go ahead and approve this change. |
||
{ | ||
std::pair<uint32_t, impl::arg_out<T>> result; | ||
memset(&result, 0, sizeof(result)); | ||
result.first = object.size(); | ||
result.second = *reinterpret_cast<impl::arg_out<T>*>(&object); | ||
memset(&object, 0, sizeof(com_array<T>)); | ||
return result; | ||
return object.detach_abi(); | ||
} | ||
|
||
template <typename T> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
#pragma once | ||
|
||
#ifdef _MSC_VER | ||
#pragma warning(disable:4100) | ||
#endif | ||
|
||
#include "winrt/Windows.Foundation.h" | ||
#include "winrt/Composable.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this reintroduce the uninitialized padding data for non-VC compilers, per the comments in the PR linked above? What compiler warning does this resolve?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GCC warning is
'void* memset(void*, int, size_t)' clearing an object of type 'struct std::pair<unsigned int, float*>' with no trivial copy-assignment; use assignment or value-initialization instead [-Wclass-memaccess]
.This change does leave the padding uninitialized, but as said before it is "almost never going to be an issue for this function" and I am uncomfortable with the attempt to fix it potentially invoking UB. (Though I am no language lawyer so I cannot say for sure whether there is UB.)