|
| 1 | +// -*- C++ -*- |
| 2 | +//===----------------------------------------------------------------------===// |
| 3 | +// |
| 4 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | +// See https://llvm.org/LICENSE.txt for license information. |
| 6 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | +// |
| 8 | +//===----------------------------------------------------------------------===// |
| 9 | + |
| 10 | +#ifndef _LIBCPP___FORCE_NONSTANDARD_LAYOUT |
| 11 | +#define _LIBCPP___FORCE_NONSTANDARD_LAYOUT |
| 12 | + |
| 13 | +#include <__config> |
| 14 | + |
| 15 | +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 16 | +# pragma GCC system_header |
| 17 | +#endif |
| 18 | + |
| 19 | +_LIBCPP_BEGIN_NAMESPACE_STD |
| 20 | + |
| 21 | +// Force a class to be non-standard layout by giving it two bases with the same |
| 22 | +// type. This is useful when structure protection is enabled because structure |
| 23 | +// protection cannot be applied to standard layout classes. We may use this in |
| 24 | +// cases where the standard does not specify whether a standard library class is |
| 25 | +// standard layout. See C++2a [class]p7: |
| 26 | +// A class S is a standard-layout class if it: |
| 27 | +// -- has at most one base class subobject of any given type |
| 28 | +_LIBCPP_DIAGNOSTIC_PUSH |
| 29 | +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winaccessible-base") |
| 30 | +class __force_nonstandard_layout_base1 {}; |
| 31 | +class __force_nonstandard_layout_base2 : __force_nonstandard_layout_base1 {}; |
| 32 | +class __force_nonstandard_layout : __force_nonstandard_layout_base1, __force_nonstandard_layout_base2 {}; |
| 33 | +_LIBCPP_DIAGNOSTIC_POP |
| 34 | + |
| 35 | +#if __has_feature(pointer_field_protection) |
| 36 | +# define _LIBCPP_MAYBE_FORCE_NONSTANDARD_LAYOUT : __force_nonstandard_layout |
| 37 | +#else |
| 38 | +# define _LIBCPP_MAYBE_FORCE_NONSTANDARD_LAYOUT |
| 39 | +#endif |
| 40 | + |
| 41 | +_LIBCPP_END_NAMESPACE_STD |
| 42 | + |
| 43 | +#endif // _LIBCPP___FORCE_NONSTANDARD_LAYOUT |
0 commit comments