[clang] [Clang] Avoid a crash when parsing an invalid pseudo-destructor (PR #111666)

via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 9 05:11:35 PDT 2024


https://github.com/cor3ntin created https://github.com/llvm/llvm-project/pull/111666

Fixes #11460.

>From 769db7b7a40060fac77ff07e61f161eeedd2ec02 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Wed, 9 Oct 2024 14:10:12 +0200
Subject: [PATCH] [Clang] Avoid a crash when parsing an invalid
 pseudo-destructor

Fixes #11460.
---
 clang/docs/ReleaseNotes.rst               |  1 +
 clang/lib/Sema/SemaExprCXX.cpp            |  3 ++-
 clang/test/Parser/cxx2c-pack-indexing.cpp | 11 +++++++++++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 583c1e6b4215c5..fdf197f802ed33 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -481,6 +481,7 @@ Bug Fixes to C++ Support
 - Clang now uses the correct set of template argument lists when comparing the constraints of
   out-of-line definitions and member templates explicitly specialized for a given implicit instantiation of
   a class template. (#GH102320)
+- Fix a crash when parsing a pseudo destructor involving an invalid type. (#GH11460)
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d490452e91c3bb..8e9bcb10a80b46 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -8429,7 +8429,8 @@ ExprResult Sema::ActOnPseudoDestructorExpr(Scope *S, Expr *Base,
   QualType ObjectType;
   QualType T;
   TypeLocBuilder TLB;
-  if (CheckArrow(*this, ObjectType, Base, OpKind, OpLoc))
+  if (CheckArrow(*this, ObjectType, Base, OpKind, OpLoc) ||
+      DS.getTypeSpecType() == DeclSpec::TST_error)
     return ExprError();
 
   switch (DS.getTypeSpecType()) {
diff --git a/clang/test/Parser/cxx2c-pack-indexing.cpp b/clang/test/Parser/cxx2c-pack-indexing.cpp
index 1b84ddfc6c20a5..c279bdd7af8c44 100644
--- a/clang/test/Parser/cxx2c-pack-indexing.cpp
+++ b/clang/test/Parser/cxx2c-pack-indexing.cpp
@@ -63,3 +63,14 @@ struct base {
 int main() {
     SS<int, base>().f(0);
 }
+
+
+namespace GH11460 {
+template <typename... T>
+requires( ); // expected-error {{expected expression}}
+struct SS {
+    void f( ) {
+        (*p).~T...[](); // expected-error {{use of undeclared identifier 'p'}}
+    }
+};
+}



More information about the cfe-commits mailing list