From 60f72e96fae8a6d044affefea1b3ec65e6049d16 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Fri, 22 Jan 2021 12:20:13 +0100
Subject: [PATCH] Macro processor: gracefully fail when argument to
 @#ifdef/@#ifndef is not a variable name

Ref. dynare#1771

(cherry picked from commit 4c14dc3fbf17bed9cfd66a8d86b5eb57aba39a6e)
---
 src/macro/Directives.cc | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/macro/Directives.cc b/src/macro/Directives.cc
index d12a0f29..dde0b377 100644
--- a/src/macro/Directives.cc
+++ b/src/macro/Directives.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019-2020 Dynare Team
+ * Copyright © 2019-2021 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -253,7 +253,9 @@ If::interpret(ostream &output, vector<filesystem::path> &paths)
           {
             first_clause = false;
             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()))
                 || (ifndef && !env.isVariableDefined(vp->getName())))
               {
-- 
GitLab