diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2009-11-18 20:39:26 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2009-11-18 20:39:26 +0000 |
commit | a9efadada0430493a4d68b34b2e76580d0fd8f10 (patch) | |
tree | 0b0ced540821a084f1fe6beb12633db8cede7422 | |
parent | c3ca6ef0e0624c153b73a5b75bd9e82fc95f2712 (diff) |
Don't generate superfluous and ambiguous built-in candidates for multi-level array subscript and arithmetic. Fixes PR5546.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89242 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 12 | ||||
-rw-r--r-- | test/SemaCXX/overloaded-operator.cpp | 10 |
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index c9c16aafc4..916fe57192 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -3022,6 +3022,12 @@ BuiltinCandidateTypeSet::AddPointerWithMoreQualifiedTypeVariants(QualType Ty, assert(PointerTy && "type was not a pointer type!"); QualType PointeeTy = PointerTy->getPointeeType(); + // Don't add qualified variants of arrays. For one, they're not allowed + // (the qualifier would sink to the element type), and for another, the + // only overload situation where it matters is subscript or pointer +- int, + // and those shouldn't have qualifier variants anyway. + if (PointeeTy->isArrayType()) + return true; unsigned BaseCVR = PointeeTy.getCVRQualifiers(); if (const ConstantArrayType *Array =Context.getAsConstantArrayType(PointeeTy)) BaseCVR = Array->getElementType().getCVRQualifiers(); @@ -3062,6 +3068,12 @@ BuiltinCandidateTypeSet::AddMemberPointerWithMoreQualifiedTypeVariants( assert(PointerTy && "type was not a member pointer type!"); QualType PointeeTy = PointerTy->getPointeeType(); + // Don't add qualified variants of arrays. For one, they're not allowed + // (the qualifier would sink to the element type), and for another, the + // only overload situation where it matters is subscript or pointer +- int, + // and those shouldn't have qualifier variants anyway. + if (PointeeTy->isArrayType()) + return true; const Type *ClassTy = PointerTy->getClass(); // Iterate through all strict supersets of the pointee type's CVR diff --git a/test/SemaCXX/overloaded-operator.cpp b/test/SemaCXX/overloaded-operator.cpp index 7762667d1a..5fdbeebdfd 100644 --- a/test/SemaCXX/overloaded-operator.cpp +++ b/test/SemaCXX/overloaded-operator.cpp @@ -286,3 +286,13 @@ class RegAlloc { } int usepri[LastReg + 1]; }; + +// PR5546: Don't generate incorrect and ambiguous overloads for multi-level +// arrays. +namespace pr5546 +{ + enum { X }; + extern const char *const sMoveCommands[][2][2]; + const char* a() { return sMoveCommands[X][0][0]; } + const char* b() { return (*(sMoveCommands+X))[0][0]; } +} |