[cfe-commits] r39566 - /cfe/cfe/trunk/AST/Type.cpp
bwendlin at cs.uiuc.edu
bwendlin at cs.uiuc.edu
Wed Jul 11 09:45:41 PDT 2007
Author: bwendlin
Date: Wed Jul 11 11:45:40 2007
New Revision: 39566
URL: http://llvm.org/viewvc/llvm-project?rev=39566&view=rev
Log:
Submitted by: Bill Wendling
Reviewed by: Chris Lattner
- Added a method to determine if two types, where at least one is a
reference, are compatible. That is you can assign the RHS to the LHS.
Modified:
cfe/cfe/trunk/AST/Type.cpp
Modified: cfe/cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Type.cpp?rev=39566&r1=39565&r2=39566&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Type.cpp (original)
+++ cfe/cfe/trunk/AST/Type.cpp Wed Jul 11 11:45:40 2007
@@ -117,6 +117,23 @@
return typesAreCompatible(ltype, rtype);
}
+// C++ 5.17p6: When the left opperand of an assignment operator denotes a
+// reference to T, the operation assigns to the object of type T denoted by the
+// reference.
+bool Type::referenceTypesAreCompatible(QualType lhs, QualType rhs) {
+ QualType ltype = lhs;
+
+ if (lhs->isReferenceType())
+ ltype = cast<ReferenceType>(lhs.getCanonicalType())->getReferenceeType();
+
+ QualType rtype = rhs;
+
+ if (rhs->isReferenceType())
+ rtype = cast<ReferenceType>(rhs.getCanonicalType())->getReferenceeType();
+
+ return typesAreCompatible(ltype, rtype);
+}
+
bool Type::functionTypesAreCompatible(QualType lhs, QualType rhs) {
const FunctionType *lbase = cast<FunctionType>(lhs.getCanonicalType());
const FunctionType *rbase = cast<FunctionType>(rhs.getCanonicalType());
@@ -190,6 +207,8 @@
switch (lcanon->getTypeClass()) {
case Type::Pointer:
return pointerTypesAreCompatible(lcanon, rcanon);
+ case Type::Reference:
+ return referenceTypesAreCompatible(lcanon, rcanon);
case Type::Array:
return arrayTypesAreCompatible(lcanon, rcanon);
case Type::FunctionNoProto:
More information about the cfe-commits
mailing list