From: Fariborz Jahanian Date: Wed, 20 Jul 2011 17:14:09 +0000 (+0000) Subject: arc-objc++: Issue an arc specific diagnostic when overload resolution X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=909bcb37c4bc1ea1a62d505881defc3c3ba0eca3;p=clang arc-objc++: Issue an arc specific diagnostic when overload resolution fails because of lifetime differences of parameter and argument type. // rdar://9790531 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135593 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index ad022c23e6..dad311ceb4 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1595,6 +1595,17 @@ def note_ovl_candidate_bad_conv : Note<"candidate " "%select{%ordinal5 argument|object argument}4; " "%select{|dereference the argument with *|" "take the address of the argument with &}6">; +def note_ovl_candidate_bad_arc_conv : Note<"candidate " + "%select{function|function|constructor|" + "function |function |constructor |" + "constructor (the implicit default constructor)|" + "constructor (the implicit copy constructor)|" + "constructor (the implicit move constructor)|" + "function (the implicit copy assignment operator)|" + "function (the implicit move assignment operator)|" + "constructor (inherited)}0%1" + " not viable: cannot implicitly convert argument of type %2 to %3 for " + "%select{%ordinal5 argument|object argument}4 under ARC">; def note_ovl_candidate_bad_addrspace : Note<"candidate " "%select{function|function|constructor|" "function |function |constructor |" diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 5ed950e5c5..2f8bdc768f 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -6981,8 +6981,21 @@ void DiagnoseBadConversion(Sema &S, OverloadCandidate *Cand, unsigned I) { return; } + if (isa(CFromTy) && + isa(CToTy)) { + Qualifiers FromQs = CFromTy.getQualifiers(); + Qualifiers ToQs = CToTy.getQualifiers(); + if (FromQs.getObjCLifetime() != ToQs.getObjCLifetime()) { + S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_arc_conv) + << (unsigned) FnKind << FnDesc + << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) + << FromTy << ToTy << (unsigned) isObjectArgument << I+1; + MaybeEmitInheritedConstructorNote(S, Fn); + return; + } + } + // TODO: specialize more based on the kind of mismatch - // Emit the generic diagnostic and, optionally, add the hints to it. PartialDiagnostic FDiag = S.PDiag(diag::note_ovl_candidate_bad_conv); FDiag << (unsigned) FnKind << FnDesc diff --git a/test/SemaObjCXX/arc-overloading.mm b/test/SemaObjCXX/arc-overloading.mm index 06b332cec8..ae63aaceeb 100644 --- a/test/SemaObjCXX/arc-overloading.mm +++ b/test/SemaObjCXX/arc-overloading.mm @@ -173,3 +173,22 @@ void test_f9() { const __autoreleasing id& ar3 = unsafe_unretained_a; const __autoreleasing id& ar4 = weak_a; } + +// rdar://9790531 +void f9790531(void *inClientData); // expected-note {{candidate function not viable: cannot implicitly convert argument of type 'MixerEQGraphTestDelegate *const __strong' to 'void *' for 1st argument under ARC}} +void f9790531_1(struct S*inClientData); // expected-note {{candidate function not viable}} +void f9790531_2(char * inClientData); // expected-note {{candidate function not viable}} + +@class UIApplication; + +@interface MixerEQGraphTestDelegate +- (void)applicationDidFinishLaunching; +@end + +@implementation MixerEQGraphTestDelegate +- (void)applicationDidFinishLaunching { + f9790531(self); // expected-error {{no matching function for call to 'f9790531'}} + f9790531_1(self); // expected-error {{no matching function for call to 'f9790531_1'}} + f9790531_2(self); // expected-error {{no matching function for call to 'f9790531_2'}} +} +@end