|
1 |
| -// RUN: %clang_cc1 -std=c++11 %s -fsyntax-only -fcxx-exceptions |
| 1 | +// RUN: %clang_cc1 -std=c++11 %s -fsyntax-only -fcxx-exceptions -verify |
| 2 | + |
| 3 | +// expected-no-diagnostics |
2 | 4 |
|
3 | 5 | template<typename T> struct remove_reference { typedef T type; };
|
4 | 6 | template<typename T> struct remove_reference<T&> { typedef T type; };
|
@@ -46,8 +48,8 @@ namespace detail {
|
46 | 48 | val.~T();
|
47 | 49 | }
|
48 | 50 |
|
49 |
| - constexpr const T &get(select<0>) { return val; } |
50 |
| - template<unsigned N> constexpr const decltype(static_cast<const rest_t&>(rest).get(select<N-1>{})) get(select<N>) { |
| 51 | + constexpr const T &get(select<0>) const { return val; } |
| 52 | + template<unsigned N> constexpr const decltype(static_cast<const rest_t&>(rest).get(select<N-1>{})) get(select<N>) const { |
51 | 53 | return rest.get(select<N-1>{});
|
52 | 54 | }
|
53 | 55 | };
|
@@ -79,21 +81,21 @@ class either {
|
79 | 81 | // FIXME: declare a destructor iff any element has a nontrivial destructor
|
80 | 82 | //~either() { impl.destroy(elem); }
|
81 | 83 |
|
82 |
| - constexpr unsigned index() noexcept { return elem; } |
| 84 | + constexpr unsigned index() const noexcept { return elem; } |
83 | 85 |
|
84 | 86 | template<unsigned N> using const_get_result =
|
85 | 87 | decltype(static_cast<const impl_t&>(impl).get(detail::select<N>{}));
|
86 | 88 |
|
87 | 89 | template<unsigned N>
|
88 |
| - constexpr const_get_result<N> get() { |
| 90 | + constexpr const_get_result<N> get() const { |
89 | 91 | // Can't just use throw here, since that makes the conditional a prvalue,
|
90 | 92 | // which means we return a reference to a temporary.
|
91 | 93 | return (elem != N ? throw_<const_get_result<N>>("bad_either_get")
|
92 | 94 | : impl.get(detail::select<N>{}));
|
93 | 95 | }
|
94 | 96 |
|
95 | 97 | template<typename U>
|
96 |
| - constexpr const U &get() { |
| 98 | + constexpr const U &get() const { |
97 | 99 | return get<impl_t::index(detail::type<U>())>();
|
98 | 100 | }
|
99 | 101 | };
|
|
0 commit comments