[Dune] dune-grid does not compile when implementations of EntityPointer and Iterator are not interoperable

Carsten Gräser graeser at math.fu-berlin.de
Fri Apr 27 14:51:29 CEST 2012


Hi,
(I'm sorry Steffan, I sent my mail before I saw yours.)

Am 27.04.2012 14:09, schrieb Steffen Müthing:
> Hi Martin,
> 
> Am 27.04.2012 um 13:00 schrieb Martin Nolte:
> 
>> Hi Steffen,
>>
>> you are right, the cast operator is indeed deprecated in the 2.1 release branch. This would mean it should be gone by now. Unfortunately, we are close to a release and I would ask the release managers whether such a change would still be in order. Is anybody still using the deprecated cast operator?
> 
> Well, regarding the cast operator: It is one of the major roadblocks towards strict aliasing support, and AFAIK
> the only one that might be directly visible to users. Looking at the release, we have the following options:
unfortunately there are more major roadblocks, but they don't give
warnings with the current compilers and it seems they didn't produce
wrong code yet.

> 1) Completely remove the cast (perhaps with an optional configure flag to keep it one more round).
I'd remove it without any extra round.

> 2) Change the implementation to work correctly for non-interoperable types. This would make it possible for grid
>   implementors to selectively disable the cast for their grids, which might simplify implementations (see e.g. your
>   comment about the required memory layout of EntityPointer) and possibly save users from a bunch of ugly
>   problems, while still staying backward compatible.
In fact the present implementation was already to tolerant wrt the
memory layout. E.g. in SubGrid the EntityPointerImp is no longer
a base class for the IteratorImp but the interoperability check worked.

> 3) Leave everything as it is now.
> 
> If I had a vote, I would pick 1). Regarding 2) or 3), I simply don't know enough about the original intentions
> behind the current code, so that's up to the developers to decide.
> 
> I noticed a missing const in my patch, an updated version is attached.
> 
>>
>> For the casting problem, you might want to have a look at GeometryGrid's entity pointer (see dune/grid/geometrygrid/entitypointer.hh). Here, the entity pointer stores the host iterator (which could, e.g., be a leaf iterator). You can then derive your iterator from the entity pointer (with the correct iterator passed as template argument) and, thus, satisfy the interoperability desired by Dune::EntityPointer. Of course, this trick has some consequences:
>> (a) There is no guarantee that the code will work
>>   (but that holds for the cast in Dune::EntityPointer as well).
>> (b) The last member of your entity pointer must be the host iterator
>>   (which is the one actually casted by the reinterpret_cast).
>> Apart from that, the code seems to work wonderfully. I have to admit, though, that I never use the deprecated cast operator in my code.
> 
> That's what I do as well. The problem occured while I was trying to debug a problem where the compiler picked a wrong constructor
> and wanted to make sure that the constructor argument would not be casted using the reference cast operator.
In SubGrid we use a similar approach. We should also adapt IdentityGrid
accordingly. Its current implementation is inefficient and at the same
time more complicated then necessary.

Carsten

> 
> Steffen
> 
>>
>> Best,
>>
>> Martin
>>
>>
>> -- 
>> Dr. Martin Nolte <nolte at mathematik.uni-freiburg.de>
>>
>> Universität Freiburg                                   phone: +49-761-203-5630
>> Abteilung für angewandte Mathematik                    fax:   +49-761-203-5632
>> Hermann-Herder-Straße 10
>> 79104 Freiburg, Germany
> 
> Steffen Müthing
> Universität Stuttgart
> Institut für Parallele und Verteilte Systeme
> Universitätsstr. 38
> 70569 Stuttgart
> Tel: +49 711 685 88429
> Fax: +49 711 685 88340
> Email: steffen.muething at ipvs.uni-stuttgart.de
> 
> 
> 
> _______________________________________________
> Dune mailing list
> Dune at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune


-- 
----------------------------------------------------------------------
Dr. Carsten Gräser       | phone: +49-30 / 838-75349
Freie Universität Berlin | fax  : +49-30 / 838-54977
Institut für Mathematik  | email: graeser at math.fu-berlin.de
Arnimallee 6             |
14195 Berlin, Germany    | URL  : http://page.mi.fu-berlin.de/graeser
----------------------------------------------------------------------




More information about the Dune mailing list