[libcxx-commits] [PATCH] D144775: [libc++][test] Add '-Wdeprecated-copy', '-Wdeprecated-copy-dtor' warnings to the test suite

Igor Zhukov via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Feb 26 06:17:43 PST 2023


fsb4000 added inline comments.


================
Comment at: libcxx/test/libcxx/memory/trivial_abi/unique_ptr_destruction_order.pass.cpp:30
+  Base(const Base& other) = default;
+  Base& operator=(const Base&) = default;
   ~Base() { shared_buff[(*cur_idx)++] = id; }
----------------
fsb4000 wrote:
> fsb4000 wrote:
> > Mordante wrote:
> > > Can these be deleted instead? I assume the `id` was intentionally const qualified.
> > Without my changes:
> > ```
> > /home/libcxx-builder/.buildkite-agent/builds/99763c758770-1/llvm-project/libcxx-ci/libcxx/test/libcxx/memory/trivial_abi/unique_ptr_destruction_order.pass.cpp:29:3: error: definition of implicit copy constructor for 'Base' is deprecated because it has a user-provided destructor [-Werror,-Wdeprecated-copy-with-user-provided-dtor]
> >   ~Base() { shared_buff[(*cur_idx)++] = id; }
> >   ^
> > /home/libcxx-builder/.buildkite-agent/builds/99763c758770-1/llvm-project/libcxx-ci/libcxx/test/libcxx/memory/trivial_abi/unique_ptr_destruction_order.pass.cpp:32:8: note: in implicit copy constructor for 'Base' first required here
> > struct A : Base {
> >        ^
> > /home/libcxx-builder/.buildkite-agent/builds/99763c758770-1/llvm-project/libcxx-ci/libcxx/test/libcxx/memory/trivial_abi/unique_ptr_destruction_order.pass.cpp:53:8: note: in implicit move constructor for 'A' first required here
> >   func(A(shared_buf, &cur_idx), std::unique_ptr<B>(new B(shared_buf, &cur_idx)),
> > ```
> > If I add `=default`:
> > ```
> > /home/libcxx-builder/.buildkite-agent/builds/c072959aa3b7-1/llvm-project/libcxx-ci/libcxx/test/libcxx/memory/trivial_abi/unique_ptr_destruction_order.pass.cpp:30:9: error: explicitly defaulted copy assignment operator is implicitly deleted [-Werror,-Wdefaulted-function-deleted]
> >   Base& operator=(const Base&) = default;
> >         ^
> > /home/libcxx-builder/.buildkite-agent/builds/c072959aa3b7-1/llvm-project/libcxx-ci/libcxx/test/libcxx/memory/trivial_abi/unique_ptr_destruction_order.pass.cpp:25:14: note: copy assignment operator of 'Base' is implicitly deleted because field 'id' is of const-qualified type 'const char'
> >   const char id;
> >              ^
> > /home/libcxx-builder/.buildkite-agent/builds/c072959aa3b7-1/llvm-project/libcxx-ci/libcxx/test/libcxx/memory/trivial_abi/unique_ptr_destruction_order.pass.cpp:30:34: note: replace 'default' with 'delete'
> >   Base& operator=(const Base&) = default;
> >                                  ^~~~~~~
> >                                  delete
> > 1 error generated.
> > ```
> > If I add `=delete`
> > ```
> > /home/libcxx-builder/.buildkite-agent/builds/ab7607b38669-1/llvm-project/libcxx-ci/libcxx/test/libcxx/memory/trivial_abi/unique_ptr_destruction_order.pass.cpp:34:8: error: call to deleted constructor of 'Base'
> > struct A : Base {
> >        ^
> > /home/libcxx-builder/.buildkite-agent/builds/ab7607b38669-1/llvm-project/libcxx-ci/libcxx/test/libcxx/memory/trivial_abi/unique_ptr_destruction_order.pass.cpp:55:8: note: in implicit copy constructor for 'A' first required here
> >   func(A(shared_buf, &cur_idx), std::unique_ptr<B>(new B(shared_buf, &cur_idx)),
> >        ^
> > /home/libcxx-builder/.buildkite-agent/builds/ab7607b38669-1/llvm-project/libcxx-ci/libcxx/test/libcxx/memory/trivial_abi/unique_ptr_destruction_order.pass.cpp:29:3: note: 'Base' has been explicitly marked deleted here
> >   Base(const Base&) = delete;
> >   ^
> > /home/libcxx-builder/.buildkite-agent/builds/ab7607b38669-1/llvm-project/libcxx-ci/libcxx/test/libcxx/memory/trivial_abi/unique_ptr_destruction_order.pass.cpp:42:8: error: call to deleted constructor of 'Base'
> > struct C : Base {
> >        ^
> > /home/libcxx-builder/.buildkite-agent/builds/ab7607b38669-1/llvm-project/libcxx-ci/libcxx/test/libcxx/memory/trivial_abi/unique_ptr_destruction_order.pass.cpp:56:8: note: in implicit copy constructor for 'C' first required here
> >        C(shared_buf, &cur_idx));
> >        ^
> > /home/libcxx-builder/.buildkite-agent/builds/ab7607b38669-1/llvm-project/libcxx-ci/libcxx/test/libcxx/memory/trivial_abi/unique_ptr_destruction_order.pass.cpp:29:3: note: 'Base' has been explicitly marked deleted here
> >   Base(const Base&) = delete;
> >   ^
> > 2 errors generated.
> > 
> > ```
> one more thing.
> On Windows I can write whatever in that test.
> It passes without my changes, it passes with `=default`, it passes with `=delete`
> 
> I run the test this way:
> ```
> C:\Dev\STL\llvm-project\build>python bin\llvm-lit.py ..\libcxx\test\libcxx\memory\trivial_abi\unique_ptr_destruction_order.pass.cpp -v
> llvm-lit.py: C:\Dev\STL\llvm-project\libcxx\utils\libcxx\test\config.py:19: note: (llvm-libc++-shared-clangcl.cfg.in) Using %{cxx} substitution: ''C:/Program Files/Microsoft Visual Studio/2022/Preview/VC/Tools/Llvm/x64/bin/clang-cl.exe''
> llvm-lit.py: C:\Dev\STL\llvm-project\libcxx\utils\libcxx\test\config.py:19: note: (llvm-libc++-shared-clangcl.cfg.in) Using %{flags} substitution: '--driver-mode=g++ --target=x86_64-pc-windows-msvc'
> llvm-lit.py: C:\Dev\STL\llvm-project\libcxx\utils\libcxx\test\config.py:19: note: (llvm-libc++-shared-clangcl.cfg.in) Using %{compile_flags} substitution: '-nostdinc++ -I %{include} -I %{target-include} -I %{libcxx}/test/support -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -DNOMINMAX -std=c++2b -Werror -Wall -Wctad-maybe-unsupported -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-noexcept-type -Wno-atomic-alignment -Wno-user-defined-literals -Wno-tautological-compare -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -Wdeprecated-copy -Wdeprecated-copy-dtor -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -D_LIBCPP_ENABLE_EXPERIMENTAL -D_LIBCPP_DISABLE_AVAILABILITY -Werror=thread-safety -Wuser-defined-warnings -DTEST_WINDOWS_DLL'
> llvm-lit.py: C:\Dev\STL\llvm-project\libcxx\utils\libcxx\test\config.py:19: note: (llvm-libc++-shared-clangcl.cfg.in) Using %{link_flags} substitution: '-llibc++experimental -nostdlib -L %{lib} -lc++ -lmsvcrt -lmsvcprt -loldnames'
> llvm-lit.py: C:\Dev\STL\llvm-project\libcxx\utils\libcxx\test\config.py:19: note: (llvm-libc++-shared-clangcl.cfg.in) Using %{exec} substitution: '%{executor} --execdir %T --env PATH=%{lib} -- '
> llvm-lit.py: C:\Dev\STL\llvm-project\libcxx\utils\libcxx\test\config.py:19: note: (llvm-libc++-shared-clangcl.cfg.in) All available features: no-filesystem, buildhost=win32, clang-15.0, target=x86_64-pc-windows-msvc, stdlib=libc++, stdlib=llvm-libc++, locale.fr_CA.ISO8859-1, -faligned-allocation, locale.zh_CN.UTF-8, locale.fr_FR.UTF-8, buildhost=windows, clang-15, clang-15.0.1, -fsized-deallocation, locale.en_US.UTF-8, clang, executor-has-no-bash, libcpp-abi-version=1, msvc-19.36, win32-broken-utf8-wchar-ctype, diagnose-if-support, windows, fdelayed-template-parsing, c++2b, thread-safety, objective-c++, c++experimental, windows-dll, long_tests, msvc-19, has-fblocks, locale.ja_JP.UTF-8, verify-support, locale.ru_RU.UTF-8, has-fconstexpr-steps, msvc
> -- Testing: 1 tests, 1 workers --
> PASS: llvm-libc++-shared-clangcl.cfg.in :: libcxx/memory/trivial_abi/unique_ptr_destruction_order.pass.cpp (1 of 1)
> 
> Testing Time: 5.96s
>   Passed: 1
> ```
I can add

```
Base(const Base&) = default;
Base& operator=(const Base&) = delete;
```
It seems it works: https://gcc.godbolt.org/z/6nEGfffEj


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144775/new/

https://reviews.llvm.org/D144775



More information about the libcxx-commits mailing list