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

Steffen Müthing steffen.muething at iwr.uni-heidelberg.de
Wed Sep 20 15:37:29 CEST 2017


> Am 20.09.2017 um 15:23 schrieb Jö Fahlke <jorrit at jorrit.de>:
> 
> 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.

That’s not a problem with "static constexpr" members, at least up to C++17. I’m
not entirely sure about the situation with C++17, but there adding an "inline" should
fix the problem (there’s a macro DUNE_INLINE_VARIABLE for that purpose).

That leaves the problem of signedness. As a lot of template parameters use int for
the dimension, we should probably go for a signed type, but I wonder if that might
be the final straw to introduce a dim_t in Dune.

Steffen

> 
> 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.
> _______________________________________________
> Dune-devel mailing list
> Dune-devel at lists.dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune-devel

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: Message signed with OpenPGP
URL: <https://lists.dune-project.org/pipermail/dune-devel/attachments/20170920/4d423d8b/attachment.sig>


More information about the Dune-devel mailing list