[PATCH] D50088: [Sema] Dig through AutoTypes that have been deduced to an undeduced AutoType in Type::isUndeducedType

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 31 10:56:33 PDT 2018


erik.pilkington created this revision.
erik.pilkington added a reviewer: rsmith.
Herald added a subscriber: dexonsmith.

Clang used to error out on the attached test case because we deduced an auto type to an undeduced auto type in the template-id G<V>. This caused Sema::CheckNonTypeTemplateParameterType to error out because isUndeducedType() returned false. It seems like we want to retain this type sugar, so this patch teaches isUndeducedType to dig through any deduced-to-undeduced types.

rdar://41852459

Thanks for taking a look!
Erik


Repository:
  rC Clang

https://reviews.llvm.org/D50088

Files:
  clang/include/clang/AST/Type.h
  clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp


Index: clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
===================================================================
--- clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -335,3 +335,13 @@
   void g(int, int);
   using Int = A<int>::B<&g>::param2;
 }
+
+namespace rdar41852459 {
+template <auto V> struct G {};
+
+template <class T> struct S {
+  template <auto V> void f() {
+    G<V> x;
+  }
+};
+}
Index: clang/include/clang/AST/Type.h
===================================================================
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -6456,8 +6456,15 @@
 }
 
 inline bool Type::isUndeducedType() const {
-  auto *DT = getContainedDeducedType();
-  return DT && !DT->isDeduced();
+  QualType Ty(this, 0);
+  while (auto *DT = Ty->getContainedDeducedType()) {
+    if (!DT->isDeduced())
+      return true;
+    Ty = DT->getDeducedType();
+    if (Ty.isNull())
+      return false;
+  }
+  return false;
 }
 
 /// Determines whether this is a type for which one can define


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50088.158318.patch
Type: text/x-patch
Size: 1085 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180731/200aac85/attachment.bin>


More information about the cfe-commits mailing list