From d44c8318f095d9fbfbe7268a8197bfa46b1c1f59 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Tue, 11 Jan 2022 11:32:03 +0100
Subject: [PATCH] COMP: use automatic cleanup for run-time compat table (fixes
 #2314)

- occurs with newer gcc on ubuntu impish (gcc-11.2.0), but may perhaps
  actually be related to `-flto=auto` or to the destruction order of
  the static variables (race condition?).

  Leaving the compat table around for automatic cleanup does not
  impact on other lookups (which are nullptr checked anyhow).
---
 .../construction/runTimeSelectionTables.H                | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/OpenFOAM/db/runTimeSelection/construction/runTimeSelectionTables.H b/src/OpenFOAM/db/runTimeSelection/construction/runTimeSelectionTables.H
index d5fd13438d2..bf734f46730 100644
--- a/src/OpenFOAM/db/runTimeSelection/construction/runTimeSelectionTables.H
+++ b/src/OpenFOAM/db/runTimeSelection/construction/runTimeSelectionTables.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2019-2021 OpenCFD Ltd.
+    Copyright (C) 2019-2022 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -37,8 +37,8 @@ Description
 
 #include "token.H"
 
-#ifndef runTimeSelectionTables_H
-#define runTimeSelectionTables_H
+#ifndef Foam_runTimeSelectionTables_H
+#define Foam_runTimeSelectionTables_H
 
 #include <memory>   // For std::unique_ptr
 #include <utility>  // For std::pair
@@ -89,6 +89,7 @@ Description
 
 
 // Not used directly: storage and helper methods for runtime tables
+// - uses automatic cleanup for compat table (issue #2314)
 #define defineRunTimeSelectionTableBase(baseType,prefix,Tspecialize)           \
                                                                                \
     /* Define table singleton (storage) */                                     \
@@ -124,8 +125,6 @@ Description
         {                                                                      \
             delete prefix##TablePtr_;                                          \
             prefix##TablePtr_ = nullptr;                                       \
-            prefix##CompatTablePtr_.reset(nullptr);                            \
-            constructed = false;                                               \
         }                                                                      \
     }                                                                          \
                                                                                \
-- 
GitLab