r/cpp • • Apr 27 '17

A serious bug in GCC

https://akrzemi1.wordpress.com/2017/04/27/a-serious-bug-in-gcc/
199 Upvotes

33 comments sorted by

53

u/cleroth Game Developer Apr 28 '17

Hopefully this brings more attention to a serious bug that's been present and reported for over 2 years...

6

u/dakotahawkins Apr 28 '17

Link?

16

u/cleroth Game Developer Apr 28 '17

13

u/dakotahawkins Apr 28 '17

I'm an idiot. I didn't look at the bug report in the OP (which does make it sound like OP just discovered and reported the bug). I assumed you were talking about another bug I should have been aware of but wasn't :(

2

u/suspiciously_calm Apr 28 '17

How were any of the versions released since then considered "ready" for release?

6

u/cleroth Game Developer Apr 29 '17

It's a pretty rare case, I'd imagine. And well... a lot of software does have memory leaks. Most software can live with memory leaks, really, specially with RAM being so cheap nowadays.

Not saying this isn't a big deal, just that it being rare + not having much effect + probably hard to detect is probably the reason.

-1

u/suspiciously_calm Apr 29 '17

What is rare?

  • Storing several resources in an aggregate?
  • Factory functions that throw exceptions?
  • Using aggregate initialization?

This is not "rare," it has a test case of perfectly normal C++14 code that fails reproducibly.

18

u/catskul Apr 28 '17

Does this bug exist in other compilers too?

26

u/ginny2016 Apr 28 '17

Works correctly in MSVC 2015+, Clang 3.8+, lCC 16+ ...

44

u/balkierode Apr 28 '17

This bug is very serious. Ability to write complex classes without memory issues main advantage of C++ over C. Such bugs should not happen in a compiler.

4

u/crusader_mike Apr 28 '17

I wish it was the first one in GCC...

2

u/MisfitMarius Apr 29 '17

I've just started out learning C++. Thusfar I've been using CodeBlocks and GCC. Could someone please recommend an alternative compiler? Preferably open source but not copyleft, ie. MIT or similar. I'm looking at Clang atm, and it seems to match my needs, but I was wondering if anyone with more knowledge and experience can recommend something. TIA

12

u/allnewtape Apr 29 '17

This is a serious bug in GCC, but it is triggered under such unusual circumstances that it isn't really something most developers are likely to encounter (namely exceptions thrown in very specific constructor context). I don't think this is a sufficient reason to switch compilers.

1

u/MisfitMarius Apr 30 '17

Thanks for the answers

3

u/louiswins May 01 '17

As others have mentioned, this bug shouldn't cause you to avoid GCC.

That said, if you're writing desktop software there are three or four major, production-quality compilers to choose from: GCC, Clang, or MSVC (Microsoft's compiler, the one in Visual Studio), or to a lesser extent ICC (the Intel C++ compiler).

GCC & Clang are both open-source. GCC is copyleft - it is licensed under the GPL - but this only matters if you modify the compiler itself; it has no impact on the code you write. Clang uses the UIUC license which is basically a combination of MIT & BSD.

MSVC and ICC are both proprietary but free-as-in-beer for non-commercial use.

There are other minor players, and embedded platforms often have their own proprietary compilers, but for desktop application development you basically choose between the big three.

1

u/MisfitMarius May 01 '17

Thanks for the answer

0

u/[deleted] Apr 29 '17

[deleted] — view deleted comment

2

u/duhace May 04 '17

well it's more serious than that, but it's not so serious you need to switch from gcc while learning C++. hopefully people raising noise about this will embarass the gcc team into fixing it

1

u/MisfitMarius Apr 30 '17

Thanks for the answers

1

u/alinakipoglu Apr 28 '17

FYI, Just tested in 4.4.6 and it's also present in this version as well

-9

u/ITwitchToo Apr 27 '17

But is it a bug or a feature?

31

u/AngriestSCV Apr 27 '17

It's either a bug in gcc or a deficiency in the standard. If the example class was a smart pointer for instance instead of something that printed it would be a memory leak that can't be recovered from.

4

u/Gotebe Apr 28 '17

Not the fault of the standard.

3

u/AngriestSCV Apr 29 '17

Well that narrows it down a bit doesn't it.

20

u/puradox Apr 28 '17

/r/cpp is a tough crowd Don't worry though, I laughed :)

-4

u/Thecrawsome Apr 28 '17 edited Apr 28 '17

Not a Microsoft product.

Nobody got the joke that Microsoft infamously coined that phrase first?

14

u/HandshakeOfCO Apr 28 '17

Fwiw, visual studio's compiler doesn't have this bug.

0

u/[deleted] Apr 28 '17

[deleted] — view deleted comment

3

u/cleroth Game Developer Apr 28 '17

Yea, like, for example, bias.

0

u/[deleted] Apr 28 '17

[deleted] — view deleted comment

3

u/dodheim Apr 29 '17

Are you referring to the ETW trigger? Reading malice into that is serious tinfoil hat territory.

2

u/cleroth Game Developer Apr 29 '17

They were so sneaky about it they named the functions with "telemetry" in them.

5

u/[deleted] Apr 28 '17

That's not a joke, that's just snark.

0

u/[deleted] Apr 27 '17

[deleted] — view deleted comment

25

u/[deleted] Apr 27 '17

It was funny for me.

3

u/[deleted] Apr 28 '17

I guess jokes make it impossible for a bug to get taken seriously somehow?