Macro processor: gracefully fail when argument to @#ifdef/@#ifndef is not a variable name

Ref. dynare#1771
issue#70
Sébastien Villemot 2021-01-22 12:20:13 +01:00
parent ec66768a63
commit 4c14dc3fbf
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
1 changed files with 4 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright © 2019-2020 Dynare Team * Copyright © 2019-2021 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
@ -253,7 +253,9 @@ If::interpret(ostream &output, Environment &env, vector<filesystem::path> &paths
{ {
first_clause = false; first_clause = false;
VariablePtr vp = dynamic_pointer_cast<Variable>(expr); VariablePtr vp = dynamic_pointer_cast<Variable>(expr);
assert(vp); if (!vp)
error(StackTrace(ifdef ? "@#ifdef" : "@ifndef",
"The condition must be a variable name", location));
if ((ifdef && env.isVariableDefined(vp->getName())) if ((ifdef && env.isVariableDefined(vp->getName()))
|| (ifndef && !env.isVariableDefined(vp->getName()))) || (ifndef && !env.isVariableDefined(vp->getName())))
{ {