Skip to content

Commit 8f95d47

Browse files
committed
[clang][test] Avoid some C++14 warnings in discrim-union.cpp
Before this patch, we emitted a bunch of irrelevant (to this test) warnings: ../clang/test/SemaCXX/discrim-union.cpp:49:24: warning: 'constexpr' non-static member function will not be implicitly 'const' in C++14; add 'const' to avoid a change in behavior [-Wconstexpr-not-const] 49 | constexpr const T &get(select<0>) { return val; } | ^ | const ../clang/test/SemaCXX/discrim-union.cpp:50:104: warning: 'constexpr' non-static member function will not be implicitly 'const' in C++14; add 'const' to avoid a change in behavior [-Wconstexpr-not-const] 50 | template<unsigned N> constexpr const decltype(static_cast<const rest_t&>(rest).get(select<N-1>{})) get(select<N>) { | ^ | const ../clang/test/SemaCXX/discrim-union.cpp:82:22: warning: 'constexpr' non-static member function will not be implicitly 'const' in C++14; add 'const' to avoid a change in behavior [-Wconstexpr-not-const] 82 | constexpr unsigned index() noexcept { return elem; } | ^ | const ../clang/test/SemaCXX/discrim-union.cpp:88:33: warning: 'constexpr' non-static member function will not be implicitly 'const' in C++14; add 'const' to avoid a change in behavior [-Wconstexpr-not-const] 88 | constexpr const_get_result<N> get() { | ^ | const ../clang/test/SemaCXX/discrim-union.cpp:96:22: warning: 'constexpr' non-static member function will not be implicitly 'const' in C++14; add 'const' to avoid a change in behavior [-Wconstexpr-not-const] 96 | constexpr const U &get() { | ^ | const 5 warnings generated.
1 parent 31e85f9 commit 8f95d47

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

clang/test/SemaCXX/discrim-union.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ namespace detail {
4646
val.~T();
4747
}
4848

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>) {
49+
constexpr const T &get(select<0>) const { return val; }
50+
template<unsigned N> constexpr const decltype(static_cast<const rest_t&>(rest).get(select<N-1>{})) get(select<N>) const {
5151
return rest.get(select<N-1>{});
5252
}
5353
};
@@ -79,21 +79,21 @@ class either {
7979
// FIXME: declare a destructor iff any element has a nontrivial destructor
8080
//~either() { impl.destroy(elem); }
8181

82-
constexpr unsigned index() noexcept { return elem; }
82+
constexpr unsigned index() const noexcept { return elem; }
8383

8484
template<unsigned N> using const_get_result =
8585
decltype(static_cast<const impl_t&>(impl).get(detail::select<N>{}));
8686

8787
template<unsigned N>
88-
constexpr const_get_result<N> get() {
88+
constexpr const_get_result<N> get() const {
8989
// Can't just use throw here, since that makes the conditional a prvalue,
9090
// which means we return a reference to a temporary.
9191
return (elem != N ? throw_<const_get_result<N>>("bad_either_get")
9292
: impl.get(detail::select<N>{}));
9393
}
9494

9595
template<typename U>
96-
constexpr const U &get() {
96+
constexpr const U &get() const {
9797
return get<impl_t::index(detail::type<U>())>();
9898
}
9999
};

0 commit comments

Comments
 (0)