2025-07-22 05:55 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0003764Spring engineLinuxpublic2013-05-01 13:34
Reportercleanrock 
Assigned Tocleanrock 
PrioritynormalSeveritymajorReproducibilityalways
StatusresolvedResolutionfixed 
Product Version94.1.1+git 
Target VersionFixed in Version95.0 
Summary0003764: build error with C++11
DescriptionI see this odd build error when i build with C++11 (cmake default now):

$ make spring
[ 47%] Building CXX object rts/builds/legacy/CMakeFiles/engine-legacy.dir/__/__/Game/GameServer.cpp.o
cd /home/johanr/my_projects/spring/build_develop/rts/builds/legacy && /usr/bin/c++ -DBOOST_NO_FENV_H -DSPRING_DATADIR=\"/home/johanr/spring_develop/share/games/spring\" -DSTREFLOP_SSE -DSYNCCHECK -DUSE_LIBSQUISH -DUSE_VALGRIND -D_GLIBCXX_USE_NANOSLEEP -D_RANDOM_TCC -fopenmp -std=gnu++11 -mtune=generic -msse -mfpmath=sse -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -mno-sse4 -mno-sse4a -mno-avx -mno-fma -mno-fma4 -mno-xop -mno-lwp -mno-avx2 -fsingle-precision-constant -frounding-math -mieee-fp -pipe -fno-strict-aliasing -fvisibility=hidden -fvisibility-inlines-hidden -pthread -O2 -DNDEBUG -g -I/home/johanr/my_projects/spring/rts/lib/lua/include -I/home/johanr/my_projects/spring/include/AL -I/home/johanr/my_projects/spring/rts/lib -I/home/johanr/my_projects/spring/rts -I/home/johanr/my_projects/spring/build_develop/src-generated/engine -I/usr/include/SDL -I/usr/include/freetype2 -I/usr/include/AL -o CMakeFiles/engine-legacy.dir/__/__/Game/GameServer.cpp.o -c /home/johanr/my_projects/spring/rts/Game/GameServer.cpp
/home/johanr/my_projects/spring/rts/Game/GameServer.cpp: In member function ‘void CGameServer::ServerReadNet()’:
/home/johanr/my_projects/spring/rts/Game/GameServer.cpp:1801:17: error: cannot convert ‘boost::shared_ptr<const netcode::RawPacket>’ to ‘bool’ in assignment
      dropPacket = (packet = link->Peek(globalConfig->linkIncomingMaxWaitingPackets));
                 ^
make[3]: *** [rts/builds/legacy/CMakeFiles/engine-legacy.dir/__/__/Game/GameServer.cpp.o] Error 1

boost::shared_ptr shall have a operator bool so its a bit odd.
If i disable C++11 in cmake spring builds fine.

Additional Informationdevelop f27a86

$ gcc --version
gcc (GCC) 4.8.0 20130411 (prerelease)

boost 1.53.0
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files

-Relationships
+Relationships

-Notes

~0010592

abma (administrator)

code is:

dropPacket bool;
boost::shared_ptr<const RawPacket> packet;
boost::shared_ptr<netcode::CConnection> &link

[...]

dropPacket = (packet = link->Peek(globalConfig->linkIncomingMaxWaitingPackets));


i wouldn't say odd... error message is clear, but i don't know what the code shall do.

(packet == link->Peek ... ?

~0010593

abma (administrator)

note: imo the code is odd, not the error message :)

~0010594

jK (developer)

shared_ptr has "explicit operator bool() const;"

~0010595

jK (developer)

likely the "explicit" causes the problem

can you test if it works if you split the assignments?:

packet = link->Peek(globalConfig->linkIncomingMaxWaitingPackets);
dropPacket = packet;

~0010596

cleanrock (reporter)

Split is not enough.
Seems assigning to a bool variable is not explicit enough, see:
http://boost.2283326.n4.nabble.com/smart-ptr-thread-test-breaking-change-on-shared-ptr-operator-bool-td4639664.html

I suggest this change which makes it compile for me:
diff --git a/rts/Game/GameServer.cpp b/rts/Game/GameServer.cpp
index 4fd0077..438df02 100644
--- a/rts/Game/GameServer.cpp
+++ b/rts/Game/GameServer.cpp
@@ -1798,7 +1798,7 @@ void CGameServer::ServerReadNet()
                        bool bwLimitIsReached = globalConfig->linkIncomingPeakBandwidth > 0 && bandwidthUsage > globalConfig->linkIncomingPeakBandwidth;
                        while (link) {
                                if (dropPacket)
- dropPacket = (packet = link->Peek(globalConfig->linkIncomingMaxWaitingPackets));
+ dropPacket = (packet = link->Peek(globalConfig->linkIncomingMaxWaitingPackets)) != 0;
                                packet = (!bwLimitIsReached || dropPacket) ? link->GetData() : link->Peek(ahead++);
                                if (!packet)
                                        break;

PS. I know you prefer NULL over 0, i think we should use 0 :)

~0010597

cleanrock (reporter)

Last edited: 2013-05-01 00:27

View 2 revisions

Pasting diffs here is not that great obviously.

~0010598

jK (developer)

use "!!(packet = link->Peek(globalConfig->linkIncomingMaxWaitingPackets))" then

~0010601

abma (administrator)

https://github.com/spring/spring/commit/bdc775a2c9891b6d17548d6743fe6ec550d2830e
+Notes

-Issue History
Date Modified Username Field Change
2013-04-30 16:09 cleanrock New Issue
2013-04-30 18:27 abma Note Added: 0010592
2013-04-30 18:29 abma Note Added: 0010593
2013-04-30 20:57 jK Note Added: 0010594
2013-04-30 21:03 jK Note Added: 0010595
2013-05-01 00:13 cleanrock Note Added: 0010596
2013-05-01 00:14 cleanrock Note Added: 0010597
2013-05-01 00:27 cleanrock Note Edited: 0010597 View Revisions
2013-05-01 00:49 jK Note Added: 0010598
2013-05-01 13:34 abma Note Added: 0010601
2013-05-01 13:34 abma Status new => resolved
2013-05-01 13:34 abma Fixed in Version => 95.0
2013-05-01 13:34 abma Resolution open => fixed
2013-05-01 13:34 abma Assigned To => cleanrock
+Issue History