Improve the C++ to be more correct for clang on Windows, still requiring the same disabled warnings as on *nix

This commit is contained in:
gingerBill
2021-08-19 14:44:53 +01:00
parent 82a74ebfa9
commit 33239324b8
3 changed files with 50 additions and 29 deletions

View File

@@ -1,5 +1,5 @@
GIT_SHA=$(shell git rev-parse --short HEAD)
DISABLED_WARNINGS=-Wno-switch -Wno-pointer-sign -Wno-tautological-constant-out-of-range-compare -Wno-tautological-compare -Wno-macro-redefined -Wno-unused-value
DISABLED_WARNINGS=-Wno-switch -Wno-macro-redefined -Wno-unused-value
LDFLAGS=-pthread -ldl -lm -lstdc++
CFLAGS=-std=c++14 -DGIT_SHA=\"$(GIT_SHA)\"
CFLAGS:=$(CFLAGS) -DODIN_VERSION_RAW=\"dev-$(shell date +"%Y-%m")\"

View File

@@ -2039,7 +2039,7 @@ typedef enum gbFileStandardType {
gbFileStandard_Count,
} gbFileStandardType;
GB_DEF gbFile *const gb_file_get_standard(gbFileStandardType std);
GB_DEF gbFile *gb_file_get_standard(gbFileStandardType std);
GB_DEF gbFileError gb_file_create (gbFile *file, char const *filename);
GB_DEF gbFileError gb_file_open (gbFile *file, char const *filename);
@@ -3678,12 +3678,12 @@ gb_inline isize gb_pointer_diff (void const *begin, void const *end) {
gb_inline void gb_zero_size(void *ptr, isize size) { gb_memset(ptr, 0, size); }
#if defined(_MSC_VER)
#if defined(_MSC_VER) && !defined(__clang__)
#pragma intrinsic(__movsb)
#endif
gb_inline void *gb_memcopy(void *dest, void const *source, isize n) {
#if defined(_MSC_VER)
#if defined(_MSC_VER) && !defined(__clang__)
if (dest == NULL) {
return NULL;
}
@@ -4654,7 +4654,14 @@ gb_inline void gb_yield_thread(void) {
gb_inline void gb_mfence(void) {
#if defined(GB_SYSTEM_WINDOWS)
_ReadWriteBarrier();
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
_ReadWriteBarrier();
#pragma clang diagnostic pop
#else
_ReadWriteBarrier();
#endif
#elif defined(GB_SYSTEM_OSX)
#if defined(GB_CPU_X86)
__sync_synchronize();
@@ -4670,7 +4677,14 @@ gb_inline void gb_mfence(void) {
gb_inline void gb_sfence(void) {
#if defined(GB_SYSTEM_WINDOWS)
_WriteBarrier();
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
_WriteBarrier();
#pragma clang diagnostic pop
#else
_WriteBarrier();
#endif
#elif defined(GB_SYSTEM_OSX)
#if defined(GB_CPU_X86)
__asm__ volatile ("" : : : "memory");
@@ -4687,7 +4701,14 @@ gb_inline void gb_sfence(void) {
gb_inline void gb_lfence(void) {
#if defined(GB_SYSTEM_WINDOWS)
_ReadBarrier();
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
_ReadBarrier();
#pragma clang diagnostic pop
#else
_ReadBarrier();
#endif
#elif defined(GB_SYSTEM_OSX)
__asm__ volatile ("" : : : "memory");
#elif defined(GB_CPU_X86)
@@ -8026,13 +8047,13 @@ gb_inline b32 gb_file_has_changed(gbFile *f) {
}
// TODO(bill): Is this a bad idea?
gb_global b32 gb__std_file_set = false;
gb_global gbFile gb__std_files[gbFileStandard_Count] = {{0}};
gb_global b32 gb__std_file_set;
gb_global gbFile gb__std_files[gbFileStandard_Count];
#if defined(GB_SYSTEM_WINDOWS)
gb_inline gbFile *const gb_file_get_standard(gbFileStandardType std) {
gb_inline gbFile *gb_file_get_standard(gbFileStandardType std) {
if (!gb__std_file_set) {
#define GB__SET_STD_FILE(type, v) gb__std_files[type].fd.p = v; gb__std_files[type].ops = gbDefaultFileOperations
GB__SET_STD_FILE(gbFileStandard_Input, GetStdHandle(STD_INPUT_HANDLE));
@@ -8082,7 +8103,7 @@ b32 gb_file_exists(char const *name) {
#else // POSIX
gb_inline gbFile *const gb_file_get_standard(gbFileStandardType std) {
gb_inline gbFile *gb_file_get_standard(gbFileStandardType std) {
if (!gb__std_file_set) {
#define GB__SET_STD_FILE(type, v) gb__std_files[type].fd.i = v; gb__std_files[type].ops = gbDefaultFileOperations
GB__SET_STD_FILE(gbFileStandard_Input, 0);

View File

@@ -52,12 +52,12 @@ gb_global gbAllocator mc_allocator = heap_allocator();
struct Find_Result {
int windows_sdk_version; // Zero if no Windows SDK found.
wchar_t *windows_sdk_root;
wchar_t *windows_sdk_um_library_path;
wchar_t *windows_sdk_ucrt_library_path;
wchar_t const *windows_sdk_root;
wchar_t const *windows_sdk_um_library_path;
wchar_t const *windows_sdk_ucrt_library_path;
wchar_t *vs_exe_path;
wchar_t *vs_library_path;
wchar_t const *vs_exe_path;
wchar_t const *vs_library_path;
};
struct Find_Result_Utf8 {
@@ -179,10 +179,10 @@ struct DECLSPEC_UUID("42843719-DB4C-46C2-8E7C-64F1816EFD5B") DECLSPEC_NOVTABLE I
struct Version_Data {
i32 best_version[4]; // For Windows 8 versions, only two of these numbers are used.
wchar_t *best_name;
wchar_t const *best_name;
};
bool os_file_exists(wchar_t *name) {
bool os_file_exists(wchar_t const *name) {
// @Robustness: What flags do we really want to check here?
auto attrib = GetFileAttributesW(name);
@@ -192,7 +192,7 @@ bool os_file_exists(wchar_t *name) {
return true;
}
wchar_t *concat(wchar_t *a, wchar_t *b, wchar_t *c = nullptr, wchar_t *d = nullptr) {
wchar_t *concat(wchar_t const *a, wchar_t const *b, wchar_t const *c = nullptr, wchar_t const *d = nullptr) {
// Concatenate up to 4 wide strings together. Allocated with malloc.
// If you don't like that, use a programming language that actually
// helps you with using custom allocators. Or just edit the code.
@@ -214,8 +214,8 @@ wchar_t *concat(wchar_t *a, wchar_t *b, wchar_t *c = nullptr, wchar_t *d = nullp
return result;
}
typedef void (*Visit_Proc_W)(wchar_t *short_name, wchar_t *full_name, Version_Data *data);
bool visit_files_w(wchar_t *dir_name, Version_Data *data, Visit_Proc_W proc) {
typedef void (*Visit_Proc_W)(wchar_t const *short_name, wchar_t const *full_name, Version_Data *data);
bool visit_files_w(wchar_t const *dir_name, Version_Data *data, Visit_Proc_W proc) {
// Visit everything in one folder (non-recursively). If it's a directory
// that doesn't start with ".", call the visit proc on it. The visit proc
@@ -246,7 +246,7 @@ bool visit_files_w(wchar_t *dir_name, Version_Data *data, Visit_Proc_W proc) {
}
wchar_t *find_windows_kit_root(HKEY key, wchar_t *version) {
wchar_t *find_windows_kit_root(HKEY key, wchar_t const *version) {
// Given a key to an already opened registry entry,
// get the value stored under the 'version' subkey.
// If that's not the right terminology, hey, I never do registry stuff.
@@ -272,7 +272,7 @@ wchar_t *find_windows_kit_root(HKEY key, wchar_t *version) {
return value;
}
void win10_best(wchar_t *short_name, wchar_t *full_name, Version_Data *data) {
void win10_best(wchar_t const *short_name, wchar_t const *full_name, Version_Data *data) {
// Find the Windows 10 subdirectory with the highest version number.
int i0, i1, i2, i3;
@@ -292,7 +292,7 @@ void win10_best(wchar_t *short_name, wchar_t *full_name, Version_Data *data) {
// we have to copy_string and free here because visit_files free's the full_name string
// after we execute this function, so Win*_Data would contain an invalid pointer.
if (data->best_name) free(data->best_name);
if (data->best_name) free((void *)data->best_name);
data->best_name = _wcsdup(full_name);
if (data->best_name) {
@@ -303,7 +303,7 @@ void win10_best(wchar_t *short_name, wchar_t *full_name, Version_Data *data) {
}
}
void win8_best(wchar_t *short_name, wchar_t *full_name, Version_Data *data) {
void win8_best(wchar_t const *short_name, wchar_t const *full_name, Version_Data *data) {
// Find the Windows 8 subdirectory with the highest version number.
int i0, i1;
@@ -317,7 +317,7 @@ void win8_best(wchar_t *short_name, wchar_t *full_name, Version_Data *data) {
// we have to copy_string and free here because visit_files free's the full_name string
// after we execute this function, so Win*_Data would contain an invalid pointer.
if (data->best_name) free(data->best_name);
if (data->best_name) free((void *)data->best_name);
data->best_name = _wcsdup(full_name);
if (data->best_name) {
@@ -502,11 +502,11 @@ bool find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *res
defer (RegCloseKey(vs7_key));
// Hardcoded search for 4 prior Visual Studio versions. Is there something better to do here?
wchar_t *versions[] = { L"14.0", L"13.0", L"12.0", L"11.0", L"10.0", L"9.0", };
wchar_t const *versions[] = { L"14.0", L"13.0", L"12.0", L"11.0", L"10.0", L"9.0", };
const int NUM_VERSIONS = sizeof(versions) / sizeof(versions[0]);
for (int i = 0; i < NUM_VERSIONS; i++) {
wchar_t *v = versions[i];
wchar_t const *v = versions[i];
DWORD dw_type;
DWORD cb_data;
@@ -589,7 +589,7 @@ Find_Result find_visual_studio_and_windows_sdk() {
return result;
}
String mc_wstring_to_string(wchar_t *str) {
String mc_wstring_to_string(wchar_t const *str) {
return string16_to_string(mc_allocator, make_string16_c(str));
}