Skip to content

Explicitly default operator= for Vec<T, n>#14934

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
StefanBruens:silence_assignment_operator_warning
Jun 30, 2019
Merged

Explicitly default operator= for Vec<T, n>#14934
opencv-pushbot merged 1 commit intoopencv:3.4from
StefanBruens:silence_assignment_operator_warning

Conversation

@StefanBruens
Copy link
Copy Markdown
Contributor

Due to the explicitly declared copy constructor Vec<T, n>::Vec(Vec <T,n>&)
GCC 9 warns if there is no assignment operator, as having one typically
requires the other (rule-of-three, constructor/desctructor/assginment).

As the values are just a plain array the default assignment operator does
the right thing. Tell the compiler explicitly to default it.

resolves #14933

const _Tp& operator ()(int i) const;
_Tp& operator ()(int i);

constexpr Vec<_Tp, cn>& operator=(const Vec<_Tp, cn>& rhs) = default;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. #ifdef CV_CXX11 (due = default)
  2. Do we really need constexpr here? if so, please use CV_CONSTEXPR instead. IMHO, it is better to remove contexpr here completely (see Windows builder warnings)
  3. What is about move assignment operator (Vec<_Tp, cn>&& rhs)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to:
http://eel.is/c++draft/dcl.fct.def.default#3

If a function is explicitly defaulted on its first declaration, it is implicitly considered to be constexpr if the implicit declaration would be.

As it is implicit constexpr, the "constexpr" can be removed without loss for the relevant cases (you can of course have a Vec<Foo, 1>, where Foo would lead to non-constexpr).

move assignments and constructors are implicitly "deleted" already, as there is a user-declared copy constructor. Both would be pointless for an array on the stack anyway (you can not efficiently move/swap these, not anymore than a memcpy would do).

Due to the explicitly declared copy constructor Vec<T, n>::Vec(Vec <T,n>&)
GCC 9 warns if there is no assignment operator, as having one typically
requires the other (rule-of-three, constructor/desctructor/assginment).

As the values are just a plain array the default assignment operator does
the right thing. Tell the compiler explicitly to default it.

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
@StefanBruens StefanBruens force-pushed the silence_assignment_operator_warning branch from 35e6a22 to e9a2e66 Compare June 29, 2019 20:26
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

@opencv-pushbot opencv-pushbot merged commit e9a2e66 into opencv:3.4 Jun 30, 2019
opencv-pushbot pushed a commit that referenced this pull request Jun 30, 2019
@StefanBruens StefanBruens deleted the silence_assignment_operator_warning branch July 2, 2019 10:50
@alalek alalek mentioned this pull request Jul 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants