Skip to content

Add C++ undefined behavior section #214

@aarmaane

Description

@aarmaane

What
We should consider adding a section that describes common occurrences of undefined/unspecified behavior in C++. This section could link to various pieces of C++ documentation as a source if students wanted to read more about specific details. It could also draw attention to the specific behaviors that will be exposed by sanitizers (and the ones that it won't help you with).

Where
Probably belongs in the "Advanced/Extra Tutorials" section of the tutorials. We could link to portions of it in our project specs when there's a issue that we commonly see.

Why

  1. It would provide background information so students can understand when and why they need to enable sanitizers. It also serves as a good introduction to the distinction between language specifications and compiler-specific implementations.
  2. This would be a great resource for macOS users. We use Linux GCC on the autograder and for Windows users. But macOS users use Apple Clang and often come across implementation differences when they submit to the autograder (i.e. "It works on my laptop, why is the autograder failing?"). We have to repeat the same explanation to each student when they come across it for the first time. It would nice if there was a common resource we could point them towards.

Common Apple Clang issues in EECS 280:

  • Variables are often initialized to 0 for you
  • Some #include statements seem like they're not needed because another Clang library already #includes it (while the same GCC library does not)
  • Function parameters are evaluated in a different order than GCC
  • Debug library differences mentioned in MacOS Standard Library Hardening #211
  • Variable-length arrays are implemented as a language extension (though less common since we've changed P2 to use vectors instead)

References
https://en.cppreference.com/w/cpp/language/ub

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions