jordan_rose created this revision.
jordan_rose added reviewers: doug.gregor, rsmith.
jordan_rose added a subscriber: cfe-commits.
jordan_rose set the repository for this revision to rL LLVM.

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.


Repository:
  rL LLVM

https://reviews.llvm.org/D26226

Files:
  lib/Sema/SemaType.cpp
  test/SemaObjCXX/Inputs/nullability-consistency-1.h


Index: test/SemaObjCXX/Inputs/nullability-consistency-1.h
===================================================================
--- test/SemaObjCXX/Inputs/nullability-consistency-1.h
+++ test/SemaObjCXX/Inputs/nullability-consistency-1.h
@@ -13,5 +13,13 @@
   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;
 
 
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -3662,7 +3662,15 @@
     // inner pointers.
     complainAboutMissingNullability = CAMN_InnerPointers;
 
-    if (T->canHaveNullability() && !T->getNullability(S.Context)) {
+    auto isDependentNonPointerType = [](QualType T) -> bool {
+      // FIXME: This just duplicates logic inside Type::canHaveNullability.
+      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;
     }
 


Index: test/SemaObjCXX/Inputs/nullability-consistency-1.h
===================================================================
--- test/SemaObjCXX/Inputs/nullability-consistency-1.h
+++ test/SemaObjCXX/Inputs/nullability-consistency-1.h
@@ -13,5 +13,13 @@
   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;
 
 
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -3662,7 +3662,15 @@
     // inner pointers.
     complainAboutMissingNullability = CAMN_InnerPointers;
 
-    if (T->canHaveNullability() && !T->getNullability(S.Context)) {
+    auto isDependentNonPointerType = [](QualType T) -> bool {
+      // FIXME: This just duplicates logic inside Type::canHaveNullability.
+      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;
     }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to