Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Jonathan Lamothe Newsgroups: comp.lang.c++ Subject: Re: Move semantics with literals Date: Tue, 14 Apr 2026 11:10:31 -0400 Organization: A noiseless patient Spider Lines: 34 Message-ID: <87fr4x60ig.fsf@posteo.de> References: <10rlkk9$6hau$1@dont-email.me> <87jyu960xp.fsf@posteo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Injection-Date: Tue, 14 Apr 2026 15:10:32 +0000 (UTC) Injection-Info: dont-email.me; posting-host="802fe6a8d5b97504ac6764022e672b27"; logging-data="163865"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7ZRDVQ0MbWO29nla6Q8q1l8rD3VKFoOE=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Cancel-Lock: sha1:LvHkDTwmk82fEhjHQZHccwhCqfw= sha1:ujM5+jTu99SqFreaw9ZzEJVFTsQ= Xref: csiph.com comp.lang.c++:123720 Jonathan Lamothe writes: > boltar@caprica.universe writes: > >> To my chagrin I got caught out by this trick question in an interview: >> >> int func(int &&a) >> { >> return a * 2; >> } >> >> >> : >> int b = func(123); >> : >> >> Where the question was "what would happen". I assumed it wouldn't compile >> being a reference to a literal but it does. So I'm just wondering why on >> earth and when would you ever do the above? Is there some wierd use case? > > The only use case I can see is tricky interview questions. ;) More seriously though, I'm not sure off-hand, but this feels like a case of undefined behaviour. At any rate, it's terrible for the clarity of the code, which I try to prioritize. I hate it when job interview questions don't actually reflect the kind of work you'll be expected to do. Though, if this *is* the expectation... bullet dodged, I guess? -- Regards, Jonathan Lamothe https://jlamothe.net