Comments (7)
Sorry, I didn't read closely and thought you meant the null_value
.
it->second
can never be a dangling reference since it's inside the map. You should test the other thing instead.
from minetest.
Actually, thinking about it again, the result is a prvalue (because of the lvalue-to-rvalue conversions), but we return an lvalue reference. So maybe there is a temporary object, that binds to the lvalue reference, resulting in a dangling reference.
On the other hand, 4) says, it's a glvalue:
- If E2 and E3 are glvalues of the same type and the same value category, then the result has the same type and value category
This C++17 standard draft I found doesn't say at this point that it's a prvalue:
—(7.1) The second and third operands have the same type; the result is of that type and the result object is
initialized using the selected operand.
So, maybe we should read this as "the conversions are applied if necessary":
- The lvalue-to-rvalue, array-to-pointer, and function-to-pointer conversions are applied to the second and third operands.
Anyway, we can just replace the ternary with an if.
from minetest.
I was unable to reproduce the warning on GCC nor do GCC Asan or Valgrind report any errors running the following unit test:
Have you treid a non-trivial type?
Or perhaps even one that prints in its con-/destructor?
from minetest.
void TestDataStructures::testMap2()
{
ModifySafeMap<int, Tracker> map;
TrackerState t0, t1;
// overwrite
map.put(1, Tracker(t0));
map.put(1, Tracker(t1));
std::cerr << "EVERYTHING PUT!\n";
UASSERT(map.get(1));
std::cerr << "GOT!\n";
UASSERT(t0.deleted);
UASSERT(!t1.copied);
UASSERT(!t1.deleted);
map.clear();
}
CONSTRUCTOR2
CONSTRUCTOR1
MOVE ASSIGNMENT
DESTRUCTOR
CONSTRUCTOR2
MOVE ASSIGNMENT
DESTRUCTOR
EVERYTHING PUT!
GOT!
DESTRUCTOR
[PASS] testMap2 - 2ms
I think it's a false positive.
from minetest.
Whoops, it may be necessary to test both.
void TestDataStructures::testMap2()
{
ModifySafeMap<int, Tracker> map;
TrackerState t0, t1;
// overwrite
map.put(1, Tracker(t0));
map.put(1, Tracker(t1));
std::cerr << "EVERYTHING PUT!\n";
UASSERT(!map.get(-1));
std::cerr << "GOT!\n";
UASSERT(t0.deleted);
UASSERT(!t1.copied);
UASSERT(!t1.deleted);
map.clear();
}
CONSTRUCTOR2
CONSTRUCTOR1
MOVE ASSIGNMENT
DESTRUCTOR
CONSTRUCTOR2
MOVE ASSIGNMENT
DESTRUCTOR
EVERYTHING PUT!
GOT!
DESTRUCTOR
[PASS] testMap2 - 0ms
It looks like the null value doesn't get converted to a temporary either.
from minetest.
Are referring to this point?
6.1) If both E2 and E3 now have the same type, the result is a prvalue of that type designating a temporary object(until C++17)whose result object is(since C++17) copy-initialized from whatever operand was selected after evaluating E1.
Since C++17, there's no temporary object. (Read it as: Result object of the prvalue will be copy-initialized from foo later, aka the prvalue points to foo. Not: The result of the expression is copy-initialized. (Easy to misread imo.))
(I didn't know there was a temporary object in pre 17. 👀)
from minetest.
Ah, phew, it seems safe in all cases since we're on C++17, then. I wonder if a bug report should be filed with MSVC?
(I'm not sure which one of the rules applies here, but that's probably the one. Even if I modify the code such that the result should be an l-value, which should not cause a temporary even pre-C++17, I still get the warning.)
from minetest.
Related Issues (20)
- Pointing problems when you stand exactly at (-10.5, ?, ?) HOT 1
- Cross compilation ready Dockerfile (for `arm` images) HOT 2
- interpolation does nothing on set_bone_override HOT 2
- Add something that moves to the shutdown screen HOT 4
- Unknown texture when shiftclicking item into full crafting grid HOT 3
- Particle spawner distance tweens
- minetest.register_on_die_entity HOT 7
- Allow texture packs to provide fallback styling for ui elements HOT 1
- Mapblock occlusion culling can hide visible geometry HOT 2
- [BUG] Pressing both "/" and "t" keys causes Minetest to be unresponsive HOT 5
- Texture won't load and everything is black HOT 1
- Segfault with minetest.get_worldpath() in async env HOT 2
- The move to SDL2 broke some keybinds under Linux/X11 HOT 5
- Linux Mint Freeze HOT 2
- Input text field blocks keyboard button from being pressed again
- What 3D modeller is recommended when making Minetest Mods models. HOT 1
- Minetest built with SDL conflicts with kwin_x11 compositing HOT 3
- Missing CURLPART_ZONEID on building with an old version of CURL HOT 2
- Smooth Rotation with set_yaw for lua entities HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minetest.