diff options
| author | Jordan Rose <jordan_rose@apple.com> | 2016-11-02 20:44:07 +0000 |
|---|---|---|
| committer | Jordan Rose <jordan_rose@apple.com> | 2016-11-02 20:44:07 +0000 |
| commit | ce65364afc657318d937ace660afff305817935d (patch) | |
| tree | 3a4868c58cfba616a97db6cfc7223e6050248169 /clang/lib/Sema | |
| parent | 771ef6d4f15452d76387cd66552a38122be60925 (diff) | |
| download | bcm5719-llvm-ce65364afc657318d937ace660afff305817935d.tar.gz bcm5719-llvm-ce65364afc657318d937ace660afff305817935d.zip | |
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
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaType.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index e9acd9db73d..46cc0b9ac1e 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/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; } |

