MacOS compilation errors RESTFramework TRestDataSetOdds.cxx

REST version : v2.3.15
REST commit : 3b4459c.
ROOT version: v6.26/06
Geant4 version: v11.0.3
Garfield version: 6
cmake version: 3.25.2
Systems: macOS Monterey v. 12.6.3 (Intel i5 chip), macOS Monterey v. 12.5 (Apple M1 Pro chip).

Dear REST experts,

I just wanted to test the fixes for the MacOS REST installations, described in this post: macOS installation issue: missing files, headers, bin on my local MacOS devices.
However, unfortunately I get some compilation errors within the TRestDataSetOdds.cxx in the latest (02.05.2023) RESTFramework commit, for both devices, see below:

/Users/heucheld/software/rest_test_new/framework/source/framework/analysis/src/TRestDataSetOdds.cxx:242:29: error: ‘histo’ in capture list does not name a variable
auto GetLogOdds = [&histo](double val) {
^
/Users/heucheld/software/rest_test_new/framework/source/framework/analysis/src/TRestDataSetOdds.cxx:243:27: error: reference to local binding ‘histo’ declared in enclosing function ‘TRestDataSetOdds::ComputeLogOdds’
double odds = histo->GetBinContent(histo->GetXaxis()->FindBin(val));
^
/Users/heucheld/software/rest_test_new/framework/source/framework/analysis/src/TRestDataSetOdds.cxx:240:32: note: ‘histo’ declared here
for (const auto& [obsName, histo] : fHistos) {
^
/Users/heucheld/software/rest_test_new/framework/source/framework/analysis/src/TRestDataSetOdds.cxx:243:48: error: reference to local binding ‘histo’ declared in enclosing function ‘TRestDataSetOdds::ComputeLogOdds’
double odds = histo->GetBinContent(histo->GetXaxis()->FindBin(val));

Something stupid from my side? Can you help with that?

Cheers,
Daniel

I think this is coming from a new construction that we do not use frequently in our codes. Perhaps Clang MacOs is not compatible with this?

It is as a function definition constructed inside the method itself.

        auto GetLogOdds = [&histo](double val) {
            double odds = histo->GetBinContent(histo->GetXaxis()->FindBin(val));
            if (odds == 0) return 1000.;
            return log(1. - odds) - log(odds);
        };

@juanan318 Cannot be this implemented differently? Or do you know how to bypass the error in MacOs?

Aparently, there is a bug in clang and structure bindings are not captured in lambda expressions c++ - Lambda implicit capture fails with variable declared from structured binding - Stack Overflow. So, there is not much that you can do from your side.

I have created a PR trying to address this issue Addressing compilation issue in macOS introduced on TRestDataSetOdds by juanangp · Pull Request #415 · rest-for-physics/framework · GitHub

-        auto GetLogOdds = [&histo](double val) {
+       auto GetLogOdds = [&histo = histo](double val) {

Changes are minimal, perhaps you can try to add these changes and compile locally before merging the PR.

1 Like

Hi Juanan and Javier,

thanks for your fast replies and checks!

Yes, it works and I can successfully compile full REST locally on my Mac with your fix now.

I will approve the PR soon.

Cheers,
Daniel