jdart1 / arasan-chess

Arasan chess engine
Other
124 stars 30 forks source link

Fix compilation in C++20 #40

Closed srogatch closed 1 year ago

srogatch commented 1 year ago

See https://en.cppreference.com/w/cpp/language/static : In C++17: "If a static data member is declared constexpr, it is implicitly inline and does not need to be redeclared at namespace scope. This redeclaration without an initializer (formerly required as shown above) is still permitted, but is deprecated." In C++20, a noinline definition for such members (e.g., in a .cpp file) gives errors, at least in MSVC 2022.

jdart1 commented 1 year ago

I cannot reproduce this error when compiling with C++20, neither with GCC-10, GCC-11, or MSVC 2022. But I did find another issue in bitboard.h, which is now fixed. Which compiler were you using that generated an error?

srogatch commented 1 year ago

I cannot reproduce this error when compiling with C++20, neither with GCC-10, GCC-11, or MSVC 2022. But I did find another issue in bitboard.h, which is now fixed. Which compiler were you using that generated an error?

I used the latest version of MSVS 2022, installed today. It's essential to set the C++ standard in your CMakeLists.txt to reproduce the error:

set(CMAKE_CXX_STANDARD 20)

Or a corresponding flag in Makefile.

jdart1 commented 1 year ago

tune.cpp should not even be complied when the parameters are consts. That file is only needed when building the parameter tuner, and that compilation uses -DTUNE, which will make the parameters in params.h non-const. The Makefile excludes tune.cpp from other builds, so I guess this issue only occurs with the Visual Studio project file or the CMake file. The solution IMO should be to exclude tune.cpp from builds of the engine or other executables besides the tuner.

jdart1 commented 1 year ago

I have pushed a fix to CMakeLists.txt for this.