layers: Fix MSVS conversion warning.
authorJamie Madill <jmadill@chromium.org>
Wed, 8 Nov 2017 21:25:22 +0000 (16:25 -0500)
committerMark Lobodzinski <mark@lunarg.com>
Mon, 27 Nov 2017 22:30:19 +0000 (15:30 -0700)
This fixes the following:

warning C4245: 'argument': conversion from 'int' to 'unsigned int', signed/unsigned mismatch

It also modifies the build to enable this warning by default.

Change-Id: If2e6c8d43811162a9a382883b3d55a148975fc37

CMakeLists.txt
layers/shader_validation.cpp
libs/vkjson/vkjson_info.cc

index 785d6fc..83b9ef2 100644 (file)
@@ -96,6 +96,8 @@ if(WIN32)
     add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/w34703>")
     # Warn about different indirection types.
     add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/w34057>")
+    # Warn about signed/unsigned mismatch.
+    add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/w34245>")
 endif()
 
 if(NOT WIN32)
index ff3a84b..11fcbdc 100644 (file)
@@ -584,8 +584,8 @@ static std::map<location_t, interface_var> collect_interface_by_location(shader_
             unsigned id = insn.word(2);
             unsigned type = insn.word(1);
 
-            int location = value_or_default(var_locations, id, -1);
-            int builtin = value_or_default(var_builtins, id, -1);
+            int location = value_or_default(var_locations, id, static_cast<unsigned>(-1));
+            int builtin = value_or_default(var_builtins, id, static_cast<unsigned>(-1));
             unsigned component = value_or_default(var_components, id, 0);  // Unspecified is OK, is 0
             bool is_patch = var_patch.find(id) != var_patch.end();
             bool is_relaxed_precision = var_relaxed_precision.find(id) != var_relaxed_precision.end();
index 9dbf02b..3c4b08b 100644 (file)
@@ -57,7 +57,7 @@ bool ParseOptions(int argc, char* argv[], Options* options) {
       if (arg == "--device-index" || arg == "-d") {
         int result = sscanf(arg2.c_str(), "%u", &options->device_index);
         if (result != 1) {
-          options->device_index = -1;
+          options->device_index = static_cast<uint32_t>(-1);
           std::cerr << "Unable to parse index: " << arg2 << std::endl;
           return false;
         }