forked from OSchip/llvm-project
Don't require nullability on template parameters in typedefs.
Previously the following code would warn on the use of "T": template <typename T> 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. llvm-svn: 285856
This commit is contained in:
parent
771ef6d4f1
commit
ce65364afc
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,5 +13,13 @@ class X {
|
|||
int X:: *memptr; // expected-warning{{member pointer is missing a nullability type specifier}}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct Typedefs {
|
||||
typedef T *Base; // no-warning
|
||||
typedef Base *type; // expected-warning{{pointer is missing a nullability type specifier}}
|
||||
};
|
||||
|
||||
Typedefs<int> xx;
|
||||
Typedefs<void *> yy;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue