From: Jacob Bandes-Storch Date: Sun, 31 Dec 2017 05:13:03 +0000 (+0000) Subject: Reverted 321592: [Sema] Improve diagnostics for const- and ref-qualified member functions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=352a8a419d7c9515bd05787c0390238f609cd4ae;p=clang Reverted 321592: [Sema] Improve diagnostics for const- and ref-qualified member functions A few tests need to be fixed git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@321593 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index e4649d3a44..01e819942f 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1589,19 +1589,11 @@ def err_non_virtual_pure : Error< def ext_pure_function_definition : ExtWarn< "function definition with pure-specifier is a Microsoft extension">, InGroup; -def err_qualified_member_of_unrelated : Error< - "%q0 is not a member of class %1">; - -def err_member_function_call_bad_cvr : Error< - "'this' argument to member function %0 has type %1, but function is not marked " - "%select{const|restrict|const or restrict|volatile|const or volatile|" - "volatile or restrict|const, volatile, or restrict}2">; -def err_member_function_call_bad_ref : Error< - "'this' argument to member function %0 is an %select{lvalue|rvalue}1, " - "but function has %select{non-const lvalue|rvalue}2 ref-qualifier">; -def err_member_function_call_bad_type : Error< +def err_implicit_object_parameter_init : Error< "cannot initialize object parameter of type %0 with an expression " "of type %1">; +def err_qualified_member_of_unrelated : Error< + "%q0 is not a member of class %1">; def warn_call_to_pure_virtual_member_function_from_ctor_dtor : Warning< "call to pure virtual member function %0 has undefined behavior; " @@ -1823,6 +1815,10 @@ def warn_temporary_array_to_pointer_decay : Warning< def err_init_list_bad_dest_type : Error< "%select{|non-aggregate }0type %1 cannot be initialized with an initializer " "list">; +def err_member_function_call_bad_cvr : Error<"member function %0 not viable: " + "'this' argument has type %1, but function is not marked " + "%select{const|restrict|const or restrict|volatile|const or volatile|" + "volatile or restrict|const, volatile, or restrict}2">; def err_reference_bind_to_bitfield : Error< "%select{non-const|volatile}0 reference cannot bind to " diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 07d931552f..2144845f4d 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -5145,8 +5145,7 @@ Sema::PerformObjectArgumentInitialization(Expr *From, *this, From->getLocStart(), From->getType(), FromClassification, Method, Method->getParent()); if (ICS.isBad()) { - switch (ICS.Bad.Kind) { - case BadConversionSequence::bad_qualifiers: { + if (ICS.Bad.Kind == BadConversionSequence::bad_qualifiers) { Qualifiers FromQs = FromRecordType.getQualifiers(); Qualifiers ToQs = DestType.getQualifiers(); unsigned CVR = FromQs.getCVRQualifiers() & ~ToQs.getCVRQualifiers(); @@ -5159,28 +5158,10 @@ Sema::PerformObjectArgumentInitialization(Expr *From, << Method->getDeclName(); return ExprError(); } - break; - } - - case BadConversionSequence::lvalue_ref_to_rvalue: - case BadConversionSequence::rvalue_ref_to_lvalue: { - bool IsRValueQualified = - Method->getRefQualifier() == RefQualifierKind::RQ_RValue; - Diag(From->getLocStart(), diag::err_member_function_call_bad_ref) - << Method->getDeclName() << FromClassification.isRValue() - << IsRValueQualified; - Diag(Method->getLocation(), diag::note_previous_decl) - << Method->getDeclName(); - return ExprError(); - } - - case BadConversionSequence::no_conversion: - case BadConversionSequence::unrelated_class: - break; } return Diag(From->getLocStart(), - diag::err_member_function_call_bad_type) + diag::err_implicit_object_parameter_init) << ImplicitParamRecordType << FromRecordType << From->getSourceRange(); } 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 df7762703c..68c79900b9 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,4 +1,5 @@ // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s +// expected-no-diagnostics template T &lvalue(); template T &&xvalue(); @@ -19,18 +20,6 @@ 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&) &&; @@ -43,7 +32,7 @@ struct X0 { float &h2() const&&; }; -void X0::g() { // expected-note {{'g' declared here}} +void X0::g() { int &ir1 = f(); int &ir2 = X0::f(); } @@ -80,26 +69,3 @@ void test_ref_qualifier_overloading() { float &fr3 = xvalue().h2(); float &fr4 = prvalue().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().lvalue(); - lvalue().const_lvalue(); - lvalue().rvalue(); // expected-error {{'this' argument to member function 'rvalue' is an lvalue, but function has rvalue ref-qualifier}} - - xvalue().lvalue(); // expected-error {{'this' argument to member function 'lvalue' is an rvalue, but function has non-const lvalue ref-qualifier}} - xvalue().const_lvalue(); - xvalue().rvalue(); - - prvalue().lvalue(); // expected-error {{'this' argument to member function 'lvalue' is an rvalue, but function has non-const lvalue ref-qualifier}} - prvalue().const_lvalue(); - prvalue().rvalue(); -} diff --git a/test/SemaCXX/copy-initialization.cpp b/test/SemaCXX/copy-initialization.cpp index cd7e5f07e1..4f6c65cf55 100644 --- a/test/SemaCXX/copy-initialization.cpp +++ b/test/SemaCXX/copy-initialization.cpp @@ -26,7 +26,7 @@ struct foo { }; // PR3600 -void test(const foo *P) { P->bar(); } // expected-error{{'this' argument to member function 'bar' has type 'const foo', but function is not marked const}} +void test(const foo *P) { P->bar(); } // expected-error{{'bar' not viable: 'this' argument has type 'const foo', but function is not marked const}} namespace PR6757 { struct Foo {