C++17 structured binding not working in ROOT prompt

@Axel I found that structured binding seems not to be working under ROOT’s prompt or in a macro, but does work when using it in ACLiC or as a script.

For example:

▶ root -l         
root [0] auto [a, b] = tuple(1, 2)
(std::tuple<int, int> &) { 1, 2 }
root [1] a
input_line_11:2:3: error: use of undeclared identifier 'a'
Error in <HandleInterpreterException>: Error evaluating expression (a).
Execution of your code was aborted.
//	auto [a, b] = tuple(1, 2);
//	cout << a << endl;
▶ root -l       
root [0] .x macro.cpp
<ROOT crash>

But this does work

//void script() {
//	auto [a, b] = tuple(1, 2);
//	cout << a << endl;
▶ root -l       
root [0] .x script.cpp

Am I doing anything wrong? This would be a useful feature to reduce the number of lines I write in the prompt.

For C++17 support, your ROOT binaries must be built with “-Dcxx17=ON”, which is NOT the default.

Sorry for not being clear. I installed ROOT from Arch Linux’s repository. Which does have C++17 enabled. Otherwise the expresstion tuple(1, 2) should be ill-formed as template type deduction is introduced in C++17.

And to proof that.

root [0] __cplusplus
(long) 201703

Thanks for the report. That’s likely just a bug, I will look at it in two weeks when back from vacation. Please ping me should you not hear back from me.


@Axel Do you have have updates about the bug?

Thanks for the ping! I still didn’t manage to look at it (and will not manage this week). I have created https://sft.its.cern.ch/jira/browse/ROOT-10291 to not forget about it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.