[cfe-commits] r67492 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaOverload.cpp test/SemaCXX/rval-references.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Sun Mar 22 16:49:29 PDT 2009
Author: cornedbee
Date: Sun Mar 22 18:49:27 2009
New Revision: 67492
URL: http://llvm.org/viewvc/llvm-project?rev=67492&view=rev
Log:
Disallow catching exceptions by rvalue reference.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/SemaCXX/rval-references.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=67492&r1=67491&r2=67492&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Mar 22 18:49:27 2009
@@ -1040,6 +1040,7 @@
def err_catch_incomplete_ref : Error<
"cannot catch reference to incomplete type %0">;
def err_catch_incomplete : Error<"cannot catch incomplete type %0">;
+def err_catch_rvalue_ref : Error<"cannot catch exceptions by rvalue reference">;
def err_qualified_catch_declarator : Error<
"exception declarator cannot be qualified">;
def err_early_catch_all : Error<"catch-all handler must come last">;
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=67492&r1=67491&r2=67492&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sun Mar 22 18:49:27 2009
@@ -2320,6 +2320,11 @@
// C++ 15.3p1: The exception-declaration shall not denote an incomplete type.
// The exception-declaration shall not denote a pointer or reference to an
// incomplete type, other than [cv] void*.
+ // N2844 forbids rvalue references.
+ if(ExDeclType->isRValueReferenceType()) {
+ Diag(Begin, diag::err_catch_rvalue_ref) << D.getSourceRange();
+ Invalid = true;
+ }
QualType BaseType = ExDeclType;
int Mode = 0; // 0 for direct type, 1 for pointer, 2 for reference
unsigned DK = diag::err_catch_incomplete;
@@ -2328,16 +2333,15 @@
Mode = 1;
DK = diag::err_catch_incomplete_ptr;
} else if(const ReferenceType *Ref = BaseType->getAsReferenceType()) {
+ // For the purpose of error recovery, we treat rvalue refs like lvalue refs.
BaseType = Ref->getPointeeType();
Mode = 2;
DK = diag::err_catch_incomplete_ref;
}
- if ((Mode == 0 || !BaseType->isVoidType()) &&
+ if (!Invalid && (Mode == 0 || !BaseType->isVoidType()) &&
RequireCompleteType(Begin, BaseType, DK))
Invalid = true;
- // FIXME: C++0x [except.handle] names the handler as cv T or cv T&, i.e.
- // rvalue references aren't there. Oversight or intentional?
// FIXME: Need to test for ability to copy-construct and destroy the
// exception variable.
// FIXME: Need to check for abstract classes.
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=67492&r1=67491&r2=67492&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Sun Mar 22 18:49:27 2009
@@ -1584,15 +1584,26 @@
= CompareQualificationConversions(SCS1, SCS2))
return QualCK;
- // C++ [over.ics.rank]p3b4:
- // -- S1 and S2 are reference bindings (8.5.3), and the types to
- // which the references refer are the same type except for
- // top-level cv-qualifiers, and the type to which the reference
- // initialized by S2 refers is more cv-qualified than the type
- // to which the reference initialized by S1 refers.
if (SCS1.ReferenceBinding && SCS2.ReferenceBinding) {
QualType T1 = QualType::getFromOpaquePtr(SCS1.ToTypePtr);
QualType T2 = QualType::getFromOpaquePtr(SCS2.ToTypePtr);
+ // C++0x [over.ics.rank]p3b4:
+ // -- S1 and S2 are reference bindings (8.5.3) and neither refers to an
+ // implicit object parameter of a non-static member function declared
+ // without a ref-qualifier, and S1 binds an rvalue reference to an
+ // rvalue and S2 binds an lvalue reference.
+ // FIXME: We have far too little information for this check. We don't know
+ // if the bound object is an rvalue. We don't know if the binding type is
+ // an rvalue or lvalue reference. We don't know if we're dealing with the
+ // implicit object parameter, or if the member function in this case has
+ // a ref qualifier.
+
+ // C++ [over.ics.rank]p3b4:
+ // -- S1 and S2 are reference bindings (8.5.3), and the types to
+ // which the references refer are the same type except for
+ // top-level cv-qualifiers, and the type to which the reference
+ // initialized by S2 refers is more cv-qualified than the type
+ // to which the reference initialized by S1 refers.
T1 = Context.getCanonicalType(T1);
T2 = Context.getCanonicalType(T2);
if (T1.getUnqualifiedType() == T2.getUnqualifiedType()) {
Modified: cfe/trunk/test/SemaCXX/rval-references.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/rval-references.cpp?rev=67492&r1=67491&r2=67492&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/rval-references.cpp (original)
+++ cfe/trunk/test/SemaCXX/rval-references.cpp Sun Mar 22 18:49:27 2009
@@ -45,4 +45,9 @@
conv_to_not_int_rvalue cnir;
not_int &&ni4 = cnir;
not_int &ni5 = cnir; // expected-error{{non-const lvalue reference to type 'struct not_int' cannot be initialized with a value of type 'struct conv_to_not_int_rvalue'}}
+
+
+ try {
+ } catch(int&&) { // expected-error {{cannot catch exceptions by rvalue reference}}
+ }
}
More information about the cfe-commits
mailing list