[all-commits] [llvm/llvm-project] e09761: [libc++] Improves UB handling in ios_base destruct...

Mark de Wever via All-commits all-commits at lists.llvm.org
Tue Mar 12 10:04:37 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e09761944cea4aeafadd055b9510ef9f0e9a7338
      https://github.com/llvm/llvm-project/commit/e09761944cea4aeafadd055b9510ef9f0e9a7338
  Author: Mark de Wever <koraq at xs4all.nl>
  Date:   2024-03-12 (Tue, 12 Mar 2024)

  Changed paths:
    M libcxx/include/ios
    M libcxx/src/ios.cpp
    A libcxx/test/libcxx/input.output/iostreams.base/ios.base/ios.base.cons/dtor.uninitialized.pass.cpp

  Log Message:
  -----------
  [libc++] Improves UB handling in ios_base destructor. (#76525)

Destroying an ios_base object before it is properly initialized is
undefined behavior. Unlike typical C++ classes the initialization is not
done in the constructor, but in a dedicated init function. Due to
virtual inheritance of the basic_ios object in ostream and friends this
undefined behaviour can be triggered when inheriting from classes that
can throw in their constructor and inheriting from ostream.

Use the __loc_ member of ios_base as sentinel to detect whether the
object has or has not been initialized.

Addresses https://github.com/llvm/llvm-project/issues/57964



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list