Opened 11 years ago

Last modified 7 years ago

#638 closed defect

Recommend a static_cast around assert strings — at Version 4

Reported by: goatbar Owned by: geos-devel@…
Priority: major Milestone: 3.7.0
Component: Default Version: 3.3.8
Severity: Unassigned Keywords:
Cc:

Description (last modified by robe)

I recommend that for all asserts with strings, that they be changed to wrap the string in a static_cast. Not very exciting, but it makes the stricter compilers happier.

e.g. in src/geom/util/GeometryEditor.cpp

assert(!"SHOULD NEVER GET HERE");

changes to

assert(!static_cast<bool>("SHOULD NEVER GET HERE"));

Change History (4)

comment:1 by goatbar, 11 years ago

warmerdam suggested:

Perhaps assertFailureWithMessage(text) that expands to something like this

comment:2 by mloskot, 11 years ago

I'm curious, what stricter compilers you mean? Non of these complain, using strict flags -pedantic -Wall -ansi -std=c++11: clang 3.4, gcc 4.8, Intell C/C++ 13.

comment:3 by goatbar, 11 years ago

"GCC 4.7.x with numerous patches", but I'm not exactly sure. This is the message I'm getting:

geos-3.3.8/src/geom/util/GeometryEditor.cpp:103:13: error: implicit conversion turns string literal into bool: 'const char [22]' to 'bool' [-Werror,-Wstring-conversion]
include/assert.h:92:5: note: expanded from macro 'assert'

comment:4 by robe, 11 years ago

Description: modified (diff)
Milestone: 3.5.0

Not seeing this particular error on my mingw gcc 4.8 built with cmake. Though I do see this somewhat troubling notice

In file included from c:/jenkins/geos/branches/3.4cmake/tests/xmltester/BufferResultMatcher.cpp:22:0:
C:/jenkins/geos/branches/3.4cmake/include/geos/geom/BinaryOp.h: In instantiation of 'std::auto_ptr<geos::geom::Geometry> geos::geom::BinaryOp(const geos::geom::Geometry*, const geos::geom::Geometry*, BinOp) [with BinOp = geos::operation::overlay::overlayOp]':
c:/jenkins/geos/branches/3.4cmake/tests/xmltester/BufferResultMatcher.cpp:80:58:   required from here
C:/jenkins/geos/branches/3.4cmake/include/geos/geom/BinaryOp.h:459:32: warning: overflow in implicit constant conversion [-Woverflow]
   long unsigned int maxScale = 1e16;

I'd just assume avoid these changes in a micro release especially since we plan to release soon and sounds like a lot of changes would need to be made to accommodate this. Pushing to 3.5

Note: See TracTickets for help on using tickets.