Fix GH57943: Friend constraint checker didn't handle null decls.
authorErich Keane <erich.keane@intel.com>
Fri, 23 Sep 2022 19:17:12 +0000 (12:17 -0700)
committerErich Keane <erich.keane@intel.com>
Fri, 23 Sep 2022 19:21:56 +0000 (12:21 -0700)
Apparently TransformDecl in TreeTransform can be called with a nullptr
for a Decl, so my casts were illegal.  The fix here is to add an early
exit to my TransformDecl.

clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaTemplate/gh57943.cpp [new file with mode: 0644]

index 68af353..cf501ad 100644 (file)
@@ -1716,6 +1716,8 @@ public:
   }
 
   Decl *TransformDecl(SourceLocation Loc, Decl *D) {
+    if (!D)
+      return D;
     // FIXME : This is possibly an incomplete list, but it is unclear what other
     // Decl kinds could be used to refer to the template parameters.  This is a
     // best guess so far based on examples currently available, but the
diff --git a/clang/test/SemaTemplate/gh57943.cpp b/clang/test/SemaTemplate/gh57943.cpp
new file mode 100644 (file)
index 0000000..5a9f6f4
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// expected-no-diagnostics
+struct s {
+    template<typename T>
+          requires requires(T x) { x.g(); }
+      friend void f(T);
+};