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

gcc 9.1 -Wdeprecated-copy warnings for implicit copy constructor and assignment operator #161

Closed
zmajeed opened this issue Jul 2, 2019 · 4 comments

Comments

@zmajeed
Copy link

zmajeed commented Jul 2, 2019

Building TBB 2019 Update 8 with make test with gcc 9.1 and -Wextra generates 1,320 -Wdeprecated-copy warnings. The other warnings are 12 -Wmissing-attributes and 6 -Wclass-memaccess (PR #157).

The -Wdeprecated-copy warning was announced in https://www.gnu.org/software/gcc/gcc-9/changes.html. It is documented at https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wdeprecated-copy

There are two types of causes for -Wdeprecated-copy warnings in TBB

  1. An assignment operator is written without a copy constructor, or a copy constructor is written without an assignment operator

  2. An assignment operator or copy constructor is made private without defining the other

Most of the causes of type 1 can be fixed by declaring the missing function as defaulted

For example:

src/test/harness_allocator.h:447:32: warning: implicitly-declared 'constexpr tbb::atomic<long unsigned int>::atomic(const tbb::atomic<long unsigned int>&)' is deprecated [-Wdeprecated-copy]
  447 |         , max_items(a.max_items)
      |                                ^
In file included from src/test/harness_allocator.h:39,
                 from src/test/test_ScalableAllocator.cpp:32:
include/tbb/atomic.h:422:24: note: because 'tbb::atomic<long unsigned int>' has user-provided 'tbb::atomic<long unsigned int>& tbb::atomic<long unsigned int>::operator=(const tbb::atomic<long unsigned int>&)'
  422 |             atomic<T>& operator=( const atomic<T>& rhs ) {store_with_release(rhs); return *this;}   \
      |                        ^~~~~~~~

is fixed by adding:

// include/tbb/atomic.h

constexpr atomic( const atomic<T>& rhs ) = default;

Causes of type 2 can be fixed by replacing the private declaration with a deleted declaration

For example:

src/test/test_atomic.cpp:1504:7: warning: implicitly-declared 'constexpr NoAssign::NoAssign(const NoAssign&)' is deprecated [-Wdeprecated-copy]
 1504 | class DekkerArbitrationBody : NoAssign, Harness::NoAfterlife {
      |       ^~~~~~~~~~~~~~~~~~~~~
In file included from src/test/test_atomic.cpp:280:
src/test/harness.h:449:10: note: because 'NoAssign' has user-provided 'void NoAssign::operator=(const NoAssign&)'
  449 |     void operator=( const NoAssign& );
      |          ^~~~~~~~

is fixed by replacing the private operator= above with:

// src/test/harness.h

void operator=( const NoAssign& ) = delete;

There is one example of type 1 that is a bit more complicated to fix

src/test/test_concurrent_queue.cpp:588:12: warning: implicitly-declared 'tbb::strict_ppl::internal::concurrent_queue_iterator<tbb::strict_ppl::concurrent_queue<Bar, tbb::cache_aligned_allocator<Bar> >, const Bar>::concurrent_queue_iterator(const tbb::strict_ppl::internal::concurrent_queue_iterator<tbb::strict_ppl::concurrent_queue<Bar, tbb::cache_aligned_allocator<Bar> >, const Bar>&)' is deprecated [-Wdeprecated-copy]
  588 |         CQ dst_queue(sqb, sqe);
      |            ^~~~~~~~~
In file included from include/tbb/concurrent_queue.h:20,
                 from src/test/test_concurrent_queue.cpp:19:
include/tbb/internal/_concurrent_queue_impl.h:767:32: note: because 'tbb::strict_ppl::internal::concurrent_queue_iterator<tbb::strict_ppl::concurrent_queue<Bar, tbb::cache_aligned_allocator<Bar> >, const Bar>' has user-provided 'tbb::strict_ppl::internal::concurrent_queue_iterator<Container, Value>& tbb::strict_ppl::internal::concurrent_queue_iterator<Container, Value>::operator=(const tbb::strict_ppl::internal::concurrent_queue_iterator<Container, Value>&) [with Container = tbb::strict_ppl::concurrent_queue<Bar, tbb::cache_aligned_allocator<Bar> >; Value = const Bar]'
  767 |     concurrent_queue_iterator& operator=( const concurrent_queue_iterator& other ) {
      |                                ^~~~~~~~

This is caused by a constructor that doubles as a copy constructor or a converting constructor

// include/tbb/internal/_concurrent_queue_impl.h

template<typename Container, typename Value>
class concurrent_queue_iterator: public concurrent_queue_iterator_base_v3<typename tbb_remove_cv<Value>::type>,
        public std::iterator<std::forward_iterator_tag,Value> {

/** If Value==Container::value_type, then this routine is the copy constructor.
     If Value==const Container::value_type, then this routine is a conversion constructor. */

  concurrent_queue_iterator( const concurrent_queue_iterator<Container,typename Container::value_type>& other ) :
    concurrent_queue_iterator_base_v3<typename tbb_remove_cv<Value>::type>(other) {}

//! Iterator assignment
  concurrent_queue_iterator& operator=( const concurrent_queue_iterator& other ) {
    this->assign(other);
    return *this;
  }

};

The warning occurs when Value is different from Container::value_type. In this case the constructor above turns into a converting constructor and there is no user-defined copy constructor. The assignment operator is defined so the warning is emitted for the compiler-generated copy constructor.

I've fixed this by defining a copy constructor and turning the converting constructor into a template function that is enabled only when Value is different from Container::value_type

The three types of changes are in separate pull requests referencing this issue

@alexey-katranov
Copy link
Contributor

Thank you for the report! We are working on the issues and we will fix them in one of the future releases.

@zmajeed
Copy link
Author

zmajeed commented Jul 3, 2019

I've closed my PRs since I did not know C++03 is still supported. Is there an EOL plan for C++03 and moving to C++11?

@alexey-katranov
Copy link
Contributor

We are considering this option to drop C++03 support but there is no final decision yet.

@ivankochin
Copy link
Contributor

@zmajeed , these warnings have been fixed in the TBB2020 U9 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants