PR44992 Don't crash when a defaulted <=> is in a class declared in a
authorRichard Smith <richard@metafoo.co.uk>
Sat, 14 Mar 2020 02:29:44 +0000 (19:29 -0700)
committerRichard Smith <richard@metafoo.co.uk>
Sat, 14 Mar 2020 02:30:49 +0000 (19:30 -0700)
transparent context.

(The same crash would happen if a class template with a friend was
declared in an 'export' block, but there are more issues with that
case.)

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaCXX/compare-cxx2a.cpp

index 109b649..875eb2b 100755 (executable)
@@ -2039,7 +2039,7 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
     // Look only into the namespace where the friend would be declared to
     // find a previous declaration. This is the innermost enclosing namespace,
     // as described in ActOnFriendFunctionDecl.
-    SemaRef.LookupQualifiedName(Previous, DC);
+    SemaRef.LookupQualifiedName(Previous, DC->getRedeclContext());
 
     // In C++, the previous declaration we find might be a tag type
     // (class or enum). In this case, the new declaration will hide the
index 46e38f7..a459554 100644 (file)
@@ -426,3 +426,9 @@ namespace Vector {
     (void)(v1 <=> v2); // expected-error {{three-way comparison between vectors is not supported}}
   }
 }
+
+namespace PR44992 {
+  extern "C++" struct s {
+    friend auto operator<=>(s const &, s const &) = default;
+  };
+}