r285856 - Don't require nullability on template parameters in typedefs.
Jordan Rose via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 2 14:34:50 PDT 2016
> On Nov 2, 2016, at 14:31, Richard Smith <richard at metafoo.co.uk> wrote:
>
> On 2 Nov 2016 1:53 pm, "Jordan Rose via cfe-commits" <cfe-commits at lists.llvm.org <mailto:cfe-commits at lists.llvm.org>> wrote:
> Author: jrose
> Date: Wed Nov 2 15:44:07 2016
> New Revision: 285856
>
> URL: http://llvm.org/viewvc/llvm-project?rev=285856&view=rev <http://llvm.org/viewvc/llvm-project?rev=285856&view=rev>
> Log:
> 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 doesn't make any sense to me. Why would T need to be a pointer type for a nullability qualifier to be valid on a T*?
Sorry, this is referring to the following change to the example:
template <typename T>
struct X {
typedef T _Nullable *type;
};
This is legal, but of course `X<int>` then produces an error. So we want to accept nullability in this position (in case T is implicitly required to be a pointer type by the definition of X) but not warn when it’s missing (in case it isn’t).
Jordan
>
> This fix doesn't handle the case where a template parameter is used
> /outside/ of a typedef. That seems trickier, especially in parameter
> position.
>
> Modified:
> cfe/trunk/lib/Sema/SemaType.cpp
> cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h
>
> Modified: cfe/trunk/lib/Sema/SemaType.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=285856&r1=285855&r2=285856&view=diff <http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=285856&r1=285855&r2=285856&view=diff>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaType.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaType.cpp Wed Nov 2 15:44:07 2016
> @@ -3600,7 +3600,17 @@ static TypeSourceInfo *GetFullTypeForDec
> // 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;
> }
>
>
> Modified: cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h?rev=285856&r1=285855&r2=285856&view=diff <http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h?rev=285856&r1=285855&r2=285856&view=diff>
> ==============================================================================
> --- cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h (original)
> +++ cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h Wed Nov 2 15:44:07 2016
> @@ -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;
>
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org <mailto:cfe-commits at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161102/d142a02e/attachment-0001.html>
More information about the cfe-commits
mailing list