~/talk

Undefined Behavior is Not an Error

Talkat emBO++ 2019 · 2019-03-14..03-17· [c-and-cpp, compilers-and-language-design]
links:none on file
links:none on file
slides:none on file

Built a C++ cross‑platform library suite (CopperSpice) and a forked documentation tool (doxypress), then hit real undefined behavior: a non‑null‑terminated QString lets clang optimize away loop code, static initialization order breaks startup, and sequencing/argument evaluation rules change behavior between C++11 and C++17. Uses concrete fixes (make string APIs safer, wrap statics in function locals, rewrite metadata), and relies on clang sanitizers and cross‑compiler/optimization testing to find UB. Treat UB as a P0 bug.

AI-written summary · about

  1. 0:00Start
  2. 3:01what does undefined behavior represent for a compiler developer ■fascinating and intriguing theoretical discussion ■possible masters degree subject for a compiler designer ■influences the way they write an optimizer
  3. 3:47what do C++ programmers believe about undefined behavior ■compilers should report undefined behavior as an error experienced developers can avoid bad code ■not my responsibility ■undefined behavior is easy to spot and simple to debug
  4. 19:03access an element of a container which is out of bounds 。 operator[] returns a reference to an element in the string no test to verify index + 1 and index + 2 are valid positions when the loop reaches the end of the string undefined behavior
  5. 22:46o relational comparison of pointers is only defined if the pointers point to members of the same object or elements of the same array ifs is replaced with the standard says you must return false
  6. 25:12modifying an object which was originally declared const keyword const_cast ■used to remove the "constness" so the data can be modified ■using this approach often means there is a design flaw modifying tmp is undefined behavior if the passed argument was originally declared const
  7. 29:14actions in C++ which produce side effects ■reading a volatile object write access to any object ■calling a library function which performs 1/0 ■Invoking a function which does any one of the above
  8. 33:55order of evaluation for passed parameters to a function originally unspecified, execution could be interleaved C++17 changed this to to indeterminately sequenced ⚫ evaluation of arguments is "sequenced before" the function call
  9. 42:28similar examples are shown as being defined in C++17 which exhibit the same compiler warning messages
~/search
type to search 8,222 conferences, 162,397 speakers and 219,688 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
← →
on a talk: 5 seconds back / forward
0–9
on a talk: jump to 0%–90% of the recording
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.