From ba7e210a999275695f58be03ef402758cfec3635 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 22 Oct 2008 15:04:37 +0000 Subject: [PATCH] QualType::isMoreQualifiedThan and isAtLeastAsQualifiedAs assert that we aren't trying to compare with address-space qualifiers (for now). Clean up handing of DeclRefExprs in Expr::isLvalue and refactor part of the check into a static DeclCanBeLvalue. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57980 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Type.h | 4 ++++ lib/AST/Expr.cpp | 17 +++++++++++------ lib/Sema/SemaOverload.cpp | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 85635709e0..29941aad09 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -1362,6 +1362,8 @@ inline bool QualType::isMoreQualifiedThan(QualType Other) const { // FIXME: Handle address spaces unsigned MyQuals = this->getCVRQualifiers(); unsigned OtherQuals = Other.getCVRQualifiers(); + assert(this->getAddressSpace() == 0 && "Address space not checked"); + assert(Other.getAddressSpace() == 0 && "Address space not checked"); return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals; } @@ -1373,6 +1375,8 @@ inline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const { // FIXME: Handle address spaces unsigned MyQuals = this->getCVRQualifiers(); unsigned OtherQuals = Other.getCVRQualifiers(); + assert(this->getAddressSpace() == 0 && "Address space not checked"); + assert(Other.getAddressSpace() == 0 && "Address space not checked"); return (MyQuals | OtherQuals) == MyQuals; } diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 4fd8a24c8a..5c0e38cf9e 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -322,6 +322,15 @@ bool Expr::hasLocalSideEffect() const { } } +/// DeclCanBeLvalue - Determine whether the given declaration can be +/// an lvalue. This is a helper routine for isLvalue. +static bool DeclCanBeLvalue(const NamedDecl *Decl, ASTContext &Ctx) { + return isa(Decl) || + // C++ 3.10p2: An lvalue refers to an object or function. + (Ctx.getLangOptions().CPlusPlus && + (isa(Decl) || isa(Decl))); +} + /// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or an /// incomplete type other than void. Nonarray expressions that can be lvalues: /// - name, where name must be a variable @@ -359,12 +368,8 @@ Expr::isLvalueResult Expr::isLvalue(ASTContext &Ctx) const { return cast(this)->getBase()->isLvalue(Ctx); return LV_Valid; case DeclRefExprClass: { // C99 6.5.1p2 - const Decl *RefdDecl = cast(this)->getDecl(); - if (isa(RefdDecl) || - isa(RefdDecl) || - // C++ 3.10p2: An lvalue refers to an object or function. - isa(RefdDecl) || - isa(RefdDecl)) + const NamedDecl *RefdDecl = cast(this)->getDecl(); + if (DeclCanBeLvalue(RefdDecl, Ctx)) return LV_Valid; break; } diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 8e440258b7..cafdf8794a 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -811,6 +811,7 @@ ImplicitConversionSequence::CompareKind Sema::CompareQualificationConversions(const StandardConversionSequence& SCS1, const StandardConversionSequence& SCS2) { + // C++ 13.3.3.2p3: // -- S1 and S2 differ only in their qualification conversion and // yield similar types T1 and T2 (C++ 4.4), respectively, and the // cv-qualification signature of type T1 is a proper subset of