summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaOverload.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2016-10-21 22:00:42 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2016-10-21 22:00:42 +0000
commit5e9746f520e6bbeafc36b8a23585b2e6117e1a7a (patch)
tree19d45b99d8cfaddc7598d6986cdd522463951cad /clang/lib/Sema/SemaOverload.cpp
parent00c03c5de7fd930da8fe1f9561037c4bc3987685 (diff)
downloadbcm5719-llvm-5e9746f520e6bbeafc36b8a23585b2e6117e1a7a.tar.gz
bcm5719-llvm-5e9746f520e6bbeafc36b8a23585b2e6117e1a7a.zip
DR583, DR1512: Implement a rewrite to C++'s 'composite pointer type' rules.
This has two significant effects: 1) Direct relational comparisons between null pointer constants (0 and nullopt) and pointers are now ill-formed. This was always the case for C, and it appears that C++ only ever permitted by accident. For instance, cases like nullptr < &a are now rejected. 2) Comparisons and conditional operators between differently-cv-qualified pointer types now work, and produce a composite type that both source pointer types can convert to (when possible). For instance, comparison between 'int **' and 'const int **' is now valid, and uses an intermediate type of 'const int *const *'. Clang previously supported #2 as an extension. We do not accept the cases in #1 as an extension. I've tested a fair amount of code to check that this doesn't break it, but if it turns out that someone is relying on this, we can easily add it back as an extension. This is a re-commit of r284800. llvm-svn: 284890
Diffstat (limited to 'clang/lib/Sema/SemaOverload.cpp')
-rw-r--r--clang/lib/Sema/SemaOverload.cpp32
1 files changed, 15 insertions, 17 deletions
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 8cc592e21e5..8d6c562dd0c 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -7624,12 +7624,12 @@ public:
}
// C++ [over.match.oper]p16:
- // For every pointer to member type T, there exist candidate operator
- // functions of the form
+ // For every pointer to member type T or type std::nullptr_t, there
+ // exist candidate operator functions of the form
//
// bool operator==(T,T);
// bool operator!=(T,T);
- void addEqualEqualOrNotEqualMemberPointerOverloads() {
+ void addEqualEqualOrNotEqualMemberPointerOrNullptrOverloads() {
/// Set of (canonical) types that we've already handled.
llvm::SmallPtrSet<QualType, 8> AddedTypes;
@@ -7646,13 +7646,22 @@ public:
QualType ParamTypes[2] = { *MemPtr, *MemPtr };
S.AddBuiltinCandidate(S.Context.BoolTy, ParamTypes, Args, CandidateSet);
}
+
+ if (CandidateTypes[ArgIdx].hasNullPtrType()) {
+ CanQualType NullPtrTy = S.Context.getCanonicalType(S.Context.NullPtrTy);
+ if (AddedTypes.insert(NullPtrTy).second) {
+ QualType ParamTypes[2] = { NullPtrTy, NullPtrTy };
+ S.AddBuiltinCandidate(S.Context.BoolTy, ParamTypes, Args,
+ CandidateSet);
+ }
+ }
}
}
// C++ [over.built]p15:
//
- // For every T, where T is an enumeration type, a pointer type, or
- // std::nullptr_t, there exist candidate operator functions of the form
+ // For every T, where T is an enumeration type or a pointer type,
+ // there exist candidate operator functions of the form
//
// bool operator<(T, T);
// bool operator>(T, T);
@@ -7737,17 +7746,6 @@ public:
QualType ParamTypes[2] = { *Enum, *Enum };
S.AddBuiltinCandidate(S.Context.BoolTy, ParamTypes, Args, CandidateSet);
}
-
- if (CandidateTypes[ArgIdx].hasNullPtrType()) {
- CanQualType NullPtrTy = S.Context.getCanonicalType(S.Context.NullPtrTy);
- if (AddedTypes.insert(NullPtrTy).second &&
- !UserDefinedBinaryOperators.count(std::make_pair(NullPtrTy,
- NullPtrTy))) {
- QualType ParamTypes[2] = { NullPtrTy, NullPtrTy };
- S.AddBuiltinCandidate(S.Context.BoolTy, ParamTypes, Args,
- CandidateSet);
- }
- }
}
}
@@ -8443,7 +8441,7 @@ void Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
case OO_EqualEqual:
case OO_ExclaimEqual:
- OpBuilder.addEqualEqualOrNotEqualMemberPointerOverloads();
+ OpBuilder.addEqualEqualOrNotEqualMemberPointerOrNullptrOverloads();
// Fall through.
case OO_Less:
OpenPOWER on IntegriCloud