Skip to content
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

Test targets compile failed for the [-Werror=uninitialized] compile option for non MSVC compiler(gcc11.2) #36

Closed
zxhcho opened this issue Nov 8, 2022 · 5 comments · Fixed by #59
Labels
bug Something isn't working build p3

Comments

@zxhcho
Copy link

zxhcho commented Nov 8, 2022

The default tag BUILD_TESTING is set as ON for the project, and there is an target_compile_options(msft_proxy_tests PRIVATE -Wall -Wextra -Wpedantic -Werror) in CMakeLists.txt of test for non MSVC compiler, so when I compile the code in gcc11.2, the test cases will fail for:

error: ‘p.pro::proxy<{anonymous}::TestFacade>::meta_’ is used uninitialized [-Werror=uninitialized]
[build] 323 | if (rhs.meta_ != nullptr) {
[build] | ~~~~^~~~~
proxy_lifetime_tests.cpp: In member function ‘virtual void ProxyLifetimeTests_TestMoveAssignment_FromNull_ToSelf_Test::TestBody()’:
proxy_lifetime_tests.cpp:692:26: note: ‘p’ declared here
[build] 692 | pro::proxy p;

and a lot of Werror ...

@mingxwa
Copy link
Collaborator

mingxwa commented Nov 9, 2022

@zxhcho Thank you for your feedback! We already have pipelines running on Ubuntu (see Actions) that build the tests with GCC and did not notice any issue so far. As you mentioned MSVC, are you using GCC on Windows? If so, could you double check if CMake is properly configured with your compiler? If this issue persists and the environment is confirmed to be good, please feel free to let us know more about how your compiler and toolchains are configured so that we can repro it and help investigate further.

@Shuenhoy
Copy link

Shuenhoy commented Nov 9, 2022

I can confirm that the tests compile on GCC 11.1 (via Docker image gcc:11.1) with -DCMAKE_BUILD_TYPE=Debug but meet the same error as @zxhcho with -DCMAKE_BUILD_TYPE=Release.

@zxhcho
Copy link
Author

zxhcho commented Nov 9, 2022

@zxhcho Thank you for your feedback! We already have pipelines running on Ubuntu (see Actions) that build the tests with GCC and did not notice any issue so far. As you mentioned MSVC, are you using GCC on Windows? If so, could you double check if CMake is properly configured with your compiler? If this issue persists and the environment is confirmed to be good, please feel free to let us know more about how your compiler and toolchains are configured so that we can repro it and help investigate further.

Ok, I build it on Ubuntu 22.04 with gcc-11.2 and Release version. When I switch to Debug, the error will not occur as @Shuenhoy

@mingxwa mingxwa added bug Something isn't working p3 and removed triage needed labels Nov 9, 2022
@frederick-vs-ja
Copy link
Contributor

proxy/proxy.h

Lines 420 to 429 in 531dfcc

proxy& operator=(proxy&& rhs) noexcept(HasNothrowMoveAssignment)
requires(HasMoveAssignment) {
if constexpr (HasNothrowMoveAssignment) {
this->~proxy();
} else {
reset(); // For weak exception safety
}
new(this) proxy(std::move(rhs));
return *this;
}

Currently self-move-assignment can result in reading *this when *this is destroyed, which is UB. I think we should perform the operations only if this != std::addressof(rhs).

@mingxwa
Copy link
Collaborator

mingxwa commented Jan 18, 2024

@frederick-vs-ja I did not notice it is a UB of proxy to move-assign to itself. Thank you for the investigation!

@mingxwa mingxwa closed this as completed Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working build p3
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants