mcc,
@mcc@mastodon.social avatar

I am in a terrible mood and I will tell you why: C++

mcc,
@mcc@mastodon.social avatar

I Never Thought It Would Happen To Me: I Forgot To Put "return true;" At The End Of A Function Returning Bool And Clang Just Kept Going Off The End Of The Function Into The Infinite Abyss

currentbias,
@currentbias@open-source-eschaton.net avatar

@mcc Bool and Clang sounds like it should be an adventure duo in the spirit of Ratchet and Clank

juliancday,
@juliancday@writing.exchange avatar

@currentbias @mcc Claiming my code as part of the bool und clang artistic movement.

gsuberland,
@gsuberland@chaos.social avatar

@mcc I have no idea why "you said this function returns a thing and you did not return the thing" was ever considered anything but a compilation error.

gsuberland,
@gsuberland@chaos.social avatar

@mcc and I'm betting the answer is something like "it was a slight convenience for systems programmers on a computing platform that went out of production in 1982 but by the time someone pointed out that it was problematic it was already part of the language standard and we didn't want to break existing code".

whitequark,
@whitequark@mastodon.social avatar

@gsuberland @mcc but they did break things like "infinite loops" so what gives

whitequark,
@whitequark@mastodon.social avatar

@gsuberland @mcc > The rationale includes that checking if every real code path returns a value is quite difficult (without knowing which functions never return), so it's not illegal to compile a function like your example, only to actually call it like your main does.

whitequark, (edited )
@whitequark@mastodon.social avatar
gsuberland,
@gsuberland@chaos.social avatar

@whitequark @mcc lol "cos it'd be work" there we go

whitequark,
@whitequark@mastodon.social avatar

@gsuberland @mcc "Falling off the end of a non-void function is only undefined behavior in C++, not in C. It is fairly common practice to compile C code as C++, " oh my fucking gods

swetland,
@swetland@chaos.social avatar

@whitequark @gsuberland @mcc I remain baffled that modern compilers will happily emit a trap for UB but not provide an option to flag it as a compile-time error.

Especially since they seem to be constantly introducing exciting new UB with every compiler and/or language revision, it feels like it'd be awfully handy to learn about it at compile time rather than at runtime.

whitequark,
@whitequark@mastodon.social avatar

@swetland @gsuberland @mcc there's a -Werror for that I think

swetland,
@swetland@chaos.social avatar

@whitequark @gsuberland @mcc On further reflection, I find this even more baffling given clang's early claim-to-fame (and big influence on gcc) of much more expressive, informative, and comprehensible errors and warnings.

whitequark,
@whitequark@mastodon.social avatar

@swetland @gsuberland @mcc -Werror=return-type does not do it?

swetland,
@swetland@chaos.social avatar

@whitequark @gsuberland @mcc I was looking for a general "flag any UB as an error" flag, but I suppose assorted flags for specific situations are better than nothing.

whitequark,
@whitequark@mastodon.social avatar

@swetland @gsuberland @mcc there's clang-analyzer that does do that, but the false positive rate is generally too high unless you're really willing to commit to it

mcc,
@mcc@mastodon.social avatar

@swetland @whitequark @gsuberland infinite loops are UB in C++ which means that providing an error on UB in C++ would literally require solving the halting problem.

In C, maybe.

whitequark,
@whitequark@mastodon.social avatar

@mcc @swetland @gsuberland (infinite loops without I/O or synchronization, which is ... well, still the halting problem but easier)

raggi,
@raggi@rag.pub avatar

@whitequark @mcc @swetland @gsuberland the whole policy of “perfection is hard so fuck the obviously helpful” is such warm and very fuzzy

by which I mean enraging and poorly defined

swetland,
@swetland@chaos.social avatar

@mcc @whitequark @gsuberland I forgot about that one. Will have to update my list of "things about C++ that negatively impact my sanity."

I feel like at some point C and C++ compilers crossed over from "impressive optimization" to "so aggressive that I can't rely on my code to actually do what a straightforward read of the source says it does."

I'm probably tainted by growing up with old, dumb compilers, but I miss being able to trust the compiler to actually do what I ask it to.

gsuberland,
@gsuberland@chaos.social avatar

@whitequark @mcc in my (admittedly limited) experience every single justification for (not) doing a thing with the c++ language standard has a counter example where they made a decision that violated that justification at some point.

more honest justifications would be "I've dug myself into a happy little rut here and now I'm personally invested in doing it this way" or "we want to fix that but it'd make extra work for the compiler devs and we'd have to put up with them complaining about it".

immibis,

@gsuberland @mcc because C is the language that makes no attempt to stop you shooting your foot off. But it should at least be a warning. I don't think I've ever not gotten a warning for this... Nor had the compiler not insert a return instruction with a garbage return value. Perhaps the optimiser thinks the end is unreachable due to earlier undefined behaviour?

mcc,
@mcc@mastodon.social avatar

@immibis @gsuberland I didn't say C. I said C++ :(

mcc,
@mcc@mastodon.social avatar

@immibis @gsuberland In this case there's a difference :(I

SpikyCaterpillar,
@SpikyCaterpillar@mastodon.social avatar

@mcc HOW is that not a syntax error (and if the answer is "the c++ spec", i will repeat the question)

mcc,
@mcc@mastodon.social avatar

[[Clang, lounging on a velvet couch, its top two shirt buttons unbuttoned, smoking a cigar]] "When I see a program counter, I increment it. There's literally never a situation where that would be the wrong thing to do."

porglezomp,
@porglezomp@mastodon.social avatar

@mcc (reading your double square bracket parenthetical as attribute syntax)

nabijaczleweli,
@nabijaczleweli@101010.pl avatar

@mcc if you didn't get -Wreturn-type for this then you should probably report this

mcc,
@mcc@mastodon.social avatar

@nabijaczleweli We got it, but due to a wonky multi-step build process we didn't notice the warning until we'd noticed the problem by reading the code. The project now has a -Werror=return-type

oblomov,
@oblomov@sociale.network avatar

@mcc did it start playing some 90s eurodance
https://m.youtube.com/watch?v=Rvig7-sxvvM

swetland,
@swetland@chaos.social avatar

@mcc I'm not 100% sure this is a case of "smells like undefined behaviour so the compiler just shrugs", but I am increasingly of the opinion that modern compilers that treat UB as a license to just make code just straight up fault or do absolutely random shit should provide a -werror-on-undefined-behaviour option to fail at compile time rather than runtime.

shafik,
@shafik@hachyderm.io avatar

@mcc In older versions of clang you can find some fun cases around this UB: https://gcc.godbolt.org/z/KGhKjvdY5

but now clang usually turns them into unreachable and often just optimizes away the bodies which is awful: https://gcc.godbolt.org/z/sjfo9K1xv

We have a bunch of bug reports on this and various undefined behavior that get treated like this: https://github.com/llvm/llvm-project/issues/48943

The fix ostensibly simple but tricky b/c it could break a lot so it would require some effort to verify before rolling out.

mcc,
@mcc@mastodon.social avatar

@shafik "tricky" looks to me like if you simply compile it in C it does something much more reasonable, so it couldn't be that tricky.

inthehands,
@inthehands@hachyderm.io avatar

@mcc
Dear Penthouse: Long time reader, first time writer. I’d heard about undefined behavior, but never thought it could happen to me. Then one night, I met a function at a bar who whispered in my ear, “I’m not wearing a return statement,” and

lispi314,
@lispi314@udongein.xyz avatar

@mcc lmao holy shit who came up with that design?

mcc,
@mcc@mastodon.social avatar

@lispi314 it seems very possible this behavior was not designed at all

oblomov,
@oblomov@sociale.network avatar

@mcc @lispi314 I think it came out organically from K&R not requiring a return type, then implicating to int rather than void, but since it could be either let's not care about an existing return, etc.

mcc,
@mcc@mastodon.social avatar

@oblomov @lispi314 I think the behavior might be C++ specific actually

18+ Creyvin_Morehead,
@Creyvin_Morehead@mastodon.social avatar
codemonkey85,
@codemonkey85@mastodon.social avatar

@mcc there’s stuff I like about C++, namely, some stuff it makes easier than other languages I’ve used, but I would not go back if I didn’t have to!

tsrono,
@tsrono@mastodon.social avatar

@mcc pinned-post-worthy

prehnra,
@prehnra@mastodon.social avatar

@mcc I was going to make a joke about "more like C--", but then I googled and realized that's already a thing.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • DreamBathrooms
  • thenastyranch
  • ngwrru68w68
  • magazineikmin
  • khanakhh
  • rosin
  • mdbf
  • Youngstown
  • slotface
  • everett
  • cisconetworking
  • kavyap
  • tacticalgear
  • InstantRegret
  • JUstTest
  • Durango
  • osvaldo12
  • ethstaker
  • modclub
  • GTA5RPClips
  • Leos
  • cubers
  • tester
  • normalnudes
  • megavids
  • provamag3
  • anitta
  • lostlight
  • All magazines