From: Daniel Arndt Date: Thu, 7 May 2020 21:18:14 +0000 (-0400) Subject: Silence gcc-10 warnings about invalid array accesses X-Git-Tag: v9.2.0-rc1~72^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F10065%2Fhead;p=dealii.git Silence gcc-10 warnings about invalid array accesses --- diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index a8d6dd3157..62e0f74b44 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -2391,9 +2391,14 @@ DEAL_II_CONSTEXPR inline DEAL_II_ALWAYS_INLINE Tensor<1, dim, typename ProductType::type> result; - result[0] = src1[1] * src2[2] - src1[2] * src2[1]; - result[1] = src1[2] * src2[0] - src1[0] * src2[2]; - result[2] = src1[0] * src2[1] - src1[1] * src2[0]; + // avoid compiler warnings + constexpr int s0 = 0 % dim; + constexpr int s1 = 1 % dim; + constexpr int s2 = 2 % dim; + + result[s0] = src1[s1] * src2[s2] - src1[s2] * src2[s1]; + result[s1] = src1[s2] * src2[s0] - src1[s0] * src2[s2]; + result[s2] = src1[s0] * src2[s1] - src1[s1] * src2[s0]; return result; } diff --git a/source/fe/fe_bernardi_raugel.cc b/source/fe/fe_bernardi_raugel.cc index 97113e5d36..de04ad99f0 100644 --- a/source/fe/fe_bernardi_raugel.cc +++ b/source/fe/fe_bernardi_raugel.cc @@ -177,7 +177,6 @@ FE_BernardiRaugel::initialize_support_points() } } -template class FE_BernardiRaugel<1>; template class FE_BernardiRaugel<2>; template class FE_BernardiRaugel<3>; diff --git a/source/grid/manifold_lib.cc b/source/grid/manifold_lib.cc index df41f41960..22203ef2d4 100644 --- a/source/grid/manifold_lib.cc +++ b/source/grid/manifold_lib.cc @@ -1171,20 +1171,25 @@ CylindricalManifold::push_forward_gradient( const Tensor<1, spacedim> intermediate = normal_direction * cosine + dxn * sine; + // avoid compiler warnings + constexpr int s0 = 0 % spacedim; + constexpr int s1 = 1 % spacedim; + constexpr int s2 = 2 % spacedim; + // derivative w.r.t the radius - derivatives[0][0] = intermediate[0]; - derivatives[1][0] = intermediate[1]; - derivatives[2][0] = intermediate[2]; + derivatives[s0][s0] = intermediate[s0]; + derivatives[s1][s0] = intermediate[s1]; + derivatives[s2][s0] = intermediate[s2]; // derivatives w.r.t the angle - derivatives[0][1] = -normal_direction[0] * sine + dxn[0] * cosine; - derivatives[1][1] = -normal_direction[1] * sine + dxn[1] * cosine; - derivatives[2][1] = -normal_direction[2] * sine + dxn[2] * cosine; + derivatives[s0][s1] = -normal_direction[s0] * sine + dxn[s0] * cosine; + derivatives[s1][s1] = -normal_direction[s1] * sine + dxn[s1] * cosine; + derivatives[s2][s1] = -normal_direction[s2] * sine + dxn[s2] * cosine; // derivatives w.r.t the direction of the axis - derivatives[0][2] = direction[0]; - derivatives[1][2] = direction[1]; - derivatives[2][2] = direction[2]; + derivatives[s0][s2] = direction[s0]; + derivatives[s1][s2] = direction[s1]; + derivatives[s2][s2] = direction[s2]; return derivatives; }