frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

C++: A prvalue is not a temporary

https://blog.knatten.org/2025/10/31/a-prvalue-is-not-a-temporary/
28•ingve•6d ago

Comments

dzdt•6d ago
[Edited] For anyone like me stuck on his language: the phrase "move from" should be understood as a technical term loosely related to the English language meaning of the words. I think the post would be better if he explained this terminology; as it is you have to know an awful lot about the topic he is writing about to even parse what he is saying.

There is a pretty good stack overflow post that quuxplusone linked below. How they explain it:

  Moving from lvalues

  Sometimes, we want to move from lvalues. That is, sometimes we want the compiler to treat an lvalue as if it were an rvalue, so it can invoke the move constructor, even though it could be potentially unsafe. For this purpose, C++11 offers a standard library function template called std::move inside the header <utility>. This name is a bit unfortunate, because std::move simply casts an lvalue to an rvalue; it does not move anything by itself. It merely enables moving. Maybe it should have been named std::cast_to_rvalue or std::enable_move, but we are stuck with the name by now.
quuxplusone•4d ago
"Move" in the sense of https://stackoverflow.com/questions/3106110/what-is-move-sem...

Now, if you don't know what "move semantics" is, then "lvalues can't be moved from" isn't terribly helpful, and if you do then it's tautological, so I'm not saying you're wrong to criticize. :) But in a C++ context, "move" does have a single specific meaning — the one he's using properly if opaquely-to-non-C++ers.

Conscat•1h ago
"move" means to pass into an r-value reference function parameter, for instance a move constructor, move assignment operator, or forwarding reference.
cjensen•1h ago
He has a good article on that at [1]

But here's the gist: sometimes you have an object you want to copy, but then abandon the original. Maybe it's to return an object from a function. Maybe it's to insert the object into a larger structure. In these cases, copying can be expensive and it would be nice if you could just "raid" the original object to steal bits of it and construct the "copy" out of the raided bits. C++11 enabled this with rvalue references, std::move, and rvalue reference constructors.

This added a lot of "what the hell is this" to C++ code and a lot of new mental-model stuff to track for programmers. I understand why it was all added, but I have deep misgivings about the added complexity.

[1] https://blog.knatten.org/2018/03/09/lvalues-rvalues-glvalues...

neonz80•24m ago
I find that this can reduce overall complexity. It makes it possible to use objects that can not be copied (such as a file descriptor wrapper) and moving can in most cases not fail. Without move semantics you'd have to use smart pointers to get similar results but with extra overhead.
Night_Thastus•2h ago
Interesting stuff! I knew about lvalues and rvalues but I never knew about concepts like "glvalue" or "prvalue" or "xvalue" that the linked page talks about.

It makes sense that C++ avoids unnecessary copying or object creation whenever possible, that's pretty much C++'s M.O.

im3w1l•1h ago
> People sometimes call this “a temporary”, but, as is the main point of this article, that’s not necessarily true.

Old habits die hard? It used to always create a temporary right?

gpderetta•45m ago
> It used to always create a temporary right?

Temporaries could still be elided in some cases before, but the semantics were still understood in terms of temporary objects.

Now some forms of elision are mandatory and elision+RVO semantics are understood as objects being directly created into the final named location.

p0w3n3d•1h ago
C++ is so complicated that I had to almost fail my exam and few years later I had to relearn C, get some experience in a real business project, and then I could start learning C++.

I find that understanding how memory is layed out in executable, how the C works in terms of stack, symbols etc is the introductory knowledge I had to obtain to even think about C++. Not sure what's there now, because I saw recently some great compiler warnings, but I'm pretty sure that I did convert a prvalue to a pointer reference (&) at least once in my life and later failed with memory problems, but no compiler errors

saghm•48m ago
Getting failures later after coercing something to a reference is even easier than that; just deference a null pointer when passing to an argument that takes a reference; no warnings or errors! https://godbolt.org/z/xf5d9jKeh
steveklabnik•53m ago
When people say "Rust is just as complex as C++," I think value categories are a great example of why it's actually simpler, even if it also seems complex. C++ has three primary categories: prvalue, xvalue, and lvalue. There's also glvalue and rvalue. Rust has two: a place (which is a glvalue) and a value (which is a prvalue).

C++ needs those extra categories, they exist for good reasons. But it is more complex.

Sharlin•42m ago
To be fair, though, Rust really needs something morally like prvalues, to solve the heap initialization problem aka `Box::new([42; 10_000_000])`
steveklabnik•22m ago
Yes, it is possible that Rust will add more complexity here specifically, but also just in general. Just how it goes :)
koito17•33m ago
Additionally, the "r" and "l" may lead one to incorrectly guess that rvalues and lvalues are related to their position in an expression. But alas, they aren't; there are lvalues that cannot appear in the left-hand side of an expression.
stonemetal12•45m ago
This is like saying 1 + 2 isn't addition because the compiler will optimize it away. It isn't an addition instruction in the emitted code but logically speaking it is addition.

Similarly just because a compiler may optimize a prvalue away doesn't change the fact that a prvalue by definition of the language is a temp.

Sesse__•24m ago
The article specifically points out that this isn't about optimization. A temporary will not be created even with -O0 (you can observe this by putting logging into the copy and move constructors).
quuxplusone•7m ago
Or even =delete'ing them or (carefully) putting static_asserts inside them. They're not called, not instantiated, not nothing.

Two billion email addresses were exposed

https://www.troyhunt.com/2-billion-email-addresses-were-exposed-and-we-indexed-them-all-in-have-i...
256•esnard•2h ago•176 comments

You Should Write An Agent

https://fly.io/blog/everyone-write-an-agent/
136•tabletcorry•2h ago•69 comments

Writing software is an act of learning. Don’t automate it.

https://martinfowler.com/articles/llm-learning-loop.html
38•johnwheeler•1h ago•7 comments

Kimi K2 Thinking, a SOTA open-source trillion-parameter reasoning model

https://moonshotai.github.io/Kimi-K2/thinking.html
512•nekofneko•8h ago•198 comments

Show HN: I scraped 3B Goodreads reviews to train a better recommendation model

https://book.sv
162•costco•1d ago•72 comments

Game Design Is Simple

https://www.raphkoster.com/2025/11/03/game-design-is-simple-actually/
23•vrnvu•51m ago•8 comments

Man who threw sandwich at US border agent not guilty of assault

https://www.bbc.com/news/articles/c5ypvv8n1jvo
40•onemoresoop•24m ago•9 comments

Swift on FreeBSD Preview

https://forums.swift.org/t/swift-on-freebsd-preview/83064
156•glhaynes•5h ago•89 comments

ICC ditches Microsoft 365 for openDesk

https://www.binnenlandsbestuur.nl/digitaal/internationaal-strafhof-neemt-afscheid-van-microsoft-365
481•vincvinc•6h ago•147 comments

Hightouch (YC S19) Is Hiring

https://job-boards.greenhouse.io/hightouch/jobs/5542602004
1•joshwget•1h ago

Open Source Implementation of Apple's Private Compute Cloud

https://github.com/openpcc/openpcc
337•adam_gyroscope•1d ago•64 comments

LLMs Encode How Difficult Problems Are

https://arxiv.org/abs/2510.18147
79•stansApprentice•4h ago•14 comments

The Parallel Search API

https://parallel.ai/blog/introducing-parallel-search
70•lukaslevert•6h ago•31 comments

FBI tries to unmask owner of archive.is

https://www.heise.de/en/news/Archive-today-FBI-Demands-Data-from-Provider-Tucows-11066346.html
615•Projectiboga•6h ago•324 comments

I analyzed the lineups at the most popular nightclubs

https://dev.karltryggvason.com/how-i-analyzed-the-lineups-at-the-worlds-most-popular-nightclubs/
135•kalli•9h ago•64 comments

C++: A prvalue is not a temporary

https://blog.knatten.org/2025/10/31/a-prvalue-is-not-a-temporary/
28•ingve•6d ago•17 comments

Eating stinging nettles

https://rachel.blog/2018/04/29/eating-stinging-nettles/
156•rzk•11h ago•155 comments

Writing Advice

https://chadnauseam.com/advice/writing-advice
34•jfantl•1w ago•4 comments

Please stop asking me to provide feedback #8036

https://github.com/anthropics/claude-code/issues/8036
68•jmward01•5h ago•43 comments

Universe's expansion 'is now slowing, not speeding up'

https://ras.ac.uk/news-and-press/research-highlights/universes-expansion-now-slowing-not-speeding
66•chrka•2h ago•60 comments

Springs and Bounces in Native CSS

https://www.joshwcomeau.com/animation/linear-timing-function/
59•Bogdanp•1w ago•5 comments

Mathematical exploration and discovery at scale

https://terrytao.wordpress.com/2025/11/05/mathematical-exploration-and-discovery-at-scale/
212•nabla9•13h ago•102 comments

Show HN: TabPFN-2.5 – SOTA foundation model for tabular data

https://priorlabs.ai/technical-reports/tabpfn-2-5-model-report
51•onasta•4h ago•11 comments

Blame Wi-Fi drivers for printer (mDNS) discovery issues

https://printserver.ink/blog/blame-wifi-drivers-for-printer-discovery-issues/
6•ValdikSS•1w ago•2 comments

Auraphone: A simple app to collect people's info at events

https://andrewarrow.dev/2025/11/simple-app-collect-peoples-info-at-events/
21•fcpguru•8h ago•13 comments

Show HN: See chords as flags – Visual harmony of top composers on musescore

https://rawl.rocks/
103•vitaly-pavlenko•1d ago•27 comments

Show HN: Dynamic code and feedback walkthroughs with your coding Agent in VSCode

https://www.intraview.ai/hn-demo
12•cyrusradfar•6h ago•0 comments

I may have found a way to spot U.S. at-sea strikes before they're announced

https://old.reddit.com/r/OSINT/comments/1opjjyv/i_may_have_found_a_way_to_spot_us_atsea_strikes/
265•hentrep•18h ago•381 comments

Supply chain attacks are exploiting our assumptions

https://blog.trailofbits.com/2025/09/24/supply-chain-attacks-are-exploiting-our-assumptions/
44•crescit_eundo•7h ago•33 comments

How often does Python allocate?

https://zackoverflow.dev/writing/how-often-does-python-allocate/
76•ingve•5d ago•49 comments