r197609 - Allow Objective-C pointer conversions following an explicit user conversion.
Douglas Gregor
dgregor at apple.com
Wed Dec 18 13:46:16 PST 2013
Author: dgregor
Date: Wed Dec 18 15:46:16 2013
New Revision: 197609
URL: http://llvm.org/viewvc/llvm-project?rev=197609&view=rev
Log:
Allow Objective-C pointer conversions following an explicit user conversion.
Finishes the work started in r194224, and fixes <rdar://problem/15494681>.
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/SemaObjCXX/contextual-convert-to-id.mm
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=197609&r1=197608&r2=197609&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Dec 18 15:46:16 2013
@@ -2162,13 +2162,13 @@ public:
CXXRecordDecl *ActingContext,
Expr *From, QualType ToType,
OverloadCandidateSet& CandidateSet,
- bool AllowObjCConversionOnExplicit = false);
+ bool AllowObjCConversionOnExplicit);
void AddTemplateConversionCandidate(FunctionTemplateDecl *FunctionTemplate,
DeclAccessPair FoundDecl,
CXXRecordDecl *ActingContext,
Expr *From, QualType ToType,
OverloadCandidateSet &CandidateSet,
- bool AllowObjCConversionOnExplicit = false);
+ bool AllowObjCConversionOnExplicit);
void AddSurrogateCandidate(CXXConversionDecl *Conversion,
DeclAccessPair FoundDecl,
CXXRecordDecl *ActingContext,
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=197609&r1=197608&r2=197609&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Dec 18 15:46:16 2013
@@ -3522,10 +3522,13 @@ static OverloadingResult TryRefInitWithC
if (ConvTemplate)
S.AddTemplateConversionCandidate(ConvTemplate, I.getPair(),
ActingDC, Initializer,
- DestType, CandidateSet);
+ DestType, CandidateSet,
+ /*AllowObjCConversionOnExplicit=*/
+ false);
else
S.AddConversionCandidate(Conv, I.getPair(), ActingDC,
- Initializer, DestType, CandidateSet);
+ Initializer, DestType, CandidateSet,
+ /*AllowObjCConversionOnExplicit=*/false);
}
}
}
@@ -4145,10 +4148,11 @@ static void TryUserDefinedConversion(Sem
if (ConvTemplate)
S.AddTemplateConversionCandidate(ConvTemplate, I.getPair(),
ActingDC, Initializer, DestType,
- CandidateSet);
+ CandidateSet, AllowExplicit);
else
S.AddConversionCandidate(Conv, I.getPair(), ActingDC,
- Initializer, DestType, CandidateSet);
+ Initializer, DestType, CandidateSet,
+ AllowExplicit);
}
}
}
Modified: cfe/trunk/test/SemaObjCXX/contextual-convert-to-id.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/contextual-convert-to-id.mm?rev=197609&r1=197608&r2=197609&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/contextual-convert-to-id.mm (original)
+++ cfe/trunk/test/SemaObjCXX/contextual-convert-to-id.mm Wed Dec 18 15:46:16 2013
@@ -8,6 +8,10 @@
- unknownMethod;
@end
+ at interface C : A
+- knownMethod;
+ at end
+
template<typename T> struct RetainPtr {
explicit operator T*() const;
};
@@ -17,6 +21,16 @@ void methodCallToSpecific(RetainPtr<A> a
[a unknownMethod]; // expected-warning{{'A' may not respond to 'unknownMethod'}}
}
+void explicitCast(RetainPtr<A> a, RetainPtr<B> b, RetainPtr<C> c) {
+ (void)(A*)a;
+ (void)(A*)b; // expected-error{{cannot convert 'RetainPtr<B>' to 'A *' without a conversion operator}}
+ (void)(A*)c;
+ (void)(C*)a;
+ (void)static_cast<A*>(a);
+ (void)static_cast<A*>(b); // expected-error{{cannot convert 'RetainPtr<B>' to 'A *' without a conversion operator}}
+ (void)static_cast<A*>(c);
+}
+
struct Incomplete; // expected-note{{forward declaration}}
void methodCallToIncomplete(Incomplete &incomplete) {
@@ -31,3 +45,8 @@ void methodCallToId(IdPtr a) {
[a knownMethod];
[a unknownMethod];
}
+
+void explicitCast(IdPtr a) {
+ (void)(A*)a;
+ (void)static_cast<A*>(a);
+}
More information about the cfe-commits
mailing list