Avoiding Implicit Bugs in C++

Avoiding Implicit Bugs in C++

1h 53mAdvanced2023-07-28

Authors

Shachar Shemesh

Shachar Shemesh

Course details

C++ is an extremely powerful, portable, and cost-effective programming language. But it's also rife with implicit and counter-intuitive semantics, which can introduce bugs into your program. In this course, join instructor Shachar Shemesh to learn the fundamental skills you need to know as a developer to avoid implicit bugs in C++.

Explore real-world bug-causing behaviors such as automatically generated copy constructors and copy assignment operators, cast chains with both built-in and user-defined casts, undefined behaviors, exception semantics, and destructors. Along the way, Shachar raises your overall awareness of best practices for identifying, avoiding, strategizing, controlling, and protecting your work from implicit bugs.

Skills covered

C++AdvancedProgramming LanguagesOpen SourceSoftware Development

Concepts

Introduction

  • Implicit bugs in C++
  • Course structure

Implicit Copying

  • The FD class
  • You have a bug
  • Locating the bug
  • Exploring the implicit copy constructor
  • Implementing implicit copy
  • Disabling implicit copying
  • Move semantics
  • Assignment operators and copy-and-swap

Implicit Casts

  • Problem 1 - Only prints once
  • Constructors as implicit casts
  • The explicit keyword
  • Problem 2 - Corrupt file descriptor
  • Explicit for casts

Undefined Behavior

  • Parameters order evaluation
  • Implementation of defined, unspecified, and undefined behavior
  • Null pointer dereference
  • Deconstructing null pointer example
  • Why UBs are a good thing (or not)

Exceptions and Destructors

  • The danger of a destructor throwing
  • Potential solutions

Conclusion

  • Philosophy of defensive class
40,000 Toman