View Issue Details

IDProjectCategoryView StatusLast Update
0004268OpenFOAMBugpublic2025-08-24 18:05
Reporterjacob Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
PlatformMinGW-w64OSWindowsOS Version11
Product Version13 
Summary0004268: Thermo relies on specific ordering of global constructors in separate translation units
DescriptionThe static attributes `derivedThermoName` in thermo classes are initialized in different translation units (e.g. "psiThermo.C") than in which they are used to populate run-time selection tables (e.g. "psiThermos.C") by means of other constructors.

While it seems to work well for common workflow using GNU ld on Linux, in general this is an undefined behaviour in C++ ( https://isocpp.org/wiki/faq/ctors#static-init-order ).

I actually ran into this problem with the MinGW-w64 compiler in Cygwin64 on Windows 11. There, apparently, `derivedThermoName` was not initialized prior to its use in the `defineThermo` macro, resulting in empty string being used to compute the amalgamated thermo name entering the constructor table. As a consequence, thermo models based on distinct basic models (`psiThermo`, `rhoFluidThermo`, etc.) produced identical run-time selection table entries, causing the solver to fail, complaining about the duplicates.

I was able to work around this issue by changing the static attribute `derivedThermoName` to an inline static function of the same name that returned the required string. The macro `defineThermo` then simply called that function.
TagsNo tags attached.

Issue History

Date Modified Username Field Change
2025-08-24 17:44 jacob New Issue
2025-08-24 18:05 henry Note Added: 0013654