godotengine / godotengine/godot-cpp
[3.4.2] register_method does not accept arguments passed by reference
- Dominant language
- C++
- Stars
- 2.7k
- Forks
- 809
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 8
Description
Let suppose a member method like this:
```
void Foo::bar(godot::String const name);
```
If we want to make it uses for GDNative script, we have to export it:
```
godot::register_method("bar", &Foo::bar);
```
This makes pass the string by copy and this works fine ! But now let pass `name` by reference:
```
void Foo::bar(godot::String const& name);
```
But this reference will produce a warning:
```
...
/home/qq/godot/3.4.2-stable/cpp/include/core/Godot.hpp:163:10: warning: returning reference to temporary [-Wreturn-local-addr]
163 | return a;
| ^
```
And possibly gives a crash. So How to deal: passing C++ reference with register_method ?
PS: register_method and C++ references worked well within Godot modules (C++ code inside the Godot editor code source inside the modules/ folder). I had no warnings.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.