summaryrefslogtreecommitdiff
path: root/test/CXX
diff options
context:
space:
mode:
authorJacob Bandes-Storch <jacob@bandes-stor.ch>2017-12-31 04:49:39 +0000
committerJacob Bandes-Storch <jacob@bandes-stor.ch>2017-12-31 04:49:39 +0000
commite006e0409cc387a371e7a22c1ef84b3048a7deed (patch)
tree9da64e2b17314b4e875818054063224ddbcd186e /test/CXX
parent2d075f470bfbcf5d146dca41b90374e32fc42278 (diff)
[Sema] Improve diagnostics for const- and ref-qualified member functions
Summary: Adjust wording for const-qualification mismatch to be a little more clear. Also add another diagnostic for a ref qualifier mismatch, which previously produced a useless error (this error path is simply very old; see rL119336): Before: error: cannot initialize object parameter of type 'X0' with an expression of type 'X0' After: error: 'this' argument to member function 'rvalue' is an lvalue, but function has rvalue ref-qualifier Reviewers: rsmith, aaron.ballman Reviewed By: aaron.ballman Subscribers: lebedev.ri, aaron.ballman, cfe-commits Differential Revision: https://reviews.llvm.org/D39937 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@321592 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CXX')
-rw-r--r--test/CXX/over/over.match/over.match.funcs/p4-0x.cpp38
1 files changed, 36 insertions, 2 deletions
diff --git a/test/CXX/over/over.match/over.match.funcs/p4-0x.cpp b/test/CXX/over/over.match/over.match.funcs/p4-0x.cpp
index 68c79900b9..df7762703c 100644
--- a/test/CXX/over/over.match/over.match.funcs/p4-0x.cpp
+++ b/test/CXX/over/over.match/over.match.funcs/p4-0x.cpp
@@ -1,5 +1,4 @@
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
-// expected-no-diagnostics
template<typename T> T &lvalue();
template<typename T> T &&xvalue();
@@ -20,6 +19,18 @@ struct X0 {
void g();
+ void c() const; // expected-note {{'c' declared here}}
+ void v() volatile; // expected-note {{'v' declared here}}
+ void r() __restrict__; // expected-note {{'r' declared here}}
+ void cr() const __restrict__; // expected-note {{'cr' declared here}}
+ void cv() const volatile;
+ void vr() volatile __restrict__; // expected-note {{'vr' declared here}}
+ void cvr() const volatile __restrict__;
+
+ void lvalue() &; // expected-note 2 {{'lvalue' declared here}}
+ void const_lvalue() const&;
+ void rvalue() &&; // expected-note {{'rvalue' declared here}}
+
int &operator+(const X0&) &;
float &operator+(const X0&) &&;
@@ -32,7 +43,7 @@ struct X0 {
float &h2() const&&;
};
-void X0::g() {
+void X0::g() { // expected-note {{'g' declared here}}
int &ir1 = f();
int &ir2 = X0::f();
}
@@ -69,3 +80,26 @@ void test_ref_qualifier_overloading() {
float &fr3 = xvalue<X0>().h2();
float &fr4 = prvalue<X0>().h2();
}
+
+void test_diagnostics(const volatile X0 &__restrict__ cvr) {
+ cvr.g(); // expected-error {{'this' argument to member function 'g' has type 'const volatile X0', but function is not marked const or volatile}}
+ cvr.c(); // expected-error {{not marked volatile}}
+ cvr.v(); // expected-error {{not marked const}}
+ cvr.r(); // expected-error {{not marked const or volatile}}
+ cvr.cr(); // expected-error {{not marked volatile}}
+ cvr.cv();
+ cvr.vr(); // expected-error {{not marked const}}
+ cvr.cvr();
+
+ lvalue<X0>().lvalue();
+ lvalue<X0>().const_lvalue();
+ lvalue<X0>().rvalue(); // expected-error {{'this' argument to member function 'rvalue' is an lvalue, but function has rvalue ref-qualifier}}
+
+ xvalue<X0>().lvalue(); // expected-error {{'this' argument to member function 'lvalue' is an rvalue, but function has non-const lvalue ref-qualifier}}
+ xvalue<X0>().const_lvalue();
+ xvalue<X0>().rvalue();
+
+ prvalue<X0>().lvalue(); // expected-error {{'this' argument to member function 'lvalue' is an rvalue, but function has non-const lvalue ref-qualifier}}
+ prvalue<X0>().const_lvalue();
+ prvalue<X0>().rvalue();
+}