Started reviewing the code. Have one diff comment so far. Will continue later 
tonight.

Diff comments:

> 
> === added file 'src/logic/map_objects/draw_text.h'
> --- src/logic/map_objects/draw_text.h 1970-01-01 00:00:00 +0000
> +++ src/logic/map_objects/draw_text.h 2018-11-24 07:43:42 +0000
> @@ -0,0 +1,39 @@
> +/*
> + * Copyright (C) 2006-2018 by the Widelands Development Team
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> + *
> + */
> +
> +#ifndef WL_LOGIC_MAP_OBJECTS_DRAW_TEXT_H
> +#define WL_LOGIC_MAP_OBJECTS_DRAW_TEXT_H
> +
> +enum class TextToDraw {
> +     kNone = 0,
> +     kCensus = 1,
> +     kStatistics = 2,
> +};
> +
> +inline TextToDraw operator|(TextToDraw a, TextToDraw b) {
> +     return static_cast<TextToDraw>(static_cast<int>(a) | 
> static_cast<int>(b));
> +}
> +inline TextToDraw operator&(TextToDraw a, TextToDraw b) {
> +     return static_cast<TextToDraw>(static_cast<int>(a) & 
> static_cast<int>(b));
> +}
> +inline TextToDraw operator~(TextToDraw a) {
> +     return static_cast<TextToDraw>(~static_cast<int>(a));

That might be dangerous. The result of the ~ is out of the range of the enum, 
and - as far as I could find out - that means that the actual result is 
unspecified, i.e., compilers might do unexpected things.

I coudn't actually find a lot where this is explicitly mentioned, but it's 
mentioned for example in 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2347.pdf (page 12, 
first paragraph) which I think was the latest proposal for enum class which 
eventually got accepted.

A safe version would be
static_cast<TextToDraw>(3 & ~static_cast<int>(a))
althought this "3" would have to be adjusted if at some point the enum gets 
extended.
Or maybe we could just not define this operator. Simple checks can also easily 
be done without it. (And generally there shouldn't be any need for elobrate 
expressions where the operator would come in handy.)

> +}
> +
> +#endif  // end of include guard: WL_LOGIC_MAP_OBJECTS_DRAW_TEXT_H


-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1796364-blinking-buildings/+merge/359348
Your team Widelands Developers is requested to review the proposed merge of 
lp:~widelands-dev/widelands/bug-1796364-blinking-buildings into lp:widelands.

_______________________________________________
Mailing list: https://launchpad.net/~widelands-dev
Post to     : widelands-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~widelands-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to