Merge pull request #3481 from myk002/myk_cpp20

get compiling with c++-20
develop
Myk 2023-07-05 22:28:59 -07:00 committed by GitHub
commit 50b3cecfcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 75 additions and 52 deletions

@ -35,9 +35,10 @@ option(REMOVE_SYMBOLS_FROM_DF_STUBS "Remove debug symbols from DF stubs. (Reduce
macro(CHECK_GCC compiler_path)
execute_process(COMMAND ${compiler_path} -dumpversion OUTPUT_VARIABLE GCC_VERSION_OUT)
string(STRIP "${GCC_VERSION_OUT}" GCC_VERSION_OUT)
if(${GCC_VERSION_OUT} VERSION_LESS "4.8")
message(SEND_ERROR "${compiler_path} version ${GCC_VERSION_OUT} cannot be used - use GCC 4.8 or later")
elseif(${GCC_VERSION_OUT} VERSION_GREATER "4.9.9")
if(${GCC_VERSION_OUT} VERSION_LESS "10")
message(SEND_ERROR "${compiler_path} version ${GCC_VERSION_OUT} cannot be used - use GCC 10 or later")
# TODO: this may need to be removed when DF linux actually comes out
# TODO: and we can test
# GCC 5 changes ABI name mangling to enable C++11 changes.
# This must be disabled to enable linking against DF.
# http://developerblog.redhat.com/2015/02/05/gcc5-and-the-c11-abi/
@ -66,8 +67,8 @@ if(WIN32)
endif()
endif()
# Ask for C++11 standard from compilers
set(CMAKE_CXX_STANDARD 11)
# Ask for C++-20 standard from compilers
set(CMAKE_CXX_STANDARD 20)
# Require the standard support from compilers.
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Use only standard c++ to keep code portable
@ -226,9 +227,7 @@ if(UNIX)
## flags for GCC
# default to hidden symbols
# ensure compatibility with older CPUs
# enable C++11 features
add_definitions(-DLINUX_BUILD)
add_definitions(-D_GLIBCXX_USE_C99)
set(GCC_COMMON_FLAGS "-fvisibility=hidden -mtune=generic -Wall -Werror")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COMMON_FLAGS}")

@ -4,11 +4,19 @@ add_subdirectory(lua)
add_subdirectory(md5)
add_subdirectory(protobuf)
if(UNIX)
set_target_properties(lua PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-deprecated-enum-enum-conversion")
set_target_properties(protoc PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-restrict")
set_target_properties(protoc-bin PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-restrict")
set_target_properties(protobuf-lite PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-restrict")
set_target_properties(protobuf PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations -Wno-restrict")
endif()
if(UNIX AND NOT APPLE) # remove this once our MSVC build env has been updated
option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" OFF)
add_subdirectory(googletest)
if(UNIX)
set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-Wno-maybe-uninitialized -Wno-sign-compare")
set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-Wno-maybe-uninitialized -Wno-sign-compare -Wno-restrict")
endif()
endif()

@ -46,6 +46,10 @@
#ifndef GOOGLE_PROTOBUF_REPEATED_FIELD_H__
#define GOOGLE_PROTOBUF_REPEATED_FIELD_H__
#ifdef __GNUC__
#pragma GCC system_header
#endif
#include <string>
#include <iterator>
#include <google/protobuf/stubs/common.h>

@ -1471,6 +1471,10 @@ std::string Core::getHackPath()
#endif
}
df::viewscreen * Core::getTopViewscreen() {
return getInstance().top_viewscreen;
}
bool Core::InitMainThread() {
Filesystem::init();
@ -1855,6 +1859,11 @@ void *Core::GetData( std::string key )
}
}
Core& Core::getInstance() {
static Core instance;
return instance;
}
bool Core::isSuspended(void)
{
return ownerThread.load() == std::this_thread::get_id();

@ -213,12 +213,12 @@ std::string pointer_identity::getFullName()
std::string container_identity::getFullName(type_identity *item)
{
return "<" + (item ? item->getFullName() : std::string("void")) + ">";
return '<' + (item ? item->getFullName() : std::string("void")) + '>';
}
std::string ptr_container_identity::getFullName(type_identity *item)
{
return "<" + (item ? item->getFullName() : std::string("void")) + "*>";
return '<' + (item ? item->getFullName() : std::string("void")) + std::string("*>");
}
std::string bit_container_identity::getFullName(type_identity *)

@ -26,6 +26,7 @@ redistribute it freely, subject to the following restrictions:
#include "Debug.h"
#include "DebugManager.h"
#include <algorithm>
#include <chrono>
#include <iomanip>
#include <thread>

@ -40,8 +40,6 @@ distribution.
#include <mutex>
#include <thread>
#include "RemoteClient.h"
#define DFH_MOD_SHIFT 1
#define DFH_MOD_CTRL 2
#define DFH_MOD_ALT 4
@ -74,6 +72,17 @@ namespace DFHack
struct Hide;
}
enum command_result
{
CR_LINK_FAILURE = -3, // RPC call failed due to I/O or protocol error
CR_NEEDS_CONSOLE = -2, // Attempt to call interactive command without console
CR_NOT_IMPLEMENTED = -1, // Command not implemented, or plugin not loaded
CR_OK = 0, // Success
CR_FAILURE = 1, // Failure
CR_WRONG_USAGE = 2, // Wrong arguments or ui state
CR_NOT_FOUND = 3 // Target object not found (for RPC mainly)
};
enum state_change_event
{
SC_UNKNOWN = -1,
@ -116,11 +125,7 @@ namespace DFHack
friend bool ::dfhooks_ncurses_key(int key);
public:
/// Get the single Core instance or make one.
static Core& getInstance()
{
static Core instance;
return instance;
}
static Core& getInstance();
/// check if the activity lock is owned by this thread
bool isSuspended(void);
/// Is everything OK?
@ -168,7 +173,7 @@ namespace DFHack
bool isWorldLoaded() { return (last_world_data_ptr != NULL); }
bool isMapLoaded() { return (last_local_map_ptr != NULL && last_world_data_ptr != NULL); }
static df::viewscreen *getTopViewscreen() { return getInstance().top_viewscreen; }
static df::viewscreen *getTopViewscreen();
DFHack::Console &getConsole() { return con; }

@ -35,8 +35,6 @@ distribution.
#include "Core.h"
#include "DataFuncs.h"
#include "RemoteClient.h"
typedef struct lua_State lua_State;
namespace tthread

@ -26,6 +26,7 @@ distribution.
#include "Pragma.h"
#include "Export.h"
#include "ColorText.h"
#include "Core.h"
class CPassiveSocket;
class CActiveSocket;
@ -39,17 +40,6 @@ namespace DFHack
using dfproto::IntMessage;
using dfproto::StringMessage;
enum command_result
{
CR_LINK_FAILURE = -3, // RPC call failed due to I/O or protocol error
CR_NEEDS_CONSOLE = -2, // Attempt to call interactive command without console
CR_NOT_IMPLEMENTED = -1, // Command not implemented, or plugin not loaded
CR_OK = 0, // Success
CR_FAILURE = 1, // Failure
CR_WRONG_USAGE = 2, // Wrong arguments or ui state
CR_NOT_FOUND = 3 // Target object not found (for RPC mainly)
};
enum DFHackReplyCode : int16_t {
RPC_REPLY_RESULT = -1,
RPC_REPLY_FAIL = -2,

@ -237,7 +237,7 @@ DFHACK_EXPORT std::string getRoomDescription(df::building *building, df::unit *u
* starting at the top left and moving right, row by row,
* the block's items are checked for anything on the ground within that stockpile.
*/
class DFHACK_EXPORT StockpileIterator : public std::iterator<std::input_iterator_tag, df::item>
class DFHACK_EXPORT StockpileIterator
{
df::building_stockpilest* stockpile;
df::map_block* block;
@ -245,6 +245,12 @@ class DFHACK_EXPORT StockpileIterator : public std::iterator<std::input_iterator
df::item *item;
public:
using iterator_category = std::input_iterator_tag;
using value_type = df::item*;
using difference_type = std::ptrdiff_t;
using pointer = df::item**;
using reference = df::item*&;
StockpileIterator() {
stockpile = NULL;
block = NULL;

@ -108,7 +108,7 @@ static bool is_running_on_wine() {
return !!pwine_get_version;
}
static DWORD findProcess(LPWSTR name) {
static DWORD findProcess(LPCWSTR name) {
PROCESSENTRY32W entry;
entry.dwSize = sizeof(PROCESSENTRY32W);
@ -150,11 +150,14 @@ static bool launchDFHack(color_ostream& out) {
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
// note that the enviornment must be explicitly zeroed out and not NULL,
static LPCWSTR procname = L"hack/launchdf.exe";
static const char * env = "\0";
// note that the environment must be explicitly zeroed out and not NULL,
// otherwise the launched process will inherit this process's environment,
// and the Steam API in the launchdf process will think it is in DF's context.
BOOL res = CreateProcessW(L"hack/launchdf.exe",
NULL, NULL, NULL, FALSE, 0, "\0", NULL, &si, &pi);
BOOL res = CreateProcessW(procname,
NULL, NULL, NULL, FALSE, 0, (LPVOID)env, NULL, &si, &pi);
return !!res;
}

@ -182,23 +182,23 @@ DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode)
if (game->main_interface.info.open) {
newFocusString = baseFocus;
newFocusString += "/Info";
newFocusString += "/" + enum_item_key(game->main_interface.info.current_mode);
newFocusString += '/' + enum_item_key(game->main_interface.info.current_mode);
switch(game->main_interface.info.current_mode) {
case df::enums::info_interface_mode_type::CREATURES:
newFocusString += "/" + enum_item_key(game->main_interface.info.creatures.current_mode);
newFocusString += '/' + enum_item_key(game->main_interface.info.creatures.current_mode);
break;
case df::enums::info_interface_mode_type::BUILDINGS:
newFocusString += "/" + enum_item_key(game->main_interface.info.buildings.mode);
newFocusString += '/' + enum_item_key(game->main_interface.info.buildings.mode);
break;
case df::enums::info_interface_mode_type::LABOR:
newFocusString += "/" + enum_item_key(game->main_interface.info.labor.mode);
newFocusString += '/' + enum_item_key(game->main_interface.info.labor.mode);
break;
case df::enums::info_interface_mode_type::ARTIFACTS:
newFocusString += "/" + enum_item_key(game->main_interface.info.artifacts.mode);
newFocusString += '/' + enum_item_key(game->main_interface.info.artifacts.mode);
break;
case df::enums::info_interface_mode_type::JUSTICE:
newFocusString += "/" + enum_item_key(game->main_interface.info.justice.current_mode);
newFocusString += '/' + enum_item_key(game->main_interface.info.justice.current_mode);
break;
case df::enums::info_interface_mode_type::WORK_ORDERS:
if (game->main_interface.info.work_orders.conditions.open)
@ -215,7 +215,7 @@ DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode)
if (game->main_interface.view_sheets.open) {
newFocusString = baseFocus;
newFocusString += "/ViewSheets";
newFocusString += "/" + enum_item_key(game->main_interface.view_sheets.active_sheet);
newFocusString += '/' + enum_item_key(game->main_interface.view_sheets.active_sheet);
if (game->main_interface.view_sheets.active_sheet == df::view_sheet_type::BUILDING) {
auto bld = df::building::find(game->main_interface.view_sheets.viewing_bldid);
if (bld)
@ -244,7 +244,7 @@ DEFINE_GET_FOCUS_STRING_HANDLER(dwarfmode)
newFocusString += "/Zone";
if (game->main_interface.civzone.cur_bld) {
newFocusString += "/Some";
newFocusString += "/" + enum_item_key(game->main_interface.civzone.cur_bld->type);
newFocusString += '/' + enum_item_key(game->main_interface.civzone.cur_bld->type);
}
break;
case df::enums::main_bottom_mode_type::ZONE_PAINT:
@ -519,7 +519,7 @@ DEFINE_GET_FOCUS_STRING_HANDLER(dungeonmode)
if (!adventure)
return;
focus += "/" + enum_item_key(adventure->menu);
focus += '/' + enum_item_key(adventure->menu);
}
*/
@ -1447,7 +1447,7 @@ DFHACK_EXPORT int Gui::makeAnnouncement(df::announcement_type type, df::announce
if (flags.bits.D_DISPLAY)
{
world->status.display_timer = ANNOUNCE_DISPLAY_TIME;
Gui::writeToGamelog("x" + to_string(repeat_count + 1));
Gui::writeToGamelog('x' + to_string(repeat_count + 1));
}
return -1;
}
@ -1709,7 +1709,7 @@ bool Gui::autoDFAnnouncement(df::report_init r, string message)
if (a_flags.bits.D_DISPLAY)
{
world->status.display_timer = r.display_timer;
Gui::writeToGamelog("x" + to_string(repeat_count + 1));
Gui::writeToGamelog('x' + to_string(repeat_count + 1));
}
DEBUG(gui).print("Announcement succeeded as repeat:\n%s\n", message.c_str());
return true;

@ -103,7 +103,7 @@ void ChannelManager::manage_group(const Group &group, bool set_marker_mode, bool
WARN(manager).print(" has %d access\n", access);
cavein_possible = config.riskaverse;
cavein_candidates.emplace(pos, access);
least_access = min(access, least_access);
least_access = std::min(access, least_access);
}
} else if (config.insta_dig && isEntombed(miner_pos, pos)) {
manage_one(pos, true, false);
@ -141,7 +141,7 @@ void ChannelManager::manage_group(const Group &group, bool set_marker_mode, bool
for (df::block_square_event* event: block->block_events) {
if (auto evT = virtual_cast<df::block_square_event_designation_priorityst>(event)) {
// we want to let the user keep some designations free of being managed
auto b = max(0, cavein_candidates[pos] - least_access);
auto b = std::max(0, cavein_candidates[pos] - least_access);
auto v = 1000 + (b * 1700);
DEBUG(manager).print("(" COORD ") 1000+1000(%d) -> %d {least-access: %d}\n",COORDARGS(pos), b, v, least_access);
evT->priority[Coord(local)] = v;

@ -23,7 +23,7 @@ namespace CSP {
inline uint32_t calc_distance(df::coord p1, df::coord p2) {
// calculate chebyshev (chessboard) distance
uint32_t distance = abs(p2.z - p1.z);
distance += max(abs(p2.x - p1.x), abs(p2.y - p1.y));
distance += std::max(abs(p2.x - p1.x), abs(p2.y - p1.y));
return distance;
}

@ -411,7 +411,7 @@ public:
Screen::paintTile(corner_ur, x2, y1);
Screen::paintTile(corner_dl, x1, y2);
Screen::paintTile(corner_dr, x2, y2);
string title = " " + get_title() + " ";
string title = ' ' + get_title() + ' ';
Screen::paintString(Screen::Pen(' ', COLOR_DARKGREY, COLOR_BLACK),
x2 - 6, y1, "DFHack");
Screen::paintString(Screen::Pen(' ', COLOR_BLACK, COLOR_GREY),

@ -103,7 +103,7 @@ static void find_active_keybindings(color_ostream &out, df::viewscreen *screen,
}
for (int i = 1; i <= 12; i++) {
valid_keys.push_back("F" + int_to_string(i));
valid_keys.push_back('F' + int_to_string(i));
}
valid_keys.push_back("`");