From: Jordan Rose Date: Wed, 2 Nov 2016 20:44:07 +0000 (+0000) Subject: Don't require nullability on template parameters in typedefs. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fb4b957c672e091bfe70b94054d120ca3f50adf7;p=clang Don't require nullability on template parameters in typedefs. Previously the following code would warn on the use of "T": template struct X { typedef T *type; }; ...because nullability is /allowed/ on template parameters (because they could be pointers). (Actually putting nullability on this use of 'T' will of course break if the argument is a non-pointer type.) This fix doesn't handle the case where a template parameter is used /outside/ of a typedef. That seems trickier, especially in parameter position. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285856 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index e9acd9db73..46cc0b9ac1 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -3600,7 +3600,17 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state, // inner pointers. complainAboutMissingNullability = CAMN_InnerPointers; - if (T->canHaveNullability() && !T->getNullability(S.Context)) { + auto isDependentNonPointerType = [](QualType T) -> bool { + // Note: This is intended to be the same check as Type::canHaveNullability + // except with all of the ambiguous cases being treated as 'false' rather + // than 'true'. + return T->isDependentType() && !T->isAnyPointerType() && + !T->isBlockPointerType() && !T->isMemberPointerType(); + }; + + if (T->canHaveNullability() && !T->getNullability(S.Context) && + !isDependentNonPointerType(T)) { + // Note that we allow but don't require nullability on dependent types. ++NumPointersRemaining; } diff --git a/test/SemaObjCXX/Inputs/nullability-consistency-1.h b/test/SemaObjCXX/Inputs/nullability-consistency-1.h index 6ab48fe0cd..a99f091e0f 100644 --- a/test/SemaObjCXX/Inputs/nullability-consistency-1.h +++ b/test/SemaObjCXX/Inputs/nullability-consistency-1.h @@ -13,5 +13,13 @@ class X { int X:: *memptr; // expected-warning{{member pointer is missing a nullability type specifier}} }; +template +struct Typedefs { + typedef T *Base; // no-warning + typedef Base *type; // expected-warning{{pointer is missing a nullability type specifier}} +}; + +Typedefs xx; +Typedefs yy;