diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index b15ad0ddd156..bdf95fa5828b 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -4033,7 +4033,7 @@ void Sema::DelayedDiagnostics::popParsingDecl(Sema &S, ParsingDeclState state, // We only want to actually emit delayed diagnostics when we // successfully parsed a decl. - if (decl && !decl->isInvalidDecl()) { + if (decl) { // We emit all the active diagnostics, not just those starting // from the saved state. The idea is this: we get one push for a // decl spec and another for each declarator; in a decl group like: @@ -4048,7 +4048,9 @@ void Sema::DelayedDiagnostics::popParsingDecl(Sema &S, ParsingDeclState state, switch (diag.Kind) { case DelayedDiagnostic::Deprecation: - S.HandleDelayedDeprecationCheck(diag, decl); + // Don't bother giving deprecation diagnostics if the decl is invalid. + if (!decl->isInvalidDecl()) + S.HandleDelayedDeprecationCheck(diag, decl); break; case DelayedDiagnostic::Access: diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index e7b899278f55..866cd225dbb9 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1062,7 +1062,9 @@ static QualType inferARCLifetimeForPointee(Sema &S, QualType type, } else if (S.ExprEvalContexts.back().Context == Sema::Unevaluated) { return type; - // If that failed, give an error and recover using __autoreleasing. + // If that failed, give an error and recover using __strong. __strong + // is the option most likely to prevent spurious second-order diagnostics, + // like when binding a reference to a field. } else { // These types can show up in private ivars in system headers, so // we need this to not be an error in those cases. Instead we @@ -1074,7 +1076,7 @@ static QualType inferARCLifetimeForPointee(Sema &S, QualType type, } else { S.Diag(loc, diag::err_arc_indirect_no_ownership) << type << isReference; } - implicitLifetime = Qualifiers::OCL_Autoreleasing; + implicitLifetime = Qualifiers::OCL_Strong; } assert(implicitLifetime && "didn't infer any lifetime!"); diff --git a/clang/test/SemaObjC/arc-decls.m b/clang/test/SemaObjC/arc-decls.m index 4b7eb8fb54d0..314e532a4768 100644 --- a/clang/test/SemaObjC/arc-decls.m +++ b/clang/test/SemaObjC/arc-decls.m @@ -86,3 +86,14 @@ void func() - (id)not_ret:(id) b __attribute((ns_returns_retained)); // expected-error {{overriding method has mismatched ns_returns_retained attributes}} - (id)both__returns_not_retained:(id) b __attribute((ns_returns_not_retained)); @end + +// Test that we give a good diagnostic here that mentions the missing +// ownership qualifier. We don't want this to get suppressed because +// of an invalid conversion. +void test7(void) { + id x; + id *px = &x; // expected-error {{pointer to non-const type 'id' with no explicit ownership}} + + I *y; + J **py = &y; // expected-error {{pointer to non-const type 'J *' with no explicit ownership}} expected-warning {{incompatible pointer types initializing}} +}