diff --git a/clang/test/SemaCXX/discrim-union.cpp b/clang/test/SemaCXX/discrim-union.cpp index 15c9a225ed9a9..b1476aaf1be8b 100644 --- a/clang/test/SemaCXX/discrim-union.cpp +++ b/clang/test/SemaCXX/discrim-union.cpp @@ -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 struct remove_reference { typedef T type; }; template struct remove_reference { typedef T type; }; @@ -46,8 +48,8 @@ namespace detail { val.~T(); } - constexpr const T &get(select<0>) { return val; } - template constexpr const decltype(static_cast(rest).get(select{})) get(select) { + constexpr const T &get(select<0>) const { return val; } + template constexpr const decltype(static_cast(rest).get(select{})) get(select) const { return rest.get(select{}); } }; @@ -79,13 +81,13 @@ 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 using const_get_result = decltype(static_cast(impl).get(detail::select{})); template - constexpr const_get_result get() { + constexpr const_get_result 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_>("bad_either_get") @@ -93,7 +95,7 @@ class either { } template - constexpr const U &get() { + constexpr const U &get() const { return get())>(); } };