Skip to content

Fix lack of explicit operator= for warnings in clang 13+

Dave Moxey requested to merge dmoxey/nektar:fix/clang-implicit-assignment into master

Issue/feature addressed

This branch fixes #301 (closed) to add an explicit operator= to classes inside SimdLib to disable compiler warning.

Proposed solution

Presently SimdLib has the following default copy constructor, e.g. for scalar types:

    inline scalarT(const scalarT &rhs) = default;

This causes a warning (compiler error with -Werror):

/nektar++/library/LibUtilities/SimdLib/scalar.hpp:124:12: error: definition of implicit copy assignment 
operator for 'scalarT<unsigned long long, void>' is deprecated because it has a user-declared 
copy constructor [-Werror,-Wdeprecated-copy]

The solution is to add appropriate operator= functions, e.g.:

    inline scalarT<T> &operator=(const scalarT<T> &rhs) = default;

A new CI job has been added to compile with clang and capture warnings for future code.

Implementation

The solution above seems adequate. An alternative is to remove the original copy constructor = default. It seems that the presence of this triggers this warning, even though with or without the line you'll get a copy constructor for this class. However adding operator= is more explicit and probably the right approach.

Tests

Checklist

  • Functions and classes, or changes to them, are documented.
  • Changelog is updated.
  • Suitable tests added for new functionality.
  • Contributed code is correctly formatted. (See the contributing guidelines).
  • License added to any new files.
  • No extraneous files have been added (e.g. compiler output or test data files).

Warning

On the 19.07 the code formatting (code style) was standardised using clang-format, over the whole Nektar++ code. This means changes in your branch will conflict with formatting changes on the master branch. To resolve these conflicts , see #295 (closed)

Edited by Dave Moxey

Merge request reports