1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

if: Add warning when elseif has no argument

Resolves: #26442
This commit is contained in:
Aliochat
2025-04-12 14:53:09 +02:00
committed by Brad King
parent 2cdf95ff86
commit 2a8bc1c4aa
4 changed files with 16 additions and 0 deletions

View File

@@ -107,6 +107,12 @@ bool cmIfFunctionBlocker::Replay(std::vector<cmListFileFunction> functions,
return true; return true;
} }
if (func.Arguments().empty()) {
mf.GetCMakeInstance()->IssueMessage(
MessageType::AUTHOR_WARNING,
"ELSEIF called with no arguments, it will be skipped. ", elseifBT);
}
if (this->HasRun) { if (this->HasRun) {
this->IsBlocking = true; this->IsBlocking = true;
} else { } else {

View File

@@ -16,6 +16,7 @@ run_cmake(duplicate-deep-else)
run_cmake(duplicate-else) run_cmake(duplicate-else)
run_cmake(duplicate-else-after-elseif) run_cmake(duplicate-else-after-elseif)
run_cmake(elseif-message) run_cmake(elseif-message)
run_cmake(empty-elseif-warning)
run_cmake(misplaced-elseif) run_cmake(misplaced-elseif)
run_cmake(unbalanced-parenthesis) run_cmake(unbalanced-parenthesis)

View File

@@ -0,0 +1,5 @@
CMake Warning \(dev\) at empty-elseif-warning.cmake:3 \(elseif\):
ELSEIF called with no arguments, it will be skipped.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.

View File

@@ -0,0 +1,4 @@
if(0)
elseif(${emptyVar}) # okay
elseif() # warns
endif()