Commit b4c4aa5
committed
GCC/Clang: Turn -Wdangling-reference into error, if available
you usually get that when calling a method that returns a reference on
a temporary and assigning that to a reference variable.
Often nasty do debug...
Example:
idVec3 v1 = ...;
idVec3 v2 = ...;
const idVec2& cross2d = v1.Cross(v2).ToVec2();
idVec3::Cross(const idVec3 &a) returns idVec3, i.e. a temporary, and
idVec3::ToVec2() returns a reference to the idVec2 part of an idVec3.
That temporary is gone after that line and cross2d points to invalid
memory..
(I found this change in another branch, don't remember what triggered
me creating it, might even have been a bug in another project, but
either way it's great that compilers can now warn about this and
if they do that should be treated as an error and be resolved.)1 parent 88f7b8c commit b4c4aa5
1 file changed
+5
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
420 | 425 | | |
421 | 426 | | |
422 | 427 | | |
| |||
0 commit comments