[clang] [Clang][Sema] Fix crash with const qualified member operator new (PR #80327)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 1 11:25:24 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Shafik Yaghmour (shafik)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/80327.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaType.cpp (+4-2)
- (modified) clang/test/SemaCXX/function-type-qual.cpp (+6)
``````````diff
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..fc9fc20c14248 100644
--- a/clang/test/SemaCXX/function-type-qual.cpp
+++ b/clang/test/SemaCXX/function-type-qual.cpp
@@ -37,3 +37,9 @@ void instantiateArrayDecay() {
int a[1];
arrayDecay(a);
}
+
+namespace GH79748 {
+struct A {
+ void* operator new(unsigned long bytes) const; //expected-error {{static member function cannot have 'const' qualifier}}
+};
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/80327
More information about the cfe-commits
mailing list