diff options
author | Gregor Jasny <gjasny@googlemail.com> | 2017-03-20 20:49:59 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-03-22 12:42:35 (GMT) |
commit | edac95b955afdea2d129b32b029bf845dc29cb71 (patch) | |
tree | cf96ba88c3e04fe23daa131817e92dd51515561a /Source/cmIfCommand.cxx | |
parent | 3be5896e013492cbe1cf65c1c61822b68d9d59c4 (diff) | |
download | CMake-edac95b955afdea2d129b32b029bf845dc29cb71.zip CMake-edac95b955afdea2d129b32b029bf845dc29cb71.tar.gz CMake-edac95b955afdea2d129b32b029bf845dc29cb71.tar.bz2 |
cmIfCommand: Reject duplicate else() and misplaced elseif()
Closes: #14335
Diffstat (limited to 'Source/cmIfCommand.cxx')
-rw-r--r-- | Source/cmIfCommand.cxx | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index a8fa4f9..421c3dd 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -57,8 +57,19 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, // watch for our state change if (scopeDepth == 0 && !cmSystemTools::Strucmp(this->Functions[c].Name.c_str(), "else")) { + + if (this->ElseSeen) { + cmListFileBacktrace bt = mf.GetBacktrace(this->Functions[c]); + mf.GetCMakeInstance()->IssueMessage( + cmake::FATAL_ERROR, + "A duplicate ELSE command was found inside an IF block.", bt); + cmSystemTools::SetFatalErrorOccured(); + return true; + } + this->IsBlocking = this->HasRun; this->HasRun = true; + this->ElseSeen = true; // if trace is enabled, print a (trivially) evaluated "else" // statement @@ -68,6 +79,15 @@ bool cmIfFunctionBlocker::IsFunctionBlocked(const cmListFileFunction& lff, } else if (scopeDepth == 0 && !cmSystemTools::Strucmp(this->Functions[c].Name.c_str(), "elseif")) { + if (this->ElseSeen) { + cmListFileBacktrace bt = mf.GetBacktrace(this->Functions[c]); + mf.GetCMakeInstance()->IssueMessage( + cmake::FATAL_ERROR, + "An ELSEIF command was found after an ELSE command.", bt); + cmSystemTools::SetFatalErrorOccured(); + return true; + } + if (this->HasRun) { this->IsBlocking = true; } else { |