Fix a bug in the constructor if Filter_circulator

The Intel Compiler 14.0, with -O2 or -O3, triggers a bug in the old
version of the code. After the construction of the filtered circulator,
`test(*this)` was not guaranteed. I am not sure if the bug is in the
code or in the compiler, but the constructor was an ugly piece of
code! (*this) was used in the body of the constructor in non obvious
ways. An object is reputed constructed once the internalizers are
evaluated, as far as I know, so probably the previous version of the
code was valid. However, that sound strange to copy an object inside the
body of the constructor of that object. Maybe that confused the
compiler.

Anyway, I have modified the implementation of that constructor in a
cleaner way, and I have added an assertion (that was failing with the
old implementation).
This commit is contained in:
Laurent Rineau 2014-01-09 14:15:45 +01:00
parent afd4cfbfef
commit 2c236ff01d
1 changed files with 10 additions and 7 deletions

View File

@ -52,19 +52,21 @@ public:
}
Filter_circulator(const Circ& c, const Pred& p=Pred())
: Circ(c), is_null(false), test(p)
: test(p)
{
if(test(static_cast<Circ&>(*this)))
Circ circ(c);
if(test(circ))
is_null=false;
else
{
Self end(*this);
Circ end(c);
do {
this->Circ::operator++();
} while( !test(static_cast<Circ&>(*this)) && (*this)!=end );
if((*this)==end)
is_null=true;
++circ;
} while( !test(circ) && end != circ );
is_null = (end == circ);
}
static_cast<Circ&>(*this) = circ;
CGAL_assertion(is_null || test(*this));
}
bool operator==( Nullptr_t ) const {
@ -87,6 +89,7 @@ public:
do {
this->Circ::operator++();
} while( !test(static_cast<Circ&>(*this)) );
CGAL_assertion(is_null || test(static_cast<Circ&>(*this)));
return *this;
}