<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 2, 2016, at 14:31, Richard Smith <<a href="mailto:richard@metafoo.co.uk" class="">richard@metafoo.co.uk</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="auto" class=""><div class=""><div class="gmail_extra"><div class="gmail_quote">On 2 Nov 2016 1:53 pm, "Jordan Rose via cfe-commits" <<a href="mailto:cfe-commits@lists.llvm.org" class="">cfe-commits@lists.llvm.org</a>> wrote:<br type="attribution" class=""><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: jrose<br class="">
Date: Wed Nov 2 15:44:07 2016<br class="">
New Revision: 285856<br class="">
<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=285856&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project?rev=285856&view=rev</a><br class="">
Log:<br class="">
Don't require nullability on template parameters in typedefs.<br class="">
<br class="">
Previously the following code would warn on the use of "T":<br class="">
<br class="">
template <typename T><br class="">
struct X {<br class="">
typedef T *type;<br class="">
};<br class="">
<br class="">
...because nullability is /allowed/ on template parameters (because<br class="">
they could be pointers). (Actually putting nullability on this use of<br class="">
'T' will of course break if the argument is a non-pointer type.)<br class=""></blockquote></div></div></div><div class=""><br class=""></div><div class="">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*?</div></div></div></blockquote><div><br class=""></div><div>Sorry, this is referring to the following change to the example:</div><div><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><div>template <typename T></div></div><div><div>struct X {</div></div><div><div> typedef T _Nullable *type;</div></div><div><div>};</div></div></blockquote><div><div><br class=""></div><div>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).</div><div><br class=""></div><div>Jordan</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div class=""><br class=""></div><div class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This fix doesn't handle the case where a template parameter is used<br class="">
/outside/ of a typedef. That seems trickier, especially in parameter<br class="">
position.<br class="">
<br class="">
Modified:<br class="">
cfe/trunk/lib/Sema/SemaType.<wbr class="">cpp<br class="">
cfe/trunk/test/SemaObjCXX/<wbr class="">Inputs/nullability-<wbr class="">consistency-1.h<br class="">
<br class="">
Modified: cfe/trunk/lib/Sema/SemaType.<wbr class="">cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=285856&r1=285855&r2=285856&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/cfe/trunk/lib/Sema/<wbr class="">SemaType.cpp?rev=285856&r1=<wbr class="">285855&r2=285856&view=diff</a><br class="">
==============================<wbr class="">==============================<wbr class="">==================<br class="">
--- cfe/trunk/lib/Sema/SemaType.<wbr class="">cpp (original)<br class="">
+++ cfe/trunk/lib/Sema/SemaType.<wbr class="">cpp Wed Nov 2 15:44:07 2016<br class="">
@@ -3600,7 +3600,17 @@ static TypeSourceInfo *GetFullTypeForDec<br class="">
// inner pointers.<br class="">
complainAboutMissingNullabilit<wbr class="">y = CAMN_InnerPointers;<br class="">
<br class="">
- if (T->canHaveNullability() && !T->getNullability(S.Context)) {<br class="">
+ auto isDependentNonPointerType = [](QualType T) -> bool {<br class="">
+ // Note: This is intended to be the same check as Type::canHaveNullability<br class="">
+ // except with all of the ambiguous cases being treated as 'false' rather<br class="">
+ // than 'true'.<br class="">
+ return T->isDependentType() && !T->isAnyPointerType() &&<br class="">
+ !T->isBlockPointerType() && !T->isMemberPointerType();<br class="">
+ };<br class="">
+<br class="">
+ if (T->canHaveNullability() && !T->getNullability(S.Context) &&<br class="">
+ !isDependentNonPointerType(T)) {<br class="">
+ // Note that we allow but don't require nullability on dependent types.<br class="">
++NumPointersRemaining;<br class="">
}<br class="">
<br class="">
<br class="">
Modified: cfe/trunk/test/SemaObjCXX/<wbr class="">Inputs/nullability-<wbr class="">consistency-1.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-1.h?rev=285856&r1=285855&r2=285856&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-<wbr class="">project/cfe/trunk/test/<wbr class="">SemaObjCXX/Inputs/nullability-<wbr class="">consistency-1.h?rev=285856&r1=<wbr class="">285855&r2=285856&view=diff</a><br class="">
==============================<wbr class="">==============================<wbr class="">==================<br class="">
--- cfe/trunk/test/SemaObjCXX/<wbr class="">Inputs/nullability-<wbr class="">consistency-1.h (original)<br class="">
+++ cfe/trunk/test/SemaObjCXX/<wbr class="">Inputs/nullability-<wbr class="">consistency-1.h Wed Nov 2 15:44:07 2016<br class="">
@@ -13,5 +13,13 @@ class X {<br class="">
int X:: *memptr; // expected-warning{{member pointer is missing a nullability type specifier}}<br class="">
};<br class="">
<br class="">
+template <typename T><br class="">
+struct Typedefs {<br class="">
+ typedef T *Base; // no-warning<br class="">
+ typedef Base *type; // expected-warning{{pointer is missing a nullability type specifier}}<br class="">
+};<br class="">
+<br class="">
+Typedefs<int> xx;<br class="">
+Typedefs<void *> yy;<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
______________________________<wbr class="">_________________<br class="">
cfe-commits mailing list<br class="">
<a href="mailto:cfe-commits@lists.llvm.org" class="">cfe-commits@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/cfe-commits</a><br class="">
</blockquote></div><br class=""></div></div></div>
</div></blockquote></div><br class=""></body></html>