Browse Source

Option for all clang errors and fixes

Kajetan Johannes Hammerle 10 months ago
parent
commit
d1999f157a

+ 14 - 0
cmake/clang_warnings.cmake

@@ -4,6 +4,7 @@ set(WARNINGS
     -Warray-parameter
     -Wbad-function-cast
     -Wcast-qual
+    -Wconditional-uninitialized
     -Wconversion
     -Wdate-time
     -Wdisabled-optimization
@@ -12,6 +13,7 @@ set(WARNINGS
     -Wenum-conversion
     -Werror
     -Wextra
+    -Wextra-semi-stmt
     -Wfloat-equal
     -Wformat=2
     -Wframe-larger-than=8388608
@@ -22,6 +24,7 @@ set(WARNINGS
     -Wmissing-braces
     -Wmissing-declarations
     -Wmissing-include-dirs
+    -Wmissing-noreturn 
     -Wmissing-prototypes
     -Wmultichar
     -Wnarrowing
@@ -43,3 +46,14 @@ set(WARNINGS
     -pedantic
     -pedantic-errors
 )
+
+if(0)
+    set(WARNINGS ${WARNINGS} 
+        -Weverything
+        -Wno-unsafe-buffer-usage
+        -Wno-c++98-compat
+        -Wno-declaration-after-statement
+        -Wno-pre-c2x-compat
+        -Wno-padded
+    )
+endif()

+ 2 - 0
cmake/gcc_warnings.cmake

@@ -1,4 +1,6 @@
 set(WARNINGS
+    -Wno-attributes
+
     -Wall
     -Walloc-zero
     -Walloca

+ 4 - 4
include/core/Logger.h

@@ -27,7 +27,7 @@ check_format(6, 7) void coreLog(CoreLogLevel l, const char* file, int line,
 #if defined(CORE_LOG_LEVEL) && CORE_LOG_LEVEL >= 1
 #define CORE_LOG_ERROR(...)                                                    \
     coreLog(CORE_LOG_ERROR, __FILE__, __LINE__, CORE_TERMINAL_RED, "[ERROR] ", \
-            __VA_ARGS__);
+            __VA_ARGS__)
 #else
 #define CORE_LOG_ERROR(...)
 #endif
@@ -35,7 +35,7 @@ check_format(6, 7) void coreLog(CoreLogLevel l, const char* file, int line,
 #if defined(CORE_LOG_LEVEL) && CORE_LOG_LEVEL >= 2
 #define CORE_LOG_WARNING(...)                                                  \
     coreLog(CORE_LOG_WARNING, __FILE__, __LINE__, CORE_TERMINAL_YELLOW,        \
-            "[WARNING] ", __VA_ARGS__);
+            "[WARNING] ", __VA_ARGS__)
 #else
 #define CORE_LOG_WARNING(...)
 #endif
@@ -43,7 +43,7 @@ check_format(6, 7) void coreLog(CoreLogLevel l, const char* file, int line,
 #if defined(CORE_LOG_LEVEL) && CORE_LOG_LEVEL >= 3
 #define CORE_LOG_INFO(...)                                                     \
     coreLog(CORE_LOG_INFO, __FILE__, __LINE__, CORE_TERMINAL_GRAY, "[INFO] ",  \
-            __VA_ARGS__);
+            __VA_ARGS__)
 #else
 #define CORE_LOG_INFO(...)
 #endif
@@ -51,7 +51,7 @@ check_format(6, 7) void coreLog(CoreLogLevel l, const char* file, int line,
 #if defined(CORE_LOG_LEVEL) && CORE_LOG_LEVEL >= 4
 #define CORE_LOG_DEBUG(...)                                                    \
     coreLog(CORE_LOG_DEBUG, __FILE__, __LINE__, CORE_TERMINAL_GREEN,           \
-            "[DEBUG] ", __VA_ARGS__);
+            "[DEBUG] ", __VA_ARGS__)
 #else
 #define CORE_LOG_DEBUG(...)
 #endif

+ 1 - 1
include/core/Utility.h

@@ -11,7 +11,7 @@ size_t corePopCount(u64 u);
 #define coreDegreeToRadian(degrees) (degrees * (CORE_PI / 180.0f))
 
 typedef void (*CoreExitHandler)(int, void*);
-void coreExitWithHandler(const char* file, int line, int value);
+[[noreturn]] void coreExitWithHandler(const char* file, int line, int value);
 void coreSetExitHandler(CoreExitHandler h, void* data);
 #define CORE_EXIT(exitValue) coreExitWithHandler(__FILE__, __LINE__, exitValue)
 

+ 1 - 1
src/Matrix.c

@@ -6,7 +6,7 @@
 #include "core/Utility.h"
 
 CoreMatrix* coreTransposeMatrix(CoreMatrix* m) {
-    CoreMatrix c;
+    CoreMatrix c = {0};
     for(size_t x = 0; x < 4; x++) {
         for(size_t y = 0; y < 4; y++) {
             c.data[x].data[y] = m->data[y].data[x];

+ 2 - 2
src/Utility.c

@@ -23,7 +23,7 @@ size_t corePopCount(u64 u) {
     return sum;
 }
 
-void coreExitWithHandler(const char* file, int line, int value) {
+[[noreturn]] void coreExitWithHandler(const char* file, int line, int value) {
     if(value != 0) {
         file = coreGetShortFileName(file);
         CORE_LOG_ERROR("Exit from %s:%d with value %d", file, line, value);
@@ -46,7 +46,7 @@ void coreSetOutOfMemoryHandler(CoreOutOfMemoryHandler h, void* data) {
 
 static void* exitOnNull(void* p, size_t n) {
     if(p == nullptr) {
-        CORE_LOG_ERROR("Out of memory, requested '%zu' bytes", n)
+        CORE_LOG_ERROR("Out of memory, requested '%zu' bytes", n);
         CORE_EXIT(1);
     }
     return p;

+ 0 - 1
test/Main.c

@@ -59,5 +59,4 @@ int main(int argAmount, const char** args) {
     coreSetExitHandler(onExit, &data);
 
     CORE_EXIT(1);
-    return 0;
 }

+ 4 - 4
test/Test.c

@@ -88,7 +88,7 @@ CORE_TEST_NAMED_COMPARE(Size, size_t, "%zu")
 CORE_TEST_NAMED_COMPARE(Bool, bool, "%d")
 
 bool coreTestString(CORE_TEST_ARGS, const char* wanted, const char* actual) {
-    CORE_TEST_SUCCESS(strcmp(wanted, actual) == 0);
+    CORE_TEST_SUCCESS(strcmp(wanted, actual) == 0)
     fputs(CORE_TERMINAL_RED, stdout);
     printf("%s:%d - expected '%s' got '%s'", file, line, wanted, actual);
     puts(CORE_TERMINAL_RESET);
@@ -98,7 +98,7 @@ bool coreTestString(CORE_TEST_ARGS, const char* wanted, const char* actual) {
 bool coreTestFloat(CORE_TEST_ARGS, float wanted, float actual, float error) {
     float diff = wanted - actual;
     diff = diff < 0.0f ? -diff : diff;
-    CORE_TEST_SUCCESS(diff <= error);
+    CORE_TEST_SUCCESS(diff <= error)
     fputs(CORE_TERMINAL_RED, stdout);
     printf("%s:%d - expected '%.3f' got '%.3f'", file, line, (double)wanted,
            (double)actual);
@@ -107,7 +107,7 @@ bool coreTestFloat(CORE_TEST_ARGS, float wanted, float actual, float error) {
 }
 
 bool coreTestNull(CORE_TEST_ARGS, const void* actual) {
-    CORE_TEST_SUCCESS(actual == nullptr);
+    CORE_TEST_SUCCESS(actual == nullptr)
     fputs(CORE_TERMINAL_RED, stdout);
     printf("%s:%d - expected null", file, line);
     puts(CORE_TERMINAL_RESET);
@@ -115,7 +115,7 @@ bool coreTestNull(CORE_TEST_ARGS, const void* actual) {
 }
 
 bool coreTestNotNull(CORE_TEST_ARGS, const void* actual) {
-    CORE_TEST_SUCCESS(actual != nullptr);
+    CORE_TEST_SUCCESS(actual != nullptr)
     fputs(CORE_TERMINAL_RED, stdout);
     printf("%s:%d - expected valid pointer", file, line);
     puts(CORE_TERMINAL_RESET);

+ 2 - 2
test/Tests.h

@@ -21,8 +21,8 @@ void coreTestRingBuffer(void);
 void coreTestStack(bool light);
 void coreTestThread(void);
 void coreTestUtility(bool light);
-void coreTestInvalidAllocate(void);
-void coreTestInvalidReallocate(void);
+[[noreturn]] void coreTestInvalidAllocate(void);
+[[noreturn]] void coreTestInvalidReallocate(void);
 void coreTestPreCanary(void);
 void coreTestPostCanary(void);
 void coreTestVector(void);

+ 0 - 1
test/modules/QuaternionTests.c

@@ -2,7 +2,6 @@
 #include "core/Quaternion.h"
 
 typedef CoreQuaternion Q;
-#define Q(a, b, c, d) (&(Q){{a, b, c}, d})
 #define CV3(a, b, c) (&(CoreVector3){{a, b, c}})
 #define CV30 CV3(0.0f, 0.0f, 0.0f)
 

+ 2 - 2
test/modules/UtilityTests.c

@@ -105,7 +105,7 @@ void coreTestInvalidReallocate(void) {
     CORE_EXIT(0);
 }
 
-void coreTestPreCanary(void) {
+[[noreturn]] void coreTestPreCanary(void) {
 #ifdef CORE_CHECK_MEMORY
     char* p = coreAllocate(16);
     p[-1] = 0;
@@ -116,7 +116,7 @@ void coreTestPreCanary(void) {
     CORE_EXIT(0);
 }
 
-void coreTestPostCanary(void) {
+[[noreturn]] void coreTestPostCanary(void) {
 #ifdef CORE_CHECK_MEMORY
     char* p = coreAllocate(16);
     p[17] = 0;

+ 1 - 1
test/modules/VectorTests.c

@@ -3,7 +3,7 @@
 #include "../Tests.h"
 #include "core/Vector.h"
 
-const float eps = 0.0001f;
+static const float eps = 0.0001f;
 
 #define V2 CoreVector2
 #define CV2(a, b, c, d) (&(V2){{a, b}})