URL:
  <http://gna.org/bugs/?19095>

                 Summary: gcc warning in src/pathfind/astarsearch.cpp
                 Project: Battle for Wesnoth
            Submitted by: kernigh
            Submitted on: Fri 02 Dec 2011 10:30:17 PM GMT
                Category: Bug
                Severity: 2 - Minor
                Priority: 5 - Normal
              Item Group:  None of the others
                  Status: None
                 Privacy: Public
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: trunk r52150
        Operating System: OpenBSD

    _______________________________________________________

Details:

I am attaching a patch to prevent a gcc warning in
src/pathfind/astarsearch.cpp. This is a bug because CMakeLists.txt puts
-Werror in the compiler flags, so every gcc warning becomes an error that
stops the compile.

I compiled trunk r512150 and used CMake 2.8.4. My system is OpenBSD 5.0,
amd64. My compiler is g++ (GCC) 4.2.1 20070719. The error is


[ 82%] Building CXX object
src/CMakeFiles/wesnoth-game.dir/pathfind/astarsearch.cpp.o
cc1plus: warnings being treated as errors
/usr/include/g++/bits/stl_algo.h: In function '_RandomAccessIterator
std::__find(_RandomAccessIterator, _RandomAccessIterator, const _Tp&,
std::random_access_iterator_tag) [with _RandomAccessIterator =
__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >,
_Tp = long unsigned int]':
/usr/include/g++/bits/stl_algo.h:327:   instantiated from '_InputIterator
std::find(_InputIterator, _InputIterator, const _Tp&) [with _InputIterator =
__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >,
_Tp = size_t]'
/home/kernigh/park/wesnoth-trunk/src/pathfind/astarsearch.cpp:223:  
instantiated from here
/usr/include/g++/bits/stl_algo.h:208: warning: comparison between signed and
unsigned integer expressions
/usr/include/g++/bits/stl_algo.h:327:   instantiated from '_InputIterator
std::find(_InputIterator, _InputIterator, const _Tp&) [with _InputIterator =
__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >,
_Tp = size_t]'
/home/kernigh/park/wesnoth-trunk/src/pathfind/astarsearch.cpp:223:  
instantiated from here
/usr/include/g++/bits/stl_algo.h:212: warning: comparison between signed and
unsigned integer expressions
/usr/include/g++/bits/stl_algo.h:216: warning: comparison between signed and
unsigned integer expressions
/usr/include/g++/bits/stl_algo.h:220: warning: comparison between signed and
unsigned integer expressions
/usr/include/g++/bits/stl_algo.h:228: warning: comparison between signed and
unsigned integer expressions
/usr/include/g++/bits/stl_algo.h:232: warning: comparison between signed and
unsigned integer expressions
/usr/include/g++/bits/stl_algo.h:236: warning: comparison between signed and
unsigned integer expressions
*** Error code 1

Stop in /home/kernigh/park/wesnoth-trunk/build (line 583 of
src/CMakeFiles/wesnoth-game.dir/build.make).
*** Error code 1

Stop in /home/kernigh/park/wesnoth-trunk/build (line 342 of
CMakeFiles/Makefile2).
*** Error code 1

Stop in /home/kernigh/park/wesnoth-trunk/build (line 133 of Makefile).


The offender is line 223 of astarsearch.cpp, which is


                                std::push_heap(pq.begin(), 
std::find(pq.begin(), pq.end(),
index(locs[i])) + 1, node_comp);


In this code, pq is a vector<int>, but index() returns a size_t. The code in
/usr/include/g++/bits/stl_algo.h seems to compare int == size_t. Because int
is signed and size_t is unsigned, there is "comparison between signed and
unsigned integer expressions".

My patch uses static_cast<int>(index(locs[i])) so that the comparisons are
int == int and the compile succeeds.



    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Fri 02 Dec 2011 10:30:17 PM GMT  Name: astar-warning.diff  Size: 619B  
By: kernigh
astar-warning.diff: prevent gcc warning
<http://gna.org/bugs/download.php?file_id=14633>

    _______________________________________________________

Reply to this item at:

  <http://gna.org/bugs/?19095>

_______________________________________________
  Message sent via/by Gna!
  http://gna.org/


_______________________________________________
Wesnoth-bugs mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-bugs

Reply via email to