[clang] [Clang] prevent assertion failure by skipping analysis of invalid field declaration (PR #99998)
Oleksandr T. via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 22 16:09:38 PDT 2024
https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/99998
Fixes #99868
>From 17f20934a971f058c8befd3a7bd850bd2c59a78c Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.tarasiuk at outlook.com>
Date: Tue, 23 Jul 2024 02:04:26 +0300
Subject: [PATCH] [Clang] prevent assertion failure by skipping analysis of
invalid field declaration
---
clang/docs/ReleaseNotes.rst | 1 +
clang/lib/AST/DeclCXX.cpp | 3 +++
.../test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp | 10 ++++++++++
3 files changed, 14 insertions(+)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9a07ad42b8f6f..bd4d65b8dd1b9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1105,6 +1105,7 @@ Bug Fixes to C++ Support
- Clang now diagnoses explicit object parameters in member pointers and other contexts where they should not appear.
Fixes (#GH85992).
- Fixed a crash-on-invalid bug involving extraneous template parameter with concept substitution. (#GH73885)
+- Fixed assertion failure by skipping the analysis of an invalid field declaration. (#GH99868)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 72d68f39a97a5..b573c2713a3aa 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -675,6 +675,9 @@ bool CXXRecordDecl::hasSubobjectAtOffsetZeroOfEmptyBaseType(
if (!IsFirstField && !FD->isZeroSize(Ctx))
continue;
+ if (FD->isInvalidDecl())
+ continue;
+
// -- If X is n array type, [visit the element type]
QualType T = Ctx.getBaseElementType(FD->getType());
if (auto *RD = T->getAsCXXRecordDecl())
diff --git a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
index 51489c5eac5ad..19793fe826372 100644
--- a/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
+++ b/clang/test/CXX/temp/temp.arg/temp.arg.template/p3-0x.cpp
@@ -38,3 +38,13 @@ X1<int, X1a> inst_x1a;
X1<long, X1b> inst_x1b;
X1<short, X1c> inst_x1c;
X1<short, X1d> inst_x1d; // expected-error{{template template argument has different template parameters than its corresponding template template paramete}}
+
+template <int> class X2; // expected-note{{template is declared here}} \
+ // expected-note{{template is declared here}}
+class X3 : X2<1> {}; // expected-error{{implicit instantiation of undefined template 'X2<1>'}}
+
+template <int> class X4 : X3 {
+ struct {
+ X2<1> e; // expected-error{{implicit instantiation of undefined template 'X2<1>'}}
+ } f;
+};
More information about the cfe-commits
mailing list