[cfe-commits] r124321 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaOverload.cpp test/CXX/over/over.load/p2-0x.cpp
Douglas Gregor
dgregor at apple.com
Wed Jan 26 13:20:37 PST 2011
Author: dgregor
Date: Wed Jan 26 15:20:37 2011
New Revision: 124321
URL: http://llvm.org/viewvc/llvm-project?rev=124321&view=rev
Log:
Implement the restriction that a function with a ref-qualifier cannot
overload a function without a ref-qualifier (C++0x
[over.load]p2). This, apparently, completes the implementation of
rvalue references for *this.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/CXX/over/over.load/p2-0x.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=124321&r1=124320&r2=124321&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jan 26 15:20:37 2011
@@ -2481,6 +2481,11 @@
"%select{static member|nonmember}0 function cannot have a ref-qualifier "
"'%select{&&|&}1'">;
+def err_ref_qualifier_overload : Error<
+ "cannot overload a member function %select{without a ref-qualifier|with "
+ "ref-qualifier '&'|with ref-qualifier '&&'}0 with a member function %select{"
+ "without a ref-qualifier|with ref-qualifier '&'|with ref-qualifier '&&'}1">;
+
def err_invalid_non_static_member_use : Error<
"invalid use of nonstatic data member %0">;
def err_invalid_incomplete_type_use : Error<
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=124321&r1=124320&r2=124321&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Jan 26 15:20:37 2011
@@ -694,8 +694,24 @@
if (OldMethod && NewMethod &&
!OldMethod->isStatic() && !NewMethod->isStatic() &&
(OldMethod->getTypeQualifiers() != NewMethod->getTypeQualifiers() ||
- OldMethod->getRefQualifier() != NewMethod->getRefQualifier()))
+ OldMethod->getRefQualifier() != NewMethod->getRefQualifier())) {
+ if (!UseUsingDeclRules &&
+ OldMethod->getRefQualifier() != NewMethod->getRefQualifier() &&
+ (OldMethod->getRefQualifier() == RQ_None ||
+ NewMethod->getRefQualifier() == RQ_None)) {
+ // C++0x [over.load]p2:
+ // - Member function declarations with the same name and the same
+ // parameter-type-list as well as member function template
+ // declarations with the same name, the same parameter-type-list, and
+ // the same template parameter lists cannot be overloaded if any of
+ // them, but not all, have a ref-qualifier (8.3.5).
+ Diag(NewMethod->getLocation(), diag::err_ref_qualifier_overload)
+ << NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
+ Diag(OldMethod->getLocation(), diag::note_previous_declaration);
+ }
+
return true;
+ }
// The signatures match; this is not an overload.
return false;
Modified: cfe/trunk/test/CXX/over/over.load/p2-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/over/over.load/p2-0x.cpp?rev=124321&r1=124320&r2=124321&view=diff
==============================================================================
--- cfe/trunk/test/CXX/over/over.load/p2-0x.cpp (original)
+++ cfe/trunk/test/CXX/over/over.load/p2-0x.cpp Wed Jan 26 15:20:37 2011
@@ -10,12 +10,15 @@
void h() &;
void h() const &;
void h() &&;
- void i() &;
- void i() const; // FIXME: expected an error here!
+ void i() &; // expected-note{{previous declaration}}
+ void i() const; // expected-error{{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&'}}
template<typename T> void f(T*) &;
template<typename T> void f(T*) &&;
- template<typename T> void g(T*) &;
- template<typename T> void g(T*); // FIXME: expected an error here
+ template<typename T> void g(T*) &; // expected-note{{previous declaration}}
+ template<typename T> void g(T*); // expected-error{{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&'}}
+
+ void k(); // expected-note{{previous declaration}}
+ void k() &&; // expected-error{{cannot overload a member function with ref-qualifier '&&' with a member function without a ref-qualifier}}
};
More information about the cfe-commits
mailing list