|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | + |
| 4 | +#include <deque> |
| 5 | +#include <forward_list> |
| 6 | +#include <list> |
| 7 | +#include <queue> |
| 8 | +#include <stack> |
| 9 | +#include <type_traits> |
| 10 | +#include <utility> |
| 11 | +#include <vector> |
| 12 | + |
| 13 | +// Test for DevCom-10745303 / VSO-2252142 "C5046 is wrongly triggered in unevaluated context" |
| 14 | + |
| 15 | +#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) |
| 16 | + |
| 17 | +using namespace std; |
| 18 | + |
| 19 | +template <class T> |
| 20 | +struct convertible_to_any { |
| 21 | + operator T() &&; // not defined, only used in unevaluated context |
| 22 | +}; |
| 23 | + |
| 24 | +template <class Cont, class = void> |
| 25 | +constexpr bool has_emplace = false; |
| 26 | +template <class Cont> |
| 27 | +constexpr bool has_emplace<Cont, |
| 28 | + void_t<decltype(declval<Cont&>().emplace(declval<convertible_to_any<typename Cont::value_type>>()))>> = true; |
| 29 | + |
| 30 | +template <class Cont, class = void> |
| 31 | +constexpr bool has_emplace_back = false; |
| 32 | +template <class Cont> |
| 33 | +constexpr bool has_emplace_back<Cont, |
| 34 | + void_t<decltype(declval<Cont&>().emplace_back(declval<convertible_to_any<typename Cont::value_type>>()))>> = true; |
| 35 | + |
| 36 | +template <class Cont, class = void> |
| 37 | +constexpr bool has_emplace_front = false; |
| 38 | +template <class Cont> |
| 39 | +constexpr bool has_emplace_front<Cont, |
| 40 | + void_t<decltype(declval<Cont&>().emplace_front(declval<convertible_to_any<typename Cont::value_type>>()))>> = true; |
| 41 | + |
| 42 | +namespace { |
| 43 | + struct S2 {}; |
| 44 | +} // namespace |
| 45 | + |
| 46 | +// Was emitting "warning C5046: Symbol involving type with internal linkage not defined" |
| 47 | +// as a consequence of our use of return type deduction for the pertinent container functions. |
| 48 | +STATIC_ASSERT(has_emplace_back<vector<S2>>); |
| 49 | +STATIC_ASSERT(has_emplace_back<deque<S2>>); |
| 50 | +STATIC_ASSERT(has_emplace_front<deque<S2>>); |
| 51 | +STATIC_ASSERT(has_emplace_front<forward_list<S2>>); |
| 52 | +STATIC_ASSERT(has_emplace_back<list<S2>>); |
| 53 | +STATIC_ASSERT(has_emplace_front<list<S2>>); |
| 54 | +STATIC_ASSERT(has_emplace<queue<S2>>); |
| 55 | +STATIC_ASSERT(has_emplace<stack<S2>>); |
| 56 | +STATIC_ASSERT(has_emplace_back<vector<bool>>); // Cannot trigger this bug, but for consistency |
0 commit comments