From 53a5aec89998a58dff53946b47426ea692c5ad8d Mon Sep 17 00:00:00 2001 From: R2RT Date: Sun, 4 Nov 2018 23:05:35 +0100 Subject: CMP0053: Fix double warning on uninitialized variables in -P mode When `CMP0053` is not set to OLD or NEW then we compute both variants in case we need to warn about a behavior change. Do not allow both code paths to produce an uninitialized variable warning. Fixes: #18552 --- Source/cmMakefile.cxx | 2 +- Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 4 ++++ Tests/RunCMake/CommandLine/warn-uninitialized-stderr.txt | 5 +++++ Tests/RunCMake/CommandLine/warn-uninitialized.cmake | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/CommandLine/warn-uninitialized-stderr.txt create mode 100644 Tests/RunCMake/CommandLine/warn-uninitialized.cmake diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 83139ba..0d42fb0 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2766,7 +2766,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew( } else { varresult = value; } - } else if (!removeEmpty) { + } else if (!removeEmpty && !this->SuppressSideEffects) { // check to see if we need to print a warning // if strict mode is on and the variable has // not been "cleared"/initialized with a set(foo ) call diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index b47abfb..ef48852 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -348,6 +348,10 @@ set(RunCMake_TEST_OPTIONS --trace-expand --warn-uninitialized) run_cmake(trace-expand-warn-uninitialized) unset(RunCMake_TEST_OPTIONS) +set(RunCMake_TEST_OPTIONS --warn-uninitialized) +run_cmake(warn-uninitialized) +unset(RunCMake_TEST_OPTIONS) + set(RunCMake_TEST_OPTIONS --trace-source=trace-only-this-file.cmake) run_cmake(trace-source) unset(RunCMake_TEST_OPTIONS) diff --git a/Tests/RunCMake/CommandLine/warn-uninitialized-stderr.txt b/Tests/RunCMake/CommandLine/warn-uninitialized-stderr.txt new file mode 100644 index 0000000..a13402a --- /dev/null +++ b/Tests/RunCMake/CommandLine/warn-uninitialized-stderr.txt @@ -0,0 +1,5 @@ +^CMake Warning \(dev\) at warn-uninitialized.cmake:1 \(set\): + uninitialized variable 'WARN_FROM_NORMAL_CMAKE_FILE' +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) +This warning is for project developers. Use -Wno-dev to suppress it.$ diff --git a/Tests/RunCMake/CommandLine/warn-uninitialized.cmake b/Tests/RunCMake/CommandLine/warn-uninitialized.cmake new file mode 100644 index 0000000..f1a75c9 --- /dev/null +++ b/Tests/RunCMake/CommandLine/warn-uninitialized.cmake @@ -0,0 +1 @@ +set(FOO "${WARN_FROM_NORMAL_CMAKE_FILE}") -- cgit v0.12