[PATCH] D134885: [Clang] Fix variant crashes from GH58028, GH57370

Roy Jacobson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 30 01:07:22 PDT 2022


royjacobson updated this revision to Diff 464172.
royjacobson added a comment.

Slightly modify the test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134885/new/

https://reviews.llvm.org/D134885

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/specialization-diagnose-crash.cpp


Index: clang/test/SemaCXX/specialization-diagnose-crash.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/specialization-diagnose-crash.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+// This is a reduction of GH57370 and GH58028, originally appearing
+// in libstdc++'s variant code.
+
+struct V1 {};
+struct V2 : V1 {
+  int &a;
+};
+
+template <class T> using void_t = void;
+
+template <class T> struct X { T x; };
+
+template <class T1, class T2, class = void> struct Variant {
+  Variant() = delete; // expected-note {{deleted here}}
+};
+
+template <class T1, class T2>
+struct Variant<T1, T2, void_t<decltype(X<T2>{T1()})>> {};
+
+void f() {
+  Variant<V1, V1>();
+  Variant<V1, V2>(); // expected-error {{call to deleted constructor}}
+}
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -695,10 +695,10 @@
         //   member of reference type uninitialized, the program is
         //   ill-formed.
         SemaRef.Diag(Loc, diag::err_init_reference_member_uninitialized)
-          << Field->getType()
-          << ILE->getSyntacticForm()->getSourceRange();
-        SemaRef.Diag(Field->getLocation(),
-                     diag::note_uninit_reference_member);
+            << Field->getType()
+            << (ILE->isSyntacticForm() ? ILE : ILE->getSyntacticForm())
+                   ->getSourceRange();
+        SemaRef.Diag(Field->getLocation(), diag::note_uninit_reference_member);
       }
       hadError = true;
       return;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134885.464172.patch
Type: text/x-patch
Size: 1649 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220930/12ea8ab0/attachment.bin>


More information about the cfe-commits mailing list