[clang] [Clang][Sema] Fix crash when MS dependent base class lookup occurs in an incomplete context (PR #83024)
Krystian Stasiowski via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 26 08:47:43 PST 2024
https://github.com/sdkrystian updated https://github.com/llvm/llvm-project/pull/83024
>From 1c57410ebef490ae96b0f087426b44ce6ae37f72 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski <sdkrystian at gmail.com>
Date: Mon, 26 Feb 2024 11:03:06 -0500
Subject: [PATCH 1/3] [Clang][Sema] Fix crash when MS dependent base class
lookup occurs in an incomplete context
---
clang/docs/ReleaseNotes.rst | 1 +
clang/lib/Sema/SemaExpr.cpp | 2 +-
.../test/SemaTemplate/ms-lookup-template-base-classes.cpp | 7 +++++++
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 9e67bbb7895040..210eb6cc586247 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -283,6 +283,7 @@ Bug Fixes to C++ Support
(`#78524 <https://github.com/llvm/llvm-project/issues/78524>`_)
- Clang no longer instantiates the exception specification of discarded candidate function
templates when determining the primary template of an explicit specialization.
+- Fixed a crash when MS unqualified dependent base class lookup occurs in an incomplete class.
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 816ee9e281359a..403839f77a2b7c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2653,7 +2653,7 @@ recoverFromMSUnqualifiedLookup(Sema &S, ASTContext &Context,
RD = ThisType->getPointeeType()->getAsCXXRecordDecl();
else if (auto *MD = dyn_cast<CXXMethodDecl>(S.CurContext))
RD = MD->getParent();
- if (!RD || !RD->hasAnyDependentBases())
+ if (!RD || !RD->hasDefinition() || !RD->hasAnyDependentBases())
return nullptr;
// Diagnose this as unqualified lookup into a dependent base class. If 'this'
diff --git a/clang/test/SemaTemplate/ms-lookup-template-base-classes.cpp b/clang/test/SemaTemplate/ms-lookup-template-base-classes.cpp
index 7856a0a16307be..534a5dc9ddc10d 100644
--- a/clang/test/SemaTemplate/ms-lookup-template-base-classes.cpp
+++ b/clang/test/SemaTemplate/ms-lookup-template-base-classes.cpp
@@ -71,6 +71,13 @@ class B : public A<T> {
template class B<int>;
+template<typename T> struct C;
+
+// Test lookup with incomplete lookup context
+template<typename T>
+auto C<T>::f() -> decltype(x) { } // expected-error {{use of undeclared identifier 'x'}}
+ // expected-error at -1 {{out-of-line definition of 'f' from class 'C<T>' without definition}}
+
}
>From f6cd58a1ac60e012a249bff11ee3ffc243bf23d1 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski <sdkrystian at gmail.com>
Date: Mon, 26 Feb 2024 11:30:29 -0500
Subject: [PATCH 2/3] [FOLD]
---
clang/docs/ReleaseNotes.rst | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 210eb6cc586247..937f5bcf652606 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -283,8 +283,10 @@ Bug Fixes to C++ Support
(`#78524 <https://github.com/llvm/llvm-project/issues/78524>`_)
- Clang no longer instantiates the exception specification of discarded candidate function
templates when determining the primary template of an explicit specialization.
-- Fixed a crash when MS unqualified dependent base class lookup occurs in an incomplete class.
+- Fixed a crash in Microsoft compatibility mode where unqualified dependent base class lookup
+ occurs in an incomplete class.
+in Microsoft compatibility mode where unqualified dependent base class lookup occurs on an incomplete class.
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
>From cbf8ce92f90933c1720391cca43e9aa49eaf1c79 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski <sdkrystian at gmail.com>
Date: Mon, 26 Feb 2024 11:46:36 -0500
Subject: [PATCH 3/3] [FOLD]
---
clang/docs/ReleaseNotes.rst | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 937f5bcf652606..515dffa28df186 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -283,10 +283,9 @@ Bug Fixes to C++ Support
(`#78524 <https://github.com/llvm/llvm-project/issues/78524>`_)
- Clang no longer instantiates the exception specification of discarded candidate function
templates when determining the primary template of an explicit specialization.
-- Fixed a crash in Microsoft compatibility mode where unqualified dependent base class lookup
- occurs in an incomplete class.
+- Fixed a crash in Microsoft compatibility mode where unqualified dependent base class
+ lookup searches the bases of an incomplete class.
-in Microsoft compatibility mode where unqualified dependent base class lookup occurs on an incomplete class.
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
More information about the cfe-commits
mailing list