Procházet zdrojové kódy

Added more warning flags for GCC (as suggested in issue #28)

Benoit Blanchon před 11 roky
rodič
revize
7e98d136f4

+ 0 - 2
CMakeLists.txt

@@ -9,8 +9,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
 
 if(MSVC)
 	add_definitions(-D_CRT_SECURE_NO_WARNINGS -W4)
-else()
-	add_definitions(-Wall)
 endif()
 
 add_subdirectory(src)

+ 1 - 1
include/ArduinoJson/Internals/JsonNode.hpp

@@ -23,7 +23,7 @@ namespace ArduinoJson
                 JSON_PROXY,
                 JSON_DOUBLE_0_DECIMALS,
                 JSON_DOUBLE_1_DECIMAL,
-                JSON_DOUBLE_2_DECIMALS,
+                JSON_DOUBLE_2_DECIMALS
                 // etc.
             };
 

+ 6 - 6
include/ArduinoJson/Internals/JsonNodeIterator.hpp

@@ -12,32 +12,32 @@ namespace ArduinoJson
         public:
 
             explicit JsonNodeIterator(JsonNode* node)
-            : node(node)
+                : _node(node)
             {
             }
 
             bool operator!= (const JsonNodeIterator& other) const
             {
-                return node != other.node;
+                return _node != other._node;
             }
 
             void operator++()
             {
-                node = node->next;
+                _node = _node->next;
             }
 
             JsonNode* operator*() const
             {
-                return node;
+                return _node;
             }
 
             JsonNode* operator->() const
             {
-                return node;
+                return _node;
             }
 
         private:
-            JsonNode* node;
+            JsonNode* _node;
         };
     }
 }

+ 1 - 1
include/ArduinoJson/JsonArray.hpp

@@ -22,7 +22,7 @@ namespace ArduinoJson
         void add(bool value);
         void add(const char* value);
         void add(double value, int decimals=2);
-        void add(int value) { add((long) value); }
+        void add(int value) { add(static_cast<long>(value)); }
         void add(long value);
         void add(JsonContainer nestedArray); // TODO: should allow JsonValue too
 

+ 1 - 1
src/Arduino/Print.cpp

@@ -21,7 +21,7 @@ size_t Print::print(const char s[])
 size_t Print::print(double value, int digits)
 {
     char tmp[32];
-    sprintf(tmp, "%.*lg", digits+1, value);
+    sprintf(tmp, "%.*g", digits+1, value);
     return print(tmp);
 }
 

+ 28 - 0
src/CMakeLists.txt

@@ -3,4 +3,32 @@ file(GLOB_RECURSE SRC_FILES *.cpp)
 
 include_directories(../include)
 
+if(CMAKE_COMPILER_IS_GNUCXX)
+	add_definitions(
+		-Wall
+		-Wcast-align
+		-Wcast-qual
+		-Wctor-dtor-privacy
+		-Wdisabled-optimization
+		-Wextra
+		-Wformat=2
+		-Winit-self
+		-Wlogical-op
+		-Wmissing-include-dirs
+		-Wno-parentheses
+		-Wno-unused
+		-Wno-variadic-macros
+		-Wnoexcept
+		-Wold-style-cast
+		-Woverloaded-virtual
+		-Wpedantic
+		-Wredundant-decls
+		-Wshadow
+		-Wsign-promo
+		-Wstrict-null-sentinel
+		-Wstrict-overflow=5
+		-Wundef
+	)
+endif()
+
 add_library(ArduinoJson ${SRC_FILES} ${INC_FILES})

+ 3 - 3
src/JsonContainer.cpp

@@ -71,13 +71,13 @@ void JsonContainer::removeChild(JsonNode* childToRemove)
 
 size_t JsonContainer::size() const
 {
-    int size = 0;
+    int n = 0;
 
     for (JsonNodeIterator it = beginChildren(); it != endChildren(); ++it)
     {
-        size++;
+        n++;
     }
 
-    return size;
+    return n;
 }