Turned warnings-as-errors on by default.
authorAndrew Woloszyn <awoloszyn@google.com>
Thu, 19 Nov 2015 14:22:53 +0000 (09:22 -0500)
committerAndrew Woloszyn <awoloszyn@google.com>
Thu, 19 Nov 2015 14:46:59 +0000 (09:46 -0500)
Fixed a few warnings that appear in builds on VS2013 and VS2015.

CMakeLists.txt
README.md
source/binary.cpp [changed mode: 0644->0755]
source/text.cpp [changed mode: 0644->0755]
test/HexFloat.cpp [changed mode: 0644->0755]

index e35b8d5..6826b98 100644 (file)
@@ -43,6 +43,7 @@ if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
   set(CMAKE_BUILD_TYPE "Debug")
 endif()
 
+option(SPIRV_WERROR "Enable error on warning" ON)
 if(UNIX)
   set(SPIRV_WARNINGS -Wall -Wextra -Wno-missing-field-initializers)
 
@@ -52,12 +53,15 @@ if(UNIX)
       -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded)
   endif()
 
-  option(SPIRV_WERROR "Enable error on warning" OFF)
   if(${SPIRV_WERROR})
     set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Werror)
   endif()
 elseif(WIN32)
   set(SPIRV_WARNINGS -D_CRT_SECURE_NO_WARNINGS /wd4800)
+
+  if(${SPIRV_WERROR})
+    set(SPIRV_WARNINGS ${SPIRV_WARNINGS} /WX)
+  endif()
 endif()
 
 option(SPIRV_COLOR_TERMINAL "Enable color terminal output" ON)
index c5956e2..7219fed 100644 (file)
--- a/README.md
+++ b/README.md
@@ -96,8 +96,8 @@ The following CMake options are supported:
   This should only be used with a debug build. Disabled by default.
 * `SPIRV_WARN_EVERYTHING=OFF` - On UNIX platforms enable the `-Weverything`
   compiler front end option, disabled by default.
-* `SPIRV_WERROR=OFF` - On UNIX platforms enable the `-Werror` compiler front end
-  option, disabled by default.
+* `SPIRV_WERROR=ON` - Forces a compilation error on any warnings encountered by
+  enabling the compiler-specific compiler front-end option, enabled by default.
 
 ## Library
 
old mode 100644 (file)
new mode 100755 (executable)
index 8657c55..3ce9ee0
@@ -318,7 +318,7 @@ spv_result_t Parser::parseInstruction() {
       opcode_desc->operandTypes + opcode_desc->numTypes);
 
   while (_.word_index < inst.offset + inst_word_count) {
-    const uint16_t inst_word_index = _.word_index - inst.offset;
+    const uint16_t inst_word_index = uint16_t(_.word_index - inst.offset);
     if (expected_operands.empty()) {
       return diagnostic() << "Invalid instruction Op" << opcode_desc->name
                           << " starting at word " << inst.offset
@@ -354,7 +354,7 @@ spv_result_t Parser::parseInstruction() {
   // Must wait until here to set the inst.operands pointer because the vector
   // might be resized while we accumulate itse elements.
   inst.operands = operands.data();
-  inst.num_operands = operands.size();
+  inst.num_operands = uint16_t(operands.size());
 
   // Issue the callback.  The callee should know that all the storage in inst
   // is transient, and will disappear immediately afterward.
@@ -371,7 +371,7 @@ spv_result_t Parser::parseOperand(spv_parsed_instruction_t* inst,
                                   spv_operand_pattern_t* expected_operands) {
   // We'll fill in this result as we go along.
   spv_parsed_operand_t parsed_operand;
-  parsed_operand.offset = _.word_index - inst->offset;
+  parsed_operand.offset = uint16_t(_.word_index - inst->offset);
   // Most operands occupy one word.  This might be be adjusted later.
   parsed_operand.num_words = 1;
   // The type argument is the one used by the grammar to parse the instruction.
@@ -526,7 +526,7 @@ spv_result_t Parser::parseOperand(spv_parsed_instruction_t* inst,
                             << std::numeric_limits<uint16_t>::max()
                             << " words: " << string_num_words << " words long";
       }
-      parsed_operand.num_words = string_num_words;
+      parsed_operand.num_words = uint16_t(string_num_words);
       parsed_operand.type = SPV_OPERAND_TYPE_LITERAL_STRING;
 
       if (SpvOpExtInstImport == inst->opcode) {
old mode 100644 (file)
new mode 100755 (executable)
index 3ebde21..18c4d50
@@ -645,7 +645,7 @@ spv_result_t spvTextEncodeOpcode(const libspirv::AssemblyGrammar& grammar,
            << SPV_LIMIT_INSTRUCTION_WORD_COUNT_MAX;
   }
 
-  pInst->words[0] = spvOpcodeMake(pInst->words.size(), opcodeEntry->opcode);
+  pInst->words[0] = spvOpcodeMake(uint16_t(pInst->words.size()), opcodeEntry->opcode);
 
   return SPV_SUCCESS;
 }
old mode 100644 (file)
new mode 100755 (executable)
index d73f6f4..3fdea66
 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 // MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
 
-#ifdef _MSC_VER
-// We define this so that we can use sscanf in the tests without
-// MSVC warning us all the time.
-#define _CRT_SECURE_NO_WARNINGS
-#endif
-
 #include <cmath>
 #include <cstdio>
 #include <sstream>