| 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-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// Pin down the ABI of associative containers with respect to their size and alignment |
| 10 |
// when passed a comparator that is a reference. |
| 11 |
// |
| 12 |
// While it's not even clear that reference comparators are legal in containers, an |
| 13 |
// unintended ABI break was discovered after implementing the new compressed pair |
| 14 |
// 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 become |
| 16 |
// 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 |
|
| 25 |
struct TEST_ALIGNAS(16) Cmp { |
| 26 |
bool operator()(int, int) const; |
| 27 |
}; |
| 28 |
|
| 29 |
template <class Compare> |
| 30 |
struct Set { |
| 31 |
char b; |
| 32 |
std::set<int, Compare> s; |
| 33 |
}; |
| 34 |
|
| 35 |
template <class Compare> |
| 36 |
struct Multiset { |
| 37 |
char b; |
| 38 |
std::multiset<int, Compare> s; |
| 39 |
}; |
| 40 |
|
| 41 |
template <class Compare> |
| 42 |
struct Map { |
| 43 |
char b; |
| 44 |
std::map<int, char, Compare> s; |
| 45 |
}; |
| 46 |
|
| 47 |
template <class Compare> |
| 48 |
struct Multimap { |
| 49 |
char b; |
| 50 |
std::multimap<int, char, Compare> s; |
| 51 |
}; |
| 52 |
|
| 53 |
static_assert(sizeof(Set<Cmp&>) == sizeof(Set<bool (*)(int, int)>), ""); |
| 54 |
static_assert(sizeof(Multiset<Cmp&>) == sizeof(Multiset<bool (*)(int, int)>), ""); |
| 55 |
|
| 56 |
static_assert(sizeof(Map<Cmp&>) == sizeof(Map<bool (*)(int, int)>), ""); |
| 57 |
static_assert(sizeof(Multimap<Cmp&>) == sizeof(Multimap<bool (*)(int, int)>), ""); |