Why do compilers not warn about this?

Compile with

struct Object { Object() : member{4} {} void mutate() { ++member; } int member;};struct Foo { Foo(Object& obj) : obj{obj} { use_object(); } void use_object() { obj.mutate(); } Object& obj;};struct Bar { Bar() : f{obj} , obj{} {} Foo f; Object obj;};int main() { Bar b{};}

Attached: 51fYzbYoXFL._UX250_.jpg (250x241, 9.03K)

Other urls found in this thread:

fonts.google.com/specimen/Ubuntu Mono
play.rust-lang.org/?gist=17f8c11e7e05b6b5f069eb23447387ff&version=stable&mode=release
twitter.com/NSFWRedditVideo

This can't happen in rust

Use Rust next time

Honest question as my C++20782381238 is rusty: what exactly is the problem here and what should the compiler warning be?

Is it the order of initialization that bugs you, or what?

General C++ rant:
I'm frustrated with the tons of new features constantly pouring in since C++11. [s]Wow, we have std::filesystem stuff now! Cool, 20 fucking years too late but still. But if they focused on the practical stuff like this first and foremost, we wouldn't have kick-ass stuff like std::string_view and folding expressions, which we totally needed. How's the concepts coming up?[/s]

Want something else that compilers don't warn about? Casting a const char* to a char*.

Attached: Screenshot at 2018-04-12 21-55-51.png (661x421 26.99 KB, 30.71K)

fucking KEK

...

...

the point here is not doing this shit on purpose but the fact that if you have a large projectr the problem in the OP can easily happen
a compiler warning at this point would be nice to reduce years of looking through code to find the problem

wow so hard. go suck some bbc you faggot

which tool warns about the issue at hand?
feel free to back up your claims anytime

Rust XDDDD

What is it about cocks that entices you so much, OP?

wait, do you even know what the problem is or are you just larping?

The problem is that you wrote incorrect code and then whine that your shit is fucked.
Write correct code next time.

so you don't know the problem...

The problem is that you are basically retarded and expect the compiler to do the work for you.
Write correct code next time or use Javascript

...

I'm actually just pretending to be retarded.
I mean what do you expect trying to tell Zig Forums that C/C++ isn't perfect?

Come on now, the OP is clearly a faggot that writes bad code because he can't see the computer screen with all that /cuteboy/ cum in his eyes, but you're being evasive.

C is perfect, C++ is an abomination.

Found the LARPer

I'm on my phone so I can't compile, but I see the issue, it's that you're using the obj before it is created. Well, that will crash, you look into the debugger and discover that the argument passed is 0. Not hard to figure out at all. Shit like this would be caught by clang format probably anyway. OPdoesn't have any arguments. If it's just you and fairly small program, this is unrxcusable, if it's big corpo project, there's constant code reviews, unit tests, starical analysis, people are all about "clean code" by that faggot uncle bob. This would never pass unless the code is outsourced to pajeets or something.

btw OP, did you report it to the gcc team or to some other compiler people ? I doubt it.

kek

It's because you passed -pedantic when you clearly meant -autistic.

This tip saved me HOURS of debugging!
Thanks!

absolutely harmful

?

>>>/soyboys/

Attached: rust shill hd.png (2955x2785, 785.06K)

get fucked, cuck.

what font is that? looks neat

Looks like Ubuntu Mono.
fonts.google.com/specimen/Ubuntu Mono

Attached: 70e88dfe-f680-430b-b077-fce20dca51cf.png (1185x736, 64.7K)

No, the punctuation in that image uses rectangular shapes. Ubuntu Mono uses round shapes.

get cucked, fuck.

It's not Ubuntu Mono. Fontsquirrel doesn't seem to recognize it either.

what shit compiler do you use that doesn't give a warning for this?

What's the problem with C?

Did he step off the Mayflower yesterday?

Trying to learn C++ here, is the problem that in struct Foo obj is called with obj{obj} but inside struct Object there is no correlating match? What's the problem here?

No Rust? Into the trash.

Thread is shit if OP doesn't explain why a compiler should generate a warning for this code.

t. brainlet

Attached: 1481714994279.png (540x720, 437.94K)

obj is passed into f before obj is initialized. f uses obj in its ctor which results in UB
to fix it you swap the order of initialization in bar

Nice of you to let us know.

Kindly explain how exactly pic related werks as well as all of its quirks and oddities.

Attached: hurr_fizzbuzz.png (621x942, 34.22K)

Because the compiler can't make sense of C++ either.

As DLW says, "C++ is the C of object oriented programming languages."

Subject: C++ Is Good For FertilizerThis message is in reply to a "discussion" spurred by the"observation" that (I quote roughly and from memory)"Computers are used by 50% of the people in the world, and Cis used by 50% of all programs, therefore improving C [ieincrementing it and discarding the result] will potentiallymake the world a 25% better place to live." I am not makingthis up.The original subject line for the discussion was "C++ isgood for the world."

Thanks user.

Oops, forgot trip.

God DAMN

Attached: iceburn.gif (500x129, 48.81K)

It doesn't warn you, because it assumes you're smart enough to know that modifying data before it's even initialized is fucking retarded. int main(){ int x; ++x; x = 4; return x; //hurr why isn't it returning 5??? muh safety}

languages that force variables to be initialized before they're used won't let this happen
does rust enforce this?

if anyone else cares, it's mononoki

...

yes???????????????????? even pajeet languages enforce this.

like javascript? :^)

use haskell, oop is trash

Attached: 15137924563180.png (423x578, 106.39K)

his examples hardly use any OOP
or did you really mean functional/imperative programming?

Attached: 50a42f7f45169132f51ba8ea56c0ddc3fb52f1650a017966f2833d18f0279579.jpg.png (255x255, 89.3K)

use of methods and shit

No. Like Java, C#, Dart, Swift, Objective-C. I wouldn't classify JavaScript as a pajeet language. JS is just shit.

...

Compile with rustc. Safe code can't access freed memory. fn main() { let v = vec!(0, 1, 2, 3); match () { () if free(v) => { unreachable!(); } _ => { println!("{:?}", v); } }}fn free(_: T) -> bool { false} This outputs [0, 0, 0, 0] Ooooooopsie

Forgot playground link: play.rust-lang.org/?gist=17f8c11e7e05b6b5f069eb23447387ff&version=stable&mode=release

Attached: 13784358234.jpg (260x222, 12.73K)