WTF Bites
-
, etc.
-
The following C++ code (defining a lambda expression and capturing two local variables) works.
int w = size.first; int h = size.second; auto action = [=] { setSize(w, h); };
Trying to use structured bindings to reduce verbosity
auto [w, h] = size; auto action = [=] { setSize(w, h); };
should be semantically equivalent. But it gives an error message (clang only, not in gcc):
error: reference to local binding 'w' declared in enclosing function 'foo'
.
Yes, so what? Why's that an error?I suppose it's because the first makes copies of the members of
size
and captures these in the lambda, while the seconds only creates aliases to them at a point where the compiler can't guarantee the lifetime ofsize
?
-
@LaoC nope. It's because destructured bindings aren't really variables therefore you cannot capture them. It has nothing to do with storage, lvalues, or anything like that.
-
@LaoC nope. It's because destructured bindings aren't really variables therefore you cannot capture them. It has nothing to do with storage, lvalues, or anything like that.
I was getting at why you can't capture them. "Aliases" is just another word for "not really variables". If you capture variables and then let them go out of scope while keeping the lambda, the compiler has to make sure the captured variables aren't simply disposed of as they normally would, right? That's where storage comes in. It can only do that if it controls how those variables are created.
-
@LaoC
[=]
is supposed to mean "capture everything by copy so that things going out of scope isn't a problem", as opposed to[&]
which means "make everything a reference". You can capture references by copy just fine - it then copies the referenced variable into the lambda object. Not to mention that having invalid references is not a compile-time error in C++.It's not that the captures cannot be aliases. It's that the captures cannot be created from aliases. Because fuck you that's why.
-
@LaoC
[=]
is supposed to mean "capture everything by copy so that things going out of scope isn't a problem", as opposed to[&]
which means "make everything a reference". You can capture references by copy just fine - it then copies the referenced variable into the lambda object. Not to mention that having invalid references is not a compile-time error in C++.It's not that the captures cannot be aliases. It's that the captures cannot be created from aliases. Because fuck you that's why.
So you're not capturing the variables anyway but only their copies? TIL. But then it works if you make the copy explicit … that's stupid for sure.
-
I think C++20 does allow that if you have it.
-
@Benjamin-Hall they’ll discover this around mid April when people start complaining about the bills they’re being told they haven’t paid and it gets shouty.
-
@Watson (CC @topspin @LaoC) you know what? This seems to be Clang-specific. GCC has no problems, even in C++17 mode.
Clang: https://rextester.com/MLM53347
GCC: https://rextester.com/MPEM70161The question is - is it GCC extension or is Clang non-compliant? Both are equally likely.
-
@Watson (CC @topspin @LaoC) you know what? This seems to be Clang-specific. GCC has no problems, even in C++17 mode.
Clang: https://rextester.com/MLM53347
GCC: https://rextester.com/MPEM70161The question is - is it GCC extension or is Clang non-compliant? Both are equally likely.
From what I read (which is not the standard in this case but just discussions about it), clang was correct in rejecting it. gcc probably either didn't reject it out of oversight or because it makes no fucking sense.
It's not that the captures cannot be aliases. It's that the captures cannot be created from aliases. Because fuck you that's why.
Correct, afaict. The problem does seem to be that structured bindings are "not really variables but aliases, herp derp", but why the fuck would that matter? In the original snippet with
int
variables, the local variables create a by value copy, and then the lambda captures create a second copy in the lambda's closure. It would work the same way if the local variables wereint&
, the lambda is explicitly told to capture by value and would createint
members in its frame. So I don't really care if the binding is secretly anint&
, "just an alias", or whatever else.
The redundant capure initializerw=w
makes it obvious that this not working makes no sense.E: I see you basically mentioned that above already. Sorry for reading stuff out of order.
-
@Gąska The only thing that I can find is mention that this changed for C++20.
If a capture list has a capture-default and does not explicitly capture the enclosing object (as this or *this), or an automatic variable that is odr-usable in the lambda body, or a structured binding whose corresponding variable has atomic storage duration (since C++20), it captures it implicitly if [...]
FWIW- MSVC also accepts code https://godbolt.org/z/K5Kj7GEzj
-
@Benjamin-Hall they’ll discover this around mid April when people start complaining about the bills they’re being told they haven’t paid and it gets shouty.
Yeah, I'm pretty sure most people will consider that a "I told you to make the payment automatic, this is not my fucking problem you didn't" situation.
-
@topspin Closest thing for reasons I could find here
Still mostly agree with what you say. (Clearly, so did other people if it's fixed in C++20.)
-
variable has atomic storage duration
What the heck is that?
Filed under: things I probably don't want to know
-
@topspin considering this is the only time this phrase is ever used in all internet, my bet is that's a typo and they meant automatic.
Edit: for future readers - yes, I realize there are two results now. There weren't before and anyway it doesn't count.
-
@Gąska New shortcut to the lambda expression page on cppreference. Yay. :-)
-
variable has atomic storage duration
What the heck is that?
It means that the variable's value is subject to exponential decay, obviously.
Filed under: λ
-
@Zerosquare said in WTF Bites:
It means that the variable's value is subject to exponential decay, obviously.
So, basically, a uint64_t occasionally falls apart into something like a uint32_t + 3 uint8_ts and a few random bits? Makes arrays of uint64_t a bit dangerous -- having that many uint64_ts in one place gives those random bits a high probability of hitting another uint64_t and triggering a chain reaction.
-
@cvi Sounds like something caused by non-ECC RAM to me.
-
@Zerosquare said in WTF Bites:
It means that the variable's value is subject to exponential decay, obviously.
So, basically, a uint64_t occasionally falls apart into something like a uint32_t + 3 uint8_ts and a few random bits? Makes arrays of uint64_t a bit dangerous -- having that main uint64_ts in one place gives those random bits a high probability of hitting another uint64_t and triggering a chain reaction.
uint64_t
is fairly stable except for its PDP-11 isotope, but make sure you have a lead heatsink if you want to use fused-multiply-add AVX instructions on 256-bit operands. Intel's Hanford Lake CPUs come with one.
-
All this talk just tells me how little I understand about quantum computing.
-
All this talk just tells me how little I understand about anything.
-
@Applied-Mediocrity said in WTF Bites:
All this talk just tells me how little I understand about anything.
Welcome to WTDWTF!
-
Status: Apparently one is completely unable to manage Google DNS nameserver entries programmatically. The literal only method to add records, delete records, etc, is through the web UI.
Looks like I'm going to be using a free alternative...
-
@Tsaukpaetra said in WTF Bites:
Status: Apparently one is completely unable to manage Google DNS nameserver entries programmatically. The literal only method to add records, delete records, etc, is through the web UI.
Looks like I'm going to be using a free alternative...
Just script up like what the UI is doing, meh.
-
-
@Tsaukpaetra said in WTF Bites:
meh.
I have to fuck with PHP, no time for that!
Okay do it in PHP then.
-
It's not that the captures cannot be aliases. It's that the captures cannot be created from aliases. Because fuck you that's why.
The C++ committee has representatives of the three main compilers (MSC++, GCC and Clang) and does not include features unless they also say they can implement them. But Clang being the one where it does not work is weird, because they are the most modern one, so I would not expect them to say “sorry, we have done this ugly hack to get X working that makes it hard for us to add Y now”. Usually it's the MSC++ compiler with that problem. That is the one said to be unholy mess, holding together with wishful thinking only.
-
they are the most modern one, so I would not expect them to say “sorry, we have done this ugly hack to get X working that makes it hard for us to add Y now”.
More likely is "sorry, we made it so that the very definition of X precludes Y and the ripples permeate the type system".
-
Usually it's the MSC++ compiler with that problem. That is the one said to be unholy mess, holding together with wishful thinking only.
It only took them 2 decades or so to implement two-phase lookup.
-
-
@Zerosquare Funny stuff is
-
What do you mean? It's a real product. The API even works.
-
@Zerosquare said in WTF Bites:
I wish the sign up links were real. I would have tried to expense it.
-
@Zerosquare how does one indicate their pricing tier to it (I.e. if I had a subscription, how would I get the result without ads or adhering correctly to numeric limits)?
Rookie mistake there, even the free tier should have API key requirements.
-
@Zerosquare said in WTF Bites:
It's a real product
About the same way Jude Thorn the Python Developer is real
-
@Arantor Access token in the HTTP header?
-
@Zerosquare said in WTF Bites:
What do you mean? It's a real product. The API even works.
I would have uppercased the E in iseven. I keep seeing “i seven” and get confused.
{"ad":"HELP WANTED: Child Care provider. Apply in person, Jack & Kill Childcare, 1905 NW Smith. NO PHONE CALLS","iseven":true}
Some of the ads are gold.
*edit another one.
{"ad":"Scarecrow wanted for field in Saskatchewan. Must not be afraid of birds. Email buddybilly@qotmail.com","iseven":true}}
-
@Zerosquare said in WTF Bites:
Amazing. The shiny, modern SPA website. The developer praise. Three pricing tiers.
I’m not convinced this isn’t real.
-
@cvi You'd think but the docs do not indicate this. I'd honestly expect this to be indicated even for a free tier.
-
I’m not convinced this isn’t real.
The only way you can actually tell is the sign-up buttons. Even my observation about authentication isn't clear cut (since while even free-tier should have authentication, I've seen enough crap APIs over the years)
Even the ads are not on their own enough to indicate it's not an example of satire because I could genuinely believe something like that.
-
Some of the ads are gold.
*edit another one.
{"ad":"Scarecrow wanted for field in Saskatchewan. Must not be afraid of birds. Email buddybilly@qotmail.com","iseven":true}}
{"ad":"For sale: human skull. Used once only. $200 OBO Dr. Scott Tyler, 454-555-6533","iseven":true}
Even the ads are not on their own enough to indicate it's not an example of satire because I could genuinely believe something like that.
The phone numbers are.
-
https://api.isevenapi.xyz/api/iseven/ⅶ/
I expected an upsell to a higher pricing tier. These guys are losing money and they don't even know it.
-
The phone numbers are.
The first 2 or 3 ads I had didn't have phone numbers and the other things (e.g. the Jack & Kill Childcare) could have been an unspotted off-by-one.
I've long given up trying to guess Poe-or-no
-
My favorite part is the $99.99/month "enterprise" plan that enables support for negative numbers.
-
@Zerosquare said in WTF Bites:
Amazing. The shiny, modern SPA website. The developer praise. Three pricing tiers.
I’m not convinced this isn’t real.Oh, oh, oh… I completely forgot to mention the “WHERE’S YOUR GOD NOW, @KAZITOR” color scheme.
-
(e.g. the Jack & Kill Childcare) could have been an unspotted off-by-one.
1905 NW Smith Ave. Lawton, OK 73507
-
@Watson on the ? side, they're not troubled by infants masturbating. Although, the wording is a bit crass.
-
Somehow, the Ukraine ended up with kill-switches shot all through their computer systems, somehow. And then somehow apparently Microsoft found the problem. I am having a lot of trouble reconciling that second bit.
Lacking the detail for a news item, this is a WTF - when did MS get ept?
-
@Zerosquare said in WTF Bites:
Amazing. The shiny, modern SPA website. The developer praise. Three pricing tiers.
I’m not convinced this isn’t real.Oh, oh, oh… I completely forgot to mention the “WHERE’S YOUR GOD NOW, @KAZITOR” color scheme.
Several identical colors that somehow have different RGB values? How did you even notice?