[clang] [Clang][Sema] Fix crash with const qualified member operator new (PR #80327)
Shafik Yaghmour via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 1 13:25:28 PST 2024
https://github.com/shafik updated https://github.com/llvm/llvm-project/pull/80327
>From afcf464812bdb0a167023e7930b0be2ed29a3b3e Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour <shafik.yaghmour at intel.com>
Date: Thu, 1 Feb 2024 11:19:14 -0800
Subject: [PATCH] [Clang][Sema] Fix crash with const qualified member operator
new
We should diagnose a const qualified member operator new but we fail to do so
and this leads to crash during debug info generation.
The fix is to diagnose this as ill-formed in the front-end.
Fixes: https://github.com/llvm/llvm-project/issues/79748
---
clang/lib/Sema/SemaType.cpp | 6 ++++--
clang/test/SemaCXX/function-type-qual.cpp | 7 +++++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 7cee73d5d6bae..2d9e3b2f73909 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5914,8 +5914,10 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
//
// ... for instance.
if (IsQualifiedFunction &&
- !(Kind == Member && !D.isExplicitObjectMemberFunction() &&
- D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static) &&
+ (Kind != Member || D.isExplicitObjectMemberFunction() ||
+ D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
+ (D.getContext() == clang::DeclaratorContext::Member &&
+ D.isStaticMember())) &&
!IsTypedefName && D.getContext() != DeclaratorContext::TemplateArg &&
D.getContext() != DeclaratorContext::TemplateTypeArg) {
SourceLocation Loc = D.getBeginLoc();
diff --git a/clang/test/SemaCXX/function-type-qual.cpp b/clang/test/SemaCXX/function-type-qual.cpp
index bb25c17e83bdf..79f00edcdea47 100644
--- a/clang/test/SemaCXX/function-type-qual.cpp
+++ b/clang/test/SemaCXX/function-type-qual.cpp
@@ -37,3 +37,10 @@ void instantiateArrayDecay() {
int a[1];
arrayDecay(a);
}
+
+namespace GH79748 {
+typedef decltype(sizeof(0)) size_t;
+struct A {
+ void* operator new(size_t bytes) const; //expected-error {{static member function cannot have 'const' qualifier}}
+};
+}
More information about the cfe-commits
mailing list