Undefined Behavior - Not what you expected
summary
A retry loop decrements an unsigned counter and then immediately dereferences a member pointer that can become null; that null pointer dereference is undefined behavior so Clang's optimizer removes the exit branch, turning the loop into an endless sequence of "connection failed" logs. The bug reproduces only with Clang (not GCC) and is visible on Godbolt; the surprising claim is that a UB after the loop lets the compiler delete the loop-exit check.
AI-written summary · about
related talks
33mUndefined Behavior in C++: What Every Programmer Should Know and Fear
01h 02mBack To Basics: Undefined Behavior
01h 04mRemoving Needless Undefined Behavior for a Safer C++
01h 30mDangerous Optimizations in C and C++ Programming Languages
01h 04mUndefined Behavior in the STL
07mLightning Talk: The UB Detector: constexpr
01h 27mDangerous Optimizations! in C++ - Part Deux
19mExploiting Undefined Behavior in C/C++ Programs for Optimization: A Study on the(…)
