Skip to content

Commit

Permalink
Fix warnings for operator precedence disambiguation [-Wparentheses]
Browse files Browse the repository at this point in the history
Fixes the following GCC 5 warnings:
```
core/io/resource_format_binary.cpp:1721:29: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
core/typedefs.h:108:24: warning: suggest parentheses around comparison in operand of '!=' [-Wparentheses]
editor/plugins/spatial_editor_plugin.cpp:2202:58: warning: suggest parentheses around comparison in operand of '!=' [-Wparentheses]
editor/plugins/spatial_editor_plugin.cpp:5002:12: warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]
main/input_default.cpp:346:59: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
main/input_default.cpp:348:60: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
main/input_default.cpp:579:57: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
modules/gridmap/grid_map_editor_plugin.cpp:613:14: warning: suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]
modules/theora/video_stream_theora.cpp:335:34: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
modules/theora/video_stream_theora.cpp:336:35: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
modules/visual_script/visual_script_property_selector.cpp:215:38: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
scene/gui/rich_text_label.cpp:424:84: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
scene/gui/rich_text_label.cpp:512:80: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
scene/gui/scroll_container.cpp:173:36: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
scene/gui/scroll_container.cpp:173:86: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
scene/gui/tree.cpp:1419:98: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
```
  • Loading branch information
akien-mga committed Sep 27, 2018
1 parent 2b08435 commit d8b30d4
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 37 deletions.
2 changes: 1 addition & 1 deletion core/io/resource_format_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@ void ResourceFormatSaverBinaryInstance::save_unicode_string(FileAccess *f, const

CharString utf8 = p_string.utf8();
if (p_bit_on_len) {
f->store_32(utf8.length() + 1 | 0x80000000);
f->store_32((utf8.length() + 1) | 0x80000000);
} else {
f->store_32(utf8.length() + 1);
}
Expand Down
4 changes: 2 additions & 2 deletions core/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ T *_nullptr() {
/** Generic ABS function, for math uses please use Math::abs */

#ifndef ABS
#define ABS(m_v) ((m_v < 0) ? (-(m_v)) : (m_v))
#define ABS(m_v) (((m_v) < 0) ? (-(m_v)) : (m_v))
#endif

#ifndef SGN
#define SGN(m_v) ((m_v < 0) ? (-1.0) : (+1.0))
#define SGN(m_v) (((m_v) < 0) ? (-1.0) : (+1.0))
#endif

#ifndef MIN
Expand Down
21 changes: 9 additions & 12 deletions editor/plugins/spatial_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2199,7 +2199,7 @@ void SpatialEditorViewport::_notification(int p_what) {

bool shrink = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_HALF_RESOLUTION));

if (shrink != viewport_container->get_stretch_shrink() > 1) {
if (shrink != (viewport_container->get_stretch_shrink() > 1)) {
viewport_container->set_stretch_shrink(shrink ? 2 : 1);
}

Expand Down Expand Up @@ -4979,32 +4979,29 @@ void SpatialEditor::_unhandled_key_input(Ref<InputEvent> p_event) {
if (!k->is_pressed())
return;

if (ED_IS_SHORTCUT("spatial_editor/tool_select", p_event))
if (ED_IS_SHORTCUT("spatial_editor/tool_select", p_event)) {
_menu_item_pressed(MENU_TOOL_SELECT);

else if (ED_IS_SHORTCUT("spatial_editor/tool_move", p_event))
} else if (ED_IS_SHORTCUT("spatial_editor/tool_move", p_event)) {
_menu_item_pressed(MENU_TOOL_MOVE);

else if (ED_IS_SHORTCUT("spatial_editor/tool_rotate", p_event))
} else if (ED_IS_SHORTCUT("spatial_editor/tool_rotate", p_event)) {
_menu_item_pressed(MENU_TOOL_ROTATE);

else if (ED_IS_SHORTCUT("spatial_editor/tool_scale", p_event))
} else if (ED_IS_SHORTCUT("spatial_editor/tool_scale", p_event)) {
_menu_item_pressed(MENU_TOOL_SCALE);
else if (ED_IS_SHORTCUT("spatial_editor/snap_to_floor", p_event))
} else if (ED_IS_SHORTCUT("spatial_editor/snap_to_floor", p_event)) {
snap_selected_nodes_to_floor();

else if (ED_IS_SHORTCUT("spatial_editor/local_coords", p_event))
} else if (ED_IS_SHORTCUT("spatial_editor/local_coords", p_event)) {
if (are_local_coords_enabled()) {
_menu_item_toggled(false, MENU_TOOL_LOCAL_COORDS);
} else {
_menu_item_toggled(true, MENU_TOOL_LOCAL_COORDS);
}
else if (ED_IS_SHORTCUT("spatial_editor/snap", p_event))
} else if (ED_IS_SHORTCUT("spatial_editor/snap", p_event)) {
if (is_snap_enabled()) {
_menu_item_toggled(false, MENU_TOOL_USE_SNAP);
} else {
_menu_item_toggled(true, MENU_TOOL_USE_SNAP);
}
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions main/input_default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ void InputDefault::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool
button_event->set_pressed(st->is_pressed());
button_event->set_button_index(BUTTON_LEFT);
if (st->is_pressed()) {
button_event->set_button_mask(mouse_button_mask | (1 << BUTTON_LEFT - 1));
button_event->set_button_mask(mouse_button_mask | (1 << (BUTTON_LEFT - 1)));
} else {
button_event->set_button_mask(mouse_button_mask & ~(1 << BUTTON_LEFT - 1));
button_event->set_button_mask(mouse_button_mask & ~(1 << (BUTTON_LEFT - 1)));
}

_parse_input_event_impl(button_event, true);
Expand Down Expand Up @@ -576,7 +576,7 @@ void InputDefault::ensure_touch_mouse_raised() {
button_event->set_global_position(mouse_pos);
button_event->set_pressed(false);
button_event->set_button_index(BUTTON_LEFT);
button_event->set_button_mask(mouse_button_mask & ~(1 << BUTTON_LEFT - 1));
button_event->set_button_mask(mouse_button_mask & ~(1 << (BUTTON_LEFT - 1)));

_parse_input_event_impl(button_event, true);
}
Expand Down
14 changes: 8 additions & 6 deletions modules/gridmap/grid_map_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,29 +597,31 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu
if (mb->get_button_index() == BUTTON_LEFT) {

if (input_action == INPUT_DUPLICATE) {

//paste
_duplicate_paste();
input_action = INPUT_NONE;
_update_duplicate_indicator();
} else if (mb->get_shift()) {
input_action = INPUT_SELECT;
} else if (mb->get_command())
} else if (mb->get_command()) {
input_action = INPUT_COPY;
else {
} else {
input_action = INPUT_PAINT;
set_items.clear();
}
} else if (mb->get_button_index() == BUTTON_RIGHT)
} else if (mb->get_button_index() == BUTTON_RIGHT) {
if (input_action == INPUT_DUPLICATE) {

input_action = INPUT_NONE;
_update_duplicate_indicator();
} else if (mb->get_shift()) {
input_action = INPUT_ERASE;
set_items.clear();
} else
} else {
return false;
}
} else {
return false;
}

return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true);
} else {
Expand Down
4 changes: 2 additions & 2 deletions modules/theora/video_stream_theora.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) {

int w;
int h;
w = (ti.pic_x + ti.frame_width + 1 & ~1) - (ti.pic_x & ~1);
h = (ti.pic_y + ti.frame_height + 1 & ~1) - (ti.pic_y & ~1);
w = ((ti.pic_x + ti.frame_width + 1) & ~1) - (ti.pic_x & ~1);
h = ((ti.pic_y + ti.frame_height + 1) & ~1) - (ti.pic_y & ~1);
size.x = w;
size.y = h;

Expand Down
11 changes: 4 additions & 7 deletions modules/visual_script/visual_script_property_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,14 @@ void VisualScriptPropertySelector::_update_search() {
if (type_filter.size() && type_filter.find(E->get().type) == -1)
continue;

// capitalize() also converts underscore to space, we'll match again both possible styles
String get_text_raw = String(vformat(TTR("Get %s"), E->get().name));
String get_text = get_text_raw.capitalize();

String set_text_raw = String(vformat(TTR("Set %s"), E->get().name));
String set_text = set_text_raw.capitalize();
String input = search_box->get_text().capitalize();
if (input == String() ||
get_text_raw.findn(input) != -1 ||
get_text.findn(input) != -1) {

if (input == String() || get_text_raw.findn(input) != -1 || get_text.findn(input) != -1) {
TreeItem *item = search_options->create_item(category ? category : root);
item->set_text(0, get_text);
item->set_metadata(0, E->get().name);
Expand All @@ -211,9 +210,7 @@ void VisualScriptPropertySelector::_update_search() {
item->set_metadata(2, connecting);
}

if (input == String() ||
set_text_raw.findn(input) != -1 &&
set_text.findn(input) != -1) {
if (input == String() || set_text_raw.findn(input) != -1 || set_text.findn(input) != -1) {
TreeItem *item = search_options->create_item(category ? category : root);
item->set_text(0, set_text);
item->set_metadata(0, E->get().name);
Expand Down
4 changes: 2 additions & 2 deletions scene/gui/rich_text_label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &

int cw = 0;

bool visible = visible_characters < 0 || p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - line_descent - line_ascent, line_ascent + line_descent);
bool visible = visible_characters < 0 || (p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - line_descent - line_ascent, line_ascent + line_descent));
if (visible)
line_is_blank = false;

Expand Down Expand Up @@ -509,7 +509,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &

ENSURE_WIDTH(img->image->get_width());

bool visible = visible_characters < 0 || p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - font->get_descent() - img->image->get_height(), img->image->get_height());
bool visible = visible_characters < 0 || (p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - font->get_descent() - img->image->get_height(), img->image->get_height()));
if (visible)
line_is_blank = false;

Expand Down
3 changes: 2 additions & 1 deletion scene/gui/scroll_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "scroll_container.h"
#include "core/os/os.h"

bool ScrollContainer::clips_input() const {

return true;
Expand Down Expand Up @@ -170,7 +171,7 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
Vector2 motion = Vector2(mm->get_relative().x, mm->get_relative().y);
drag_accum -= motion;

if (beyond_deadzone || scroll_h && Math::abs(drag_accum.x) > deadzone || scroll_v && Math::abs(drag_accum.y) > deadzone) {
if (beyond_deadzone || (scroll_h && Math::abs(drag_accum.x) > deadzone) || (scroll_v && Math::abs(drag_accum.y) > deadzone)) {
if (!beyond_deadzone) {
propagate_notification(NOTIFICATION_SCROLL_BEGIN);
emit_signal("scroll_started");
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2

while (c) {

if (cache.draw_relationship_lines == 1 && (c->get_parent() != root || c->get_parent() == root && !hide_root)) {
if (cache.draw_relationship_lines == 1 && (c->get_parent() != root || !hide_root)) {
int root_ofs = children_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin);
int parent_ofs = p_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin);
Point2i root_pos = Point2i(root_ofs, children_pos.y + label_h / 2) - cache.offset + p_draw_ofs;
Expand Down

0 comments on commit d8b30d4

Please sign in to comment.