What is wrong with this code?

I have the following code in a source file:

#include <iostream>
#include <string>

struct Foo{ std::string name; };

Foo getDefaultFoo(){
	Foo f;
	f.name = "test";
	return f;
}
void test(Foo f = getDefaultFoo()) {
	std::cout << f.name << std::endl;
}

When I compile it, it works as expected, but when I run it in the interpreter I get a segmentation violation:

root [0] .L testScript.cxx
root [1] test()

 *** Break *** segmentation violation

Why is this happening? What is causing this error?

Interestingly I also get a segmentation violation when load the file (".L") and type only “test” and then press tab (which should show me the possible function signatures).

I also tried to change the code to this:

struct Foo{
	std::string name;
	Foo() : name("test") {}
};


void test(Foo f = Foo()){
	std::cout << f.name << std::endl;
}

but it keeps crashing with a segmentation violation…

I am using root 5.43 and even if I could compile it I would like to know why the interpreter doesnt swallow it, because the code is part of some bigger code that I cannot compile (unless I change lots of code).

Hi,

I tried on ROOT 6.06.02 and everything ran flawlessly.
I wonder if updating is an option for you.

Danilo

Thanks for you reply.
Updating is not really an option at the moment. Anyhow, I already found a workaround for my actual problem. I was asking more out of curiosity, to know what to avoid in the future (until updating to root 6). My guess at the moment is that the problem is caused by the default parameter being a function call (or constructor call).