Skip to content

Warning about missing base class initialisation in Tensor and TensorFixedSize

Summary

Gcc8.5 warns that base class Eigen::TensorBase<...> should be explicitly initialized in the copy constructor [-Wextra] in the constructors Tensor(const Self& other), TensorFixedSize(const Self& other), and TensorRef(const TensorRef& other).

Environment

  • Operating System : Linux
  • Architecture : x64
  • Eigen Version : 3.4.x latest git checkout
  • Compiler Version : Gcc8.5
  • Compile Flags : -O3 -march=native

Steps to reproduce

  1. perform a recent git checkout and run mkdir build && cd build && cmake .. && make cxx11_tensor_assign cxx11_tensor_custom_op cxx11_tensor_empty

What is the current bug behavior?

During compilation of cxx11_tensor_assign Gcc8.5 issues the following warning

unsupported/Eigen/CXX11/src/Tensor/Tensor.h:277:25: warning: base class 'class Eigen::TensorBase<Eigen::Tensor<int, 1>, 1>' should be explicitly initialized in the copy constructor [-Wextra]
     EIGEN_STRONG_INLINE Tensor(const Self& other)

During compilation of cxx11_tensor_custom_op Gcc8.5 issues the following warning

unsupported/Eigen/CXX11/src/Tensor/TensorRef.h:177:5: warning: base class 'class Eigen::TensorBase<Eigen::TensorRef<Eigen::Tensor<float, 2> >, 1>' should be explicitly initialized in the copy constructor [-Wextra]
     TensorRef(const TensorRef& other) : m_evaluator(other.m_evaluator) {

During compilation of cxx11_tensor_empty Gcc8.5 issues the following warning

unsupported/Eigen/CXX11/src/Tensor/TensorFixedSize.h:217:25: warning: base class 'class Eigen::TensorBase<Eigen::TensorFixedSize<float, Eigen::Sizes<0> >, 1>' should be explicitly initialized in the copy constructor [-Wextra]
     EIGEN_STRONG_INLINE TensorFixedSize(const Self& other)

What is the expected correct behavior?

I would expect that these warning should not be issued.

  • Have a plan to fix this issue.

The following quick fix makes the warnings disappear

Change the copy constructors as follows:

EIGEN_DEVICE_FUNC
    EIGEN_STRONG_INLINE Tensor(const Self& other)
      : Base(other), m_storage(other.m_storage)
    {
    }
EIGEN_DEVICE_FUNC
    EIGEN_STRONG_INLINE TensorFixedSize(const Self& other)
      : Base(other), m_storage(other.m_storage)
    {
    }
TensorRef(const TensorRef& other) 
      : TensorBase<TensorRef<PlainObjectType> >(other), m_evaluator(other.m_evaluator) {
      eigen_assert(m_evaluator->refCount() > 0);
      m_evaluator->incrRefCount();
    }

Remark: Since TensorRef is derived from TensorBase<TensorRef<PlainObjectType> > but its Base type is defined as follows

typedef typename PlainObjectType::Base Base;

with PlainObjectType being the template type of TensorRef a delegation of the form : Base(other) does not work here.