[Dune-devel] replace `enum { something = 42 }; ` with `constexpr static int something = 42; `

Ansgar Burchardt ansgar.burchardt at tu-dresden.de
Mon May 23 16:37:11 CEST 2022


Hi,

while building dune-grid (including tests) with gcc 11.3.0, I saw a
bunch of warnings like the following:

+---
| dune-grid/dune/grid/identitygrid/identitygridentity.hh:209:62: warning: arithmetic
| between different enumeration types
| ‘Dune::Grid<1, 1, double, Dune::YaspGridFamily<1, Dune::EquidistantCoordinates<double, 1> > >::<unnamed enum>’ and
| ‘Dune::Grid<1, 1, double, Dune::IdentityGridFamily<1, Dune::YaspGrid<1, Dune::EquidistantCoordinates<double, 1> > > >::<unnamed enum>’
| is deprecated [-Wdeprecated-enum-enum-conversion]
|   209 |     enum {CodimInHostGrid = GridImp::HostGridType::dimension - GridImp::dimension};
|       |                                                    ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
+---

The correct solution to me looks like no longer using `enum` here and
instead use `constexpr static int`.

Is there anything that speaks against this change?

If I remember correctly, in the past there were some issues that should
be resolved with C++17 (as `constexpr static` member variables are also
inline variables).

Ansgar




More information about the Dune-devel mailing list