Opened 3 years ago

Closed 3 years ago

#1104 closed defect (fixed)

error: conversion from 'std::size_t' {aka 'long long unsigned int'} to 'long int' may change value [-Werror=conversion]

Reported by: robe Owned by: mdavis
Priority: major Milestone: 3.10.0
Component: Default Version: main
Severity: Unassigned Keywords:
Cc:

Description (last modified by strk)

Seeing this error on winnie's gcc 8.1 64-bit builds. Strk says he is seeing the same errors. This is with cmake 3.15.4. I'm going to up it and see if things improve.

-- GEOS: Build type: Release
-- GEOS: Run-time output: E:/jenkins/geos/branches/build64cmake3.10/bin
-- GEOS: Archives output: E:/jenkins/geos/branches/build64cmake3.10/lib
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Check for working C compiler: C:/ming64gcc81/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/ming64gcc81/mingw64/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/ming64gcc81/mingw64/bin/g++.exe
-- Check for working CXX compiler: C:/ming64gcc81/mingw64/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- GEOS: Version 3.10.0dev
-- GEOS: C API Version 1.15.0
-- GEOS: JTS port 1.17.0
-- GEOS: Require C++11
-- GEOS: Function inlining ENABLED
-- GEOS: Developer mode ENABLED
-- GEOS: Configured 'dist' target
-- GEOS: Configured 'distcheck' target
-- Configuring done
-- Generating done

[ 98%] [32mBuilding CXX object util/geosop/CMakeFiles/geosop.dir/GeosOp.cpp.obj[0m
E:/jenkins/geos/branches/3.10cmake/util/geosop/GeosOp.cpp: In function 'bool isWKTLiteral(std::__cxx11::string)':
E:/jenkins/geos/branches/3.10cmake/util/geosop/GeosOp.cpp:171:32: error: conversion from 'std::__iterator_traits<__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >, void>::difference_type' {aka 'long long int'} to 'long int' may change value [-Werror=conversion]
     long numLParen = std::count(s.begin(), s.end(), '(');
                      ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
E:/jenkins/geos/branches/3.10cmake/util/geosop/GeosOp.cpp: In member function 'void GeosOp::executeUnary(GeomFunction*)':
E:/jenkins/geos/branches/3.10cmake/util/geosop/GeosOp.cpp:355:47: error: conversion from 'std::size_t' {aka 'long long unsigned int'} to 'long int' may change value [-Werror=conversion]
         vertexCount += geomA[i]->getNumPoints();
                                               ^
E:/jenkins/geos/branches/3.10cmake/util/geosop/GeosOp.cpp: In member function 'void GeosOp::executeBinary(GeomFunction*)':
E:/jenkins/geos/branches/3.10cmake/util/geosop/GeosOp.cpp:366:52: error: conversion from 'std::size_t' {aka 'long long unsigned int'} to 'long int' may change value [-Werror=conversion]
             vertexCount += geomA[ia]->getNumPoints();
                                                    ^
E:/jenkins/geos/branches/3.10cmake/util/geosop/GeosOp.cpp:367:52: error: conversion from 'std::size_t' {aka 'long long unsigned int'} to 'long int' may change value [-Werror=conversion]
             vertexCount += geomB[ib]->getNumPoints();
                                                    ^
At global scope:
cc1plus.exe: error: unrecognized command line option '-Wno-unknown-warning-option' [-Werror]
cc1plus.exe: all warnings being treated as errors
make[2]: *** [util/geosop/CMakeFiles/geosop.dir/build.make:64: util/geosop/CMakeFiles/geosop.dir/GeosOp.cpp.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:1962: util/geosop/CMakeFiles/geosop.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

I'm seeing a bunch of errors on 32-bit but will look at those closer

Change History (9)

comment:1 by strk, 3 years ago

Description: modified (diff)

I've filed #1105 for the last error about unrecognized option, which I also get

comment:2 by robe, 3 years ago

This looks to have started happening right after this commit:

8b024bbdd1ce8fe951e30ddccd5932d15e1995c0/git)

comment:3 by gdt, 3 years ago

It seems std::count is of type size_t, not long, so the variable the answer is stored in should be size_t. I don't see that this is more complicated than using the right type.

comment:4 by robe, 3 years ago

Only thing is why am I the only one affected by this if it's just a type issue or is my type being detected incorrectly.

Compile works on my mingw64 32-bit but is failing on my mingw64 64-bit.

comment:5 by dbaston, 3 years ago

Owner: changed from geos-devel@… to mbdavis

comment:6 by dbaston, 3 years ago

Owner: changed from mbdavis to mdavis

comment:7 by gdt, 3 years ago

It's natural for incorrect code to work in some environments if size_t and long int happen to be the same type. On LP64 arches in Unix, that doesn't seem surprising. It's also unsurprising that all type errors that show up on typical GNU/Linux systems have been fixed already. So I would not worry why it's only you. If reading the code shows it's wrong, just fix it (based on using types correctly, not avoiding warnings).

comment:9 by Regina Obe <lr@…>, 3 years ago

Resolution: fixed
Status: newclosed

In 1d69445/git:

Fix from dbaston. Closes https://github.com/libgeos/geos/pull/426 Closes #1104

Note: See TracTickets for help on using tickets.