-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[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
tbaederr
wants to merge
1
commit into
llvm:main
Choose a base branch
from
tbaederr:discrim-union
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+8
−6
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesBefore this patch, we emitted a bunch of irrelevant (to this test) warnings:
Full diff: https://github.com/llvm/llvm-project/pull/146829.diff 1 Files Affected:
diff --git a/clang/test/SemaCXX/discrim-union.cpp b/clang/test/SemaCXX/discrim-union.cpp
index 15c9a225ed9a9..9877b70205104 100644
--- a/clang/test/SemaCXX/discrim-union.cpp
+++ b/clang/test/SemaCXX/discrim-union.cpp
@@ -46,8 +46,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>{});
}
};
@@ -79,13 +79,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<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")
@@ -93,7 +93,7 @@ class either {
}
template<typename U>
- constexpr const U &get() {
+ constexpr const U &get() const {
return get<impl_t::index(detail::type<U>())>();
}
};
|
Can we add -verify to the runline (+ expected-no-diagnostics)? |
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.
yes, done. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before this patch, we emitted a bunch of irrelevant (to this test) warnings: