From d6cb18ab15dfda62866e662d37ea039fc6001997 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?=
 <stephane.adjemian@univ-lemans.fr>
Date: Wed, 21 May 2014 16:41:41 +0200
Subject: [PATCH] Do not initialize subfields of options_ as empty structs if
 they are already defined (in global_initialization).

---
 preprocessor/Statement.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/preprocessor/Statement.cc b/preprocessor/Statement.cc
index 70889c6b2e..b72e4e24d8 100644
--- a/preprocessor/Statement.cc
+++ b/preprocessor/Statement.cc
@@ -135,7 +135,11 @@ OptionsList::writeOutput(ostream &output) const
 void
 OptionsList::writeOutput(ostream &output, const string &option_group) const
 {
-  output << option_group << " = struct();" << endl;
+  // Initialize option_group as an empty struct iff the field does not exist!
+  unsigned idx = option_group.find_last_of(".");
+  output << "if ~isfield(" << option_group.substr(0,idx) << ",'" << option_group.substr(idx+1) << "')" << endl;
+  output << "    " << option_group << " = struct();" << endl;
+  output << "end" << endl;
 
   for (num_options_t::const_iterator it = num_options.begin();
        it != num_options.end(); it++)
-- 
GitLab