Implicit Conversions Considered Harmful
summary
Implicit conversions create surprising behavior and hidden costs: converting string literals to std::string makes temporaries and extra copies, pair-to-pair and tuple-like conversions silently copy and rewrap std::function causing heap allocs and a measured 10x slowdown in a QuickBench microbenchmark, moving into const smart pointers materializes temporaries and forces extra refcount increments on shared_ptr. Tools sometimes help — GCC warning "loop variable binds to temporary" or clang-tidy checks catch common cases, Visual Studio emits other warnings, and perf with call-graph tracing or Cachegrind exposes where implicit conversions inflate call counts.
AI-written summary · about
chapters (18)
- 0:00Welcome
- 3:21Implicit conversions tools miss
- 10:48Code review of PR
- 18:16Historical context advice
- 22:54C++11 library features
- 26:50Tuple and pair conversions
- 31:34Unique pointer issues
- 36:17Shared pointer overhead
- 42:23Variant and optional conversions
- 43:25String views undefined behavior
- 45:54C++20 and C++23 additions
- 48:00Complex conversion chains
- 51:17Performance impact
- 52:22Finding conversion costs
- 55:39AI tools fail to detect
- 56:45Best practices
- 59:57Future solutions and proposal
- 1:00:20Q&A
related talks
58mArgument Passing, Core Guidelines and Aliasing
33mC++: Unexpected Behaviour
01h 03mHidden Overhead of a Function API
45mBack to Basics: Casting
48mWhat is a static function but isn't a static function
06mSafe bool idiom
01h 00mThe Implementation of Value Types
01h 30mDangerous Optimizations in C and C++ Programming Languages
