[Dune-devel] convert `enum` to `static const int`

Jö Fahlke jorrit at jorrit.de
Wed Sep 20 15:23:42 CEST 2017


Am Mi, 20. Sep 2017, 13:58:41 +0200 schrieb Ansgar Burchardt:
> it looks like GCC has new warnings:
> 
>     ../dune/grid/test/checkintersectionit.hh:599:58: warning:
>     comparison between ‘enum Dune::Grid<[...]>::<unnamed>’
>     and ‘enum Dune::Grid<[...]>::<unnamed>’ [-Wenum-compare]
> 
> for the expression
> 
>     GridType::dimension == GridType::dimensionworld
> 
> Is there any downside to changing every constant that is currently a
> `enum` to a `static const int`?  (Minus deciding on the signedness, but
> that is unrelated to the `enum` -> `static const` conversion.)

It should probably be `constexpr`, not `const`, but other than that using
either `int` or `unsigned` is probably preferrable now.  Of course, then it is
_all_ about the signedness, because that is a problem that you did not have
with pure enums (or at least, it wasn't aggressively warned about).

Oh, and: `static constexpr` (or `static const`) variables are lvalues, while
enumerators were prvalues.  That means we need to define them (in addition to
initializing them) without violating the ODR.  Otherwise expressions like
`std::min(GridType::dimension, 2)` can produce linker errors.

Regards,
Jö.

-- 
Jorrit (Jö) Fahlke, Institute for Computational und Applied Mathematics,
University of Münster, Orleans-Ring 10, D-48149 Münster
Tel: +49 251 83 35146 Fax: +49 251 83 32729

If you receive something that says "Send this to everyone you know,"
pretend you don't know me.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.dune-project.org/pipermail/dune-devel/attachments/20170920/2bdeb87e/attachment.sig>


More information about the Dune-devel mailing list