[PATCH] D105478: [clang] Make CXXRecrdDecl invalid if it contains any undeduced fields.

Adam Czachorowski via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 7 05:35:11 PDT 2021


adamcz updated this revision to Diff 356925.
adamcz added a comment.

changed to marking field type as invalid


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105478

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/AST/ast-dump-undeduced-field.cpp
  clang/test/SemaCXX/cxx11-crashes.cpp


Index: clang/test/SemaCXX/cxx11-crashes.cpp
===================================================================
--- clang/test/SemaCXX/cxx11-crashes.cpp
+++ clang/test/SemaCXX/cxx11-crashes.cpp
@@ -104,3 +104,20 @@
   bool baz() { return __has_nothrow_constructor(B); }
   bool qux() { return __has_nothrow_copy(B); }
 }
+
+namespace undeduced_field {
+template<class T>
+struct Foo {
+  typedef T type;
+};
+
+struct Bar {
+  Bar();
+  // The missing expression makes A undeduced.
+  static constexpr auto A = ;  // expected-error {{expected expression}}
+  Foo<decltype(A)>::type B;  // The type of B is also undeduced (wrapped in Elaborated).
+};
+
+// This used to crash when trying to get the layout of B.
+Bar x;
+}
Index: clang/test/AST/ast-dump-undeduced-field.cpp
===================================================================
--- /dev/null
+++ clang/test/AST/ast-dump-undeduced-field.cpp
@@ -0,0 +1,15 @@
+// RUN: not %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -ast-dump %s | FileCheck %s
+
+template< class T >
+struct Foo {
+  typedef T type;
+};
+
+struct Bar {
+  Bar();
+  static constexpr auto A = ;
+  Foo<decltype(A)>::type baz;
+};
+
+// CHECK: -CXXRecordDecl {{.*}} invalid struct Bar definition
+// CHECK: -FieldDecl {{.*}} invalid baz {{.*}}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16759,6 +16759,9 @@
       TInfo = Context.getTrivialTypeSourceInfo(T, Loc);
     }
   }
+  if (const auto *U = T->getUnqualifiedDesugaredType())
+    if (U->isUndeducedType())
+      D.setInvalidType();
 
   DiagnoseFunctionSpecifiers(D.getDeclSpec());
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105478.356925.patch
Type: text/x-patch
Size: 1709 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210707/1d95f9e6/attachment-0001.bin>


More information about the cfe-commits mailing list