UB or not
-
I had an interesting question and confusion in my head, const QList<qlonglong>& keys = storeTypeChat.keys(); (storeTypeChat - QList) why there will be no dangling reference?
-
I had an interesting question and confusion in my head, const QList<qlonglong>& keys = storeTypeChat.keys(); (storeTypeChat - QList) why there will be no dangling reference?
-
@Christian-Ehrlicher then it turns out that this is still a dangling ref?
-
@Christian-Ehrlicher then it turns out that this is still a dangling ref?
-
@DmitryTS
Define exactly what you mean/think of "dangling reference" here.
Given @Christian-Ehrlicher's response ofBecause the function returns a value which gets destroyed when the constant ref gets destroyed.
-
You mean from the point of the function call till the end of the reference's/function's lifetime? Yes! Rather than my picking a reference for you, Googling
c++ constant reference extend the life of this temporary object or not
will give you various confirmatory links.I believe you are using an lvalue here (
const QList<qlonglong>& keys = ...
), and for that you must useconst
for lifetime extension, apparently. -