brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 6a26db9 Raw
58 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// Pin down the ABI of associative containers with respect to their size and alignment10// when passed a comparator that is a reference.11//12// While it's not even clear that reference comparators are legal in containers, an13// unintended ABI break was discovered after implementing the new compressed pair14// mechanism based on [[no_unique_address]], and this is a regression test for that.15// If we decide to make reference comparators ill-formed, this test would become16// unnecessary.17//18// See https://llvm.org/PR118559 for more details.19 20#include <set>21#include <map>22 23#include "test_macros.h"24 25struct TEST_ALIGNAS(16) Cmp {26  bool operator()(int, int) const;27};28 29template <class Compare>30struct Set {31  char b;32  std::set<int, Compare> s;33};34 35template <class Compare>36struct Multiset {37  char b;38  std::multiset<int, Compare> s;39};40 41template <class Compare>42struct Map {43  char b;44  std::map<int, char, Compare> s;45};46 47template <class Compare>48struct Multimap {49  char b;50  std::multimap<int, char, Compare> s;51};52 53static_assert(sizeof(Set<Cmp&>) == sizeof(Set<bool (*)(int, int)>), "");54static_assert(sizeof(Multiset<Cmp&>) == sizeof(Multiset<bool (*)(int, int)>), "");55 56static_assert(sizeof(Map<Cmp&>) == sizeof(Map<bool (*)(int, int)>), "");57static_assert(sizeof(Multimap<Cmp&>) == sizeof(Multimap<bool (*)(int, int)>), "");58