Explorar el Código

cmake: Fix processing of -Wno-error= flags

Fix two bugs that happened to cancel each other out for cases covered
by our test suite.  Add a test case that distinguishes them.
Brad King hace 5 años
padre
commit
d800c26ce9
Se han modificado 2 ficheros con 12 adiciones y 3 borrados
  1. 8 3
      Source/cmake.cxx
  2. 4 0
      Tests/RunCMake/CommandLine/RunCMakeTest.cmake

+ 8 - 3
Source/cmake.cxx

@@ -427,12 +427,12 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
       bool foundError = false;
       unsigned int nameStartPosition = 0;
 
-      if (entry.find("no-", nameStartPosition) == 0) {
+      if (entry.find("no-", nameStartPosition) == nameStartPosition) {
         foundNo = true;
         nameStartPosition += 3;
       }
 
-      if (entry.find("error=", nameStartPosition) == 0) {
+      if (entry.find("error=", nameStartPosition) == nameStartPosition) {
         foundError = true;
         nameStartPosition += 6;
       }
@@ -454,7 +454,12 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args)
         this->DiagLevels[name] = DIAG_ERROR;
       } else {
         // -Wno-error=<name>
-        this->DiagLevels[name] = std::min(this->DiagLevels[name], DIAG_WARN);
+        // This can downgrade an error to a warning, but should not enable
+        // or disable a warning in the first place.
+        auto dli = this->DiagLevels.find(name);
+        if (dli != this->DiagLevels.end()) {
+          dli->second = std::min(dli->second, DIAG_WARN);
+        }
       }
     } else if (cmHasLiteralPrefix(arg, "-U")) {
       std::string entryPattern = arg.substr(2);

+ 4 - 0
Tests/RunCMake/CommandLine/RunCMakeTest.cmake

@@ -671,6 +671,10 @@ set(RunCMake_TEST_OPTIONS -Wno-error=deprecated)
 run_cmake(Wno-error_deprecated)
 unset(RunCMake_TEST_OPTIONS)
 
+set(RunCMake_TEST_OPTIONS -Werror=deprecated -Wno-error=deprecated)
+run_cmake(Wno-error_deprecated)
+unset(RunCMake_TEST_OPTIONS)
+
 # Dev warnings should be on by default
 run_cmake(Wdev)