summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-03-22 13:24:35 (GMT)
committerKitware Robot <kwrobot@kitware.com>2017-03-22 13:24:49 (GMT)
commit5d2f30f5acbcf572a464f6f45fafaea23c7ae75a (patch)
tree75d2ab147b055a443e68b86ac29eba17b3fab761 /Source
parente24ed7ad870730304431f5cb09d90c980136639c (diff)
parentedac95b955afdea2d129b32b029bf845dc29cb71 (diff)
downloadCMake-5d2f30f5acbcf572a464f6f45fafaea23c7ae75a.zip
CMake-5d2f30f5acbcf572a464f6f45fafaea23c7ae75a.tar.gz
CMake-5d2f30f5acbcf572a464f6f45fafaea23c7ae75a.tar.bz2
Merge topic '14335-duplicate-else'
edac95b9 cmIfCommand: Reject duplicate else() and misplaced elseif() Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !594
Diffstat (limited to 'Source')
-rw-r--r--Source/cmIfCommand.cxx20
-rw-r--r--Source/cmIfCommand.h2
2 files changed, 22 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 {
diff --git a/Source/cmIfCommand.h b/Source/cmIfCommand.h
index 56eef30..f81db67 100644
--- a/Source/cmIfCommand.h
+++ b/Source/cmIfCommand.h
@@ -21,6 +21,7 @@ public:
cmIfFunctionBlocker()
{
this->HasRun = false;
+ this->ElseSeen = false;
this->ScopeDepth = 0;
}
~cmIfFunctionBlocker() CM_OVERRIDE {}
@@ -32,6 +33,7 @@ public:
std::vector<cmListFileFunction> Functions;
bool IsBlocking;
bool HasRun;
+ bool ElseSeen;
unsigned int ScopeDepth;
};