From 093e367e14405895f0d60f96bc9cee2ff44f3375 Mon Sep 17 00:00:00 2001
From: Botond Baranyi <botond.baranyi@ericsson.com>
Date: Thu, 11 Mar 2021 11:12:07 +0100
Subject: [PATCH] OOP: code generated for 'finally' now only uses C++11 if it
 is supported by the C++ compiler (Bug 568899)

Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com>
Change-Id: I75568c10eae09937187317bb6d03cac2e0cfe636
---
 compiler2/ttcn3/Statement.cc | 8 +++++---
 core/OOP.hh                  | 2 ++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/compiler2/ttcn3/Statement.cc b/compiler2/ttcn3/Statement.cc
index bd76e24e6..8b97d8fd1 100644
--- a/compiler2/ttcn3/Statement.cc
+++ b/compiler2/ttcn3/Statement.cc
@@ -518,12 +518,12 @@ namespace Ttcn {
     }
     if (finally_block != NULL) {
       string tmp_id = get_scope_mod_gen()->get_temporary_id();
-      /*str = mputprintf(str,
+#if __cplusplus < 201103L
+      str = mputprintf(str,
         "class %s_finally {\n"
         "public:\n", tmp_id.c_str());
       // TODO: all local declarations (or those referenced in the 'finally' block) need to
       // be added as members of this class, so the destructor can reach them
-      // or the C++11 code could be used...
       if (include_location_info) {
         str = mputprintf(str,
           "TTCN_Location& current_location;\n"
@@ -538,12 +538,14 @@ namespace Ttcn {
         "};\n"
         "%s_finally %s%s;\n",
         tmp_id.c_str(), tmp_id.c_str(),
-        include_location_info ? "(current_location)" : "");*/
+        include_location_info ? "(current_location)" : "");
+#else
       // C++11 version:
       str = mputprintf(str,
         "FINALLY %s([&] {\n", tmp_id.c_str());
       str = finally_block->generate_code(str, def_glob_vars, src_glob_vars);
       str = mputstr(str, "});\n");
+#endif
     }
     if (catch_blocks.size() > 0) {
       str = mputstr(str, "try {\n");
diff --git a/core/OOP.hh b/core/OOP.hh
index d862def76..2d11e25f8 100644
--- a/core/OOP.hh
+++ b/core/OOP.hh
@@ -284,6 +284,7 @@ public:
   T& operator()() { return *exc_ptr->val_ptr; }
 };
 
+#if __cplusplus >= 201103L
 class FINALLY
 {
   std::function<void(void)> functor;
@@ -294,6 +295,7 @@ public:
     functor();
   }
 };
+#endif // C++11
 
 #endif /* OOP_HH */
 
-- 
GitLab