COMMON: Compile error - SWAP undeclared in algorithm.h
|Reported by:||salty-horse||Owned by:||lordhoto|
While trying tom compile from SVN with clang, I encountered the following error:
In file included from engines/scumm/detection.cpp:26: In file included from ./base/plugins.h:31: In file included from ./common/util.h:30: In file included from ./common/str.h:29: In file included from ./common/array.h:29: ./common/algorithm.h:182:2: error: use of undeclared identifier 'SWAP'
algorithm.h uses SWAP without including util.h.
The reason the code compiles in gcc is that (after preprocessing) engines/scumm/detection.cpp includes common/util.h AFTER including common/algorithm.h. Since SWAP depends on the template arguments of sortPartition, gcc only instantiates it (and lookups its symbols) at the end of the translation unit.
See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29131 for details. There is an open issue about whether this is defined behavior with the C++ standards committee.
In any case, this is an ugly edge-case. However, it cannot easily be fixed by including common/util.h in common/algorithm.h. This causes a circular dependency between util.h -> str.h -> array.h -> algorithm.h -> util.h
A possible solution is to not use SWAP in algorithm.h.
Ticket imported from: #2971226. Ticket imported from: bugs/4822.
Change History (7)
comment:2 by , 14 years ago
|Summary:||Compilation error - SWAP undeclared in algorithm.h → COMMON: Compile error - SWAP undeclared in algorithm.h|