November 30th, 2024

C++, Complexity, and Compiler Bugs

Azeem Bande-Ali discusses C++ complexities, highlighting issues like temporary lifetime extension, C and C++ incompatibilities, and template disambiguation, while advocating for a simpler successor language to enhance development.

Read original articleLink Icon
C++, Complexity, and Compiler Bugs

Azeem Bande-Ali discusses the complexities of C++ and the challenges posed by compiler bugs based on his professional experiences. He highlights how the language's power comes with significant emergent complexity, making it difficult for developers to fully grasp. One key issue he encountered was related to temporary lifetime extension, where a const reference could extend the lifetime of a temporary variable, leading to unexpected behavior when upgrading compilers. This feature, established in 1993, was not widely known among developers, which resulted in production crashes. Bande-Ali also addresses the incompatibility between C and C++ regarding designated initializers, where GCC7 would silently ignore invalid syntax, causing years of unnoticed errors until GCC9 flagged them. Additionally, he points out the confusion surrounding template disambiguation, where different compilers (GCC and Clang) handle unnecessary disambiguation differently, complicating the development process. He concludes by expressing a desire for a successor language that could simplify C++'s complexities while still allowing for its powerful features.

- C++'s complexity can lead to significant challenges for developers, especially with compiler bugs.

- Temporary lifetime extension can cause unexpected behavior when upgrading compilers.

- Incompatibilities between C and C++ can lead to unnoticed errors in code.

- Template disambiguation issues arise from differing compiler interpretations.

- There is a call for a simpler successor language to address C++'s complexities.

Link Icon 5 comments
By @muststopmyths - 5 months
Of all the anti-C++ rants that regularly get posted here, I felt this one the most as a career C++ developer.

Specifically,

- incompatibility with C is just stupid

- agreeing with sibling comment, references were a mistake

- the complexity has really gotten out of hand.

By @foooorsyth - 5 months
Pass by reference was a mistake. Doesn’t need to exist. Obscures what’s actually happening at the call site. Overloads the minds of programmers with an unnecessary third option, which causes bugs like this. Some other non-null indicating syntax for pass by pointer (visible at call site) would’ve made more sense.

I feel exactly like the author. I get less comfortable with C++ year after year, despite writing it all day. I feel like a race car driver who was once confident but has now gotten into too many big crashes.

By @plorkyeran - 5 months
The first two of these are weird cases for reading the standard and arguing with your compiler vendor because regardless of the legality they’re stupid code. Reference lifetime extension is useful for generic code where the function may return either a reference or a value, and is just bad code in nearly any other circumstance. The array initialization example is something that never actually worked, and a newer compiler version exposing some code that appeared to work but didn’t is sort of routine?
By @SleepyMyroslav - 5 months
>I don’t know man, why are we writing C++?

2 cents from gamedev:

1. Vendor lock in on platforms is still there and is not going anywhere.

2. Existing code. Every successful AAA project / game engine has a mountain of code that is already there. Often with even bigger mountain of data that no one really wants to redo. It also often depends on multiple middleware or open source packages that already work and are hard to replace.

There is no rational reason to keep learning historical accidents why things are like they are in C++ but see points 1 and 2 above.

> I am hoping there can be a cleaner successor language that lets you easily use C++ code when you need to but also allows you to ignore the C++ complexity when you aren’t touching the C++ code directly.

I do not understand how left hand of author wants to run C++ code with all of the data going in and right hand does not want to touch it. It does not work like this. At least in gamedev. End of rant.