brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · c042509 Raw
84 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// TODO(mordante) Investigate10// UNSUPPORTED: apple-clang11 12// UNSUPPORTED: no-exceptions13 14// The fix for issue 57964 requires an updated dylib due to explicit15// instantiations. That means Apple backdeployment targets remain broken.16// XFAIL using-built-library-before-llvm-1917 18// <ios>19 20// class ios_base21 22// ~ios_base()23//24// Destroying a constructed ios_base object that has not been25// initialized by basic_ios::init is undefined behaviour. This can26// happen in practice, make sure the undefined behaviour is handled27// gracefully.28//29//30// [ios.base.cons]/131//32// ios_base();33// Effects: Each ios_base member has an indeterminate value after construction.34// The object's members shall be initialized by calling basic_ios::init before35// the object's first use or before it is destroyed, whichever comes first;36// otherwise the behavior is undefined.37//38// [basic.ios.cons]/239//40// basic_ios();41// Effects: Leaves its member objects uninitialized.  The object shall be42// initialized by calling basic_ios::init before its first use or before it is43// destroyed, whichever comes first; otherwise the behavior is undefined.44//45// ostream and friends have a basic_ios virtual base.46// [class.base.init]/1347// In a non-delegating constructor, initialization proceeds in the48// following order:49// - First, and only for the constructor of the most derived class50//   ([intro.object]), virtual base classes are initialized ...51//52// So in this example53// struct Foo : AlwaysThrows, std::ostream {54//    Foo() : AlwaysThrows{}, std::ostream{nullptr} {}55// };56//57// Here58// - the ios_base object is constructed59// - the AlwaysThrows object is constructed and throws an exception60// - the AlwaysThrows object is destrodyed61// - the ios_base object is destroyed62//63// The ios_base object is destroyed before it has been initialized and runs64// into undefined behavior. By using __loc_ as a sentinel we can avoid65// accessing uninitialized memory in the destructor.66 67#include <ostream>68 69struct AlwaysThrows {70  AlwaysThrows() { throw 1; }71};72 73struct Foo : AlwaysThrows, std::ostream {74  Foo() : AlwaysThrows(), std::ostream(nullptr) {}75};76 77int main(int, char**) {78  try {79    Foo foo;80  } catch (...) {81  };82  return 0;83}84