From: Cloudwalk Date: Sat, 4 May 2024 05:54:37 +0000 (-0400) Subject: makefile: demote -Werror=c++-compat to a warning X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6abbad2450fd7e2c55dabd23dafa6bc81b1802aa;p=xonotic%2Fdarkplaces.git makefile: demote -Werror=c++-compat to a warning Also edited CONTRIBUTING.md and a comment in common.h accordingly to reflect this change. --- diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 56beb08f..f6835885 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -101,20 +101,31 @@ if (boo) AHH("!!!\n"); ``` -4. DarkPlaces is written in a special subset of C and C++ that sits in the - center of the Venn diagram of compatibility between the two languages. - While there is no practical reason for keeping it this way (yet), it is - generally preferred that all code submitted at least compiles under gcc and - g++ and clang(++). This could be done by setting the CC environment - variable to g++ or clang++ on the command-line before building. - - Most of the differences are enforced by a compile warning set to be an - error (`-Werror=c++-compat`) but some are subtle and would cause behavior - differences between the two compilers, or are not caught by that warning. - The things to look out for are: +4. DarkPlaces is written in the common subset of C and C++. This means it is + (usually) both valid C and C++. We historically wanted to keep it that way, + but don't worry about it unless you care enough and/or are a maintainer. + + Most of the differences are caught by `-Wc++-compat` but some are subtle + and would cause behavior differences between the two compilers, or are not + caught by that warning. The things to look out for are: 1. Character constants are `int`-sized in C but `char`-sized in C++. This - means `sizeof('a')` will be 4 in C, but 1 in C++. + means `sizeof('a')` will be 4 in C, but 1 in C++. 2. `goto label;` cannot jump over a variable initialization. This will - cause a compiler error as C++ but is not caught by `-Wc++-compat`. + cause a compiler error as C++ but is not caught by `-Wc++-compat`. + This is nevertheless bad code, so avoid this anyway. + + If, for some reason, you care enough, compatibility can always be tested + affirmatively by setting CC=g++. CC=clang++ may not work in the future, if + it did not already stop working in current versions LLVM, as it otherwise + spams deprecation warnings for using a C file asinput to a C++ compiler. + +> [!NOTE] +> We do not officially support building C code with a C++ compiler and may not +> address issue reports for buggy behavior that does not occur when compiled +> with a C compiler. That said, there have been fleeting ideas for converting +> either the entire engine or parts of it to C++, which is what `-Wc++-compat` +> would make a little easier. So, we at least *do not discourage* such issue +> reports, especially for things the warning doesn't catch. They will be noted +> as they would become relevant in the event we do decide to convert to C++. \ No newline at end of file diff --git a/common.h b/common.h index 5b73aa6f..cde830dc 100644 --- a/common.h +++ b/common.h @@ -221,7 +221,12 @@ void COM_Shutdown (void); char *va(char *buf, size_t buflen, const char *format, ...) DP_FUNC_PRINTF(3); // does a varargs printf into provided buffer, returns buffer (so it can be called in-line unlike dpsnprintf) -// GCC with -Werror=c++-compat will error out if static_assert is used even though the macro is valid C11... +/* Some versions of GCC with -Wc++-compat will complain if static_assert + * is used even though the macro is valid C11, so make it happy anyway + * because having build logs without any purple text is pretty satisfying. + * TODO: Disable the flag by default in makefile, with an optional variable + * to reenable it. + */ #ifndef __cplusplus #define DP_STATIC_ASSERT(expr, str) _Static_assert(expr, str) #else diff --git a/makefile.inc b/makefile.inc index dc9c990e..33cbc043 100644 --- a/makefile.inc +++ b/makefile.inc @@ -139,7 +139,7 @@ else CFLAGS_STANDARD= endif -CFLAGS_WARNINGS=-Wall -Werror=vla -Werror=c++-compat -Wwrite-strings -Wshadow -Wold-style-definition -Wstrict-prototypes -Wsign-compare -Wdeclaration-after-statement -Wmissing-prototypes +CFLAGS_WARNINGS=-Wall -Werror=vla -Wc++-compat -Wwrite-strings -Wshadow -Wold-style-definition -Wstrict-prototypes -Wsign-compare -Wdeclaration-after-statement -Wmissing-prototypes CFLAGS_TCC= ifeq ($(CC), tcc)