dasebe / webcachesim

A C++11 simulator for a variety of CDN caching policies.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compilation error

lakshit07 opened this issue · comments

g++ -std=c++11 -MMD -MP -I./ -Wall -Werror -O2 -c -o caches/lru_variants.o caches/lru_variants.cpp
In file included from caches/lru_variants.cpp:5:
In file included from caches/lru_variants.h:6:
./cache.h:79:26: error: moving a temporary object prevents copy elision
[-Werror,-Wpessimizing-move]
Cache_instance = move(get_factory_instance()[name]->create_unique());
^
./cache.h:79:26: note: remove std::move call here
Cache_instance = move(get_factory_instance()[name]->create_unique());
^~~~~ ~
1 error generated.
make: *** [caches/lru_variants.o] Error 1

Hi @lakshit07,
which compiler are you using?
I just checked the current version and with g++ (GCC) 7.2.0 there are no compilation warnings or errors. I've also checked GCC 6, and all work as well.

Are you maybe using LLVM/Clang? I don't typically use that compiler, but I'm happy to help debug and fix. Does Clang's suggestion work for you?

Hi @dasebe
On running g++ --version I get

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr /include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Which Clang suggestion are you referring to?

Hi @dasebe, I encountered the same issue when trying to compile using both g++ and clang++ on OSX. I found the root cause is the move statements as mentioned in the error by OP. The reason you aren't seeing it in GCC 7.2.0 is because -Wall doesn't turn on -Wpessimizing-move which catches these kinds of warnings. The latest version of GCC, clang (the default versions on OSX) turns on -Wpessimizing-move in -Wall.

Reference docs:
GCC 7.2.0
GCC 10.0.0

Fix is to remove the call to move in cache.h at line 79 and webcachesim.cpp at line 24.

Entirely right, fixed in 26223b2