[PATCH] D113145: Remove two sema checkings as assertions introduced by D79719.

Yuanfang Chen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 3 14:32:08 PDT 2021


ychen created this revision.
ychen added reviewers: hubert.reinterpretcast, Xiangling_L.
ychen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Sema layer should handle these already. Otherwise checking build of the
compiler would crash for these invalid constructs.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113145

Files:
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/test/SemaCXX/virtual-function-in-union.cpp


Index: clang/test/SemaCXX/virtual-function-in-union.cpp
===================================================================
--- clang/test/SemaCXX/virtual-function-in-union.cpp
+++ clang/test/SemaCXX/virtual-function-in-union.cpp
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
-union x {
-  virtual void f(); // expected-error {{unions cannot have virtual functions}}
+union U {
+  int d;
+  virtual int f() { return d; }; // expected-error {{unions cannot have virtual functions}}
 };
+
+int foo() { U u; return u.d; }
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===================================================================
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1066,7 +1066,6 @@
     EnsureVTablePointerAlignment(PtrAlign);
     HasOwnVFPtr = true;
 
-    assert(!IsUnion && "Unions cannot be dynamic classes.");
     HandledFirstNonOverlappingEmptyField = true;
 
     setSize(getSize() + PtrWidth);
@@ -1204,8 +1203,6 @@
 
 CharUnits
 ItaniumRecordLayoutBuilder::LayoutBase(const BaseSubobjectInfo *Base) {
-  assert(!IsUnion && "Unions cannot have base classes.");
-
   const ASTRecordLayout &Layout = Context.getASTRecordLayout(Base->Class);
   CharUnits Offset;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113145.384586.patch
Type: text/x-patch
Size: 1245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211103/25d4ced4/attachment.bin>


More information about the cfe-commits mailing list