Skip to content

[clang][test] Avoid some C++14 warnings in discrim-union.cpp #146829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions clang/test/SemaCXX/discrim-union.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// RUN: %clang_cc1 -std=c++11 %s -fsyntax-only -fcxx-exceptions
// RUN: %clang_cc1 -std=c++11 %s -fsyntax-only -fcxx-exceptions -verify

// expected-no-diagnostics

template<typename T> struct remove_reference { typedef T type; };
template<typename T> struct remove_reference<T&> { typedef T type; };
Expand Down Expand Up @@ -46,8 +48,8 @@ namespace detail {
val.~T();
}

constexpr const T &get(select<0>) { return val; }
template<unsigned N> constexpr const decltype(static_cast<const rest_t&>(rest).get(select<N-1>{})) get(select<N>) {
constexpr const T &get(select<0>) const { return val; }
template<unsigned N> constexpr const decltype(static_cast<const rest_t&>(rest).get(select<N-1>{})) get(select<N>) const {
return rest.get(select<N-1>{});
}
};
Expand Down Expand Up @@ -79,21 +81,21 @@ class either {
// FIXME: declare a destructor iff any element has a nontrivial destructor
//~either() { impl.destroy(elem); }

constexpr unsigned index() noexcept { return elem; }
constexpr unsigned index() const noexcept { return elem; }

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

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

template<typename U>
constexpr const U &get() {
constexpr const U &get() const {
return get<impl_t::index(detail::type<U>())>();
}
};
Expand Down