ukaea / UDA

Universal Data Access library to provide data over the network in a unified data object.
https://ukaea.github.io/UDA/
Apache License 2.0
11 stars 4 forks source link

Refactor `udaLog` from variadic function to variadic template #29

Open maarten-ic opened 8 months ago

maarten-ic commented 8 months ago

Currently udaLog is a variadic function.

This has a number of downsides (as listed on cppreference.com). The current usage is also not strictly conformant to ISO C++11, as you can observe when adding the -Wpedantic flag:

/home/maarten/projects/UDA/source/client2/client.cpp:276:85: error: ISO C++11 requires at least one argument for the "..." in a variadic macro [-Werror]
  276 |         UDA_LOG(UDA_LOG_DEBUG, "Receiving Hierarchical Data Structure from Server\n");

There's also an issue when compiling release 2.7.4 with the intel c++ compiler (icpc, version 2020.4.304), related to the same:

FAILED: source/client2/CMakeFiles/client2-objects.dir/client.cpp.o
<...>
icpc: command line warning #10148: option '-Wno-use-after-free' not supported
icpc: command line warning #10148: option '-Wno-mismatched-new-delete' not supported
/tmp/<...>/EasyBuild/UDA/2.7.4/iccifort-2020.4.304/UDA-2.7.4/source/client2/client.cpp(586): error #1595: non-POD (Plain Old Data) class type passed through ellipsis
              UDA_LOG(UDA_LOG_ERROR, "Error identifying the Data Source [%s]\n", data_source);
              ^compilation aborted for /tmp/<...>/EasyBuild/UDA/2.7.4/iccifort-2020.4.304/UDA-2.7.4/source/client2/client.cpp (code 2)

See https://jira.iter.org/browse/IMAS-5014 (behind login wall).

A better approach would be to use variadic templates as listed at the alternatives for variadic arguments