Skip to content

[Clang][Sema] Fix crash with const qualified member operator new #80327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ Bug Fixes to C++ Support
and (`#79745 <https://github.com/llvm/llvm-project/issues/79745>`_)
- Fix incorrect code generation caused by the object argument of ``static operator()`` and ``static operator[]`` calls not being evaluated.
Fixes (`#67976 <https://github.com/llvm/llvm-project/issues/67976>`_)
- Fix crash and diagnostic with const qualified member operator new.
Fixes (`#79748 <https://github.com/llvm/llvm-project/issues/79748>`_)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
13 changes: 11 additions & 2 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5907,15 +5907,24 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
// - the type-id in the default argument of a type-parameter, or
// - the type-id of a template-argument for a type-parameter
//
// C++23 [dcl.fct]p6 (P0847R7)
// ... A member-declarator with an explicit-object-parameter-declaration
// shall not include a ref-qualifier or a cv-qualifier-seq and shall not be
// declared static or virtual ...
//
// FIXME: Checking this here is insufficient. We accept-invalid on:
//
// template<typename T> struct S { void f(T); };
// S<int() const> s;
//
// ... for instance.
if (IsQualifiedFunction &&
!(Kind == Member && !D.isExplicitObjectMemberFunction() &&
D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static) &&
// Check for non-static member function and not and
// explicit-object-parameter-declaration
(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();
Expand Down
18 changes: 18 additions & 0 deletions clang/test/SemaCXX/function-type-qual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,21 @@ 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}}
void* operator new[](size_t bytes) const; //expected-error {{static member function cannot have 'const' qualifier}}

void operator delete(void*) const; //expected-error {{static member function cannot have 'const' qualifier}}
void operator delete[](void*) const; //expected-error {{static member function cannot have 'const' qualifier}}
};
struct B {
void* operator new(size_t bytes) volatile; //expected-error {{static member function cannot have 'volatile' qualifier}}
void* operator new[](size_t bytes) volatile; //expected-error {{static member function cannot have 'volatile' qualifier}}

void operator delete(void*) volatile; //expected-error {{static member function cannot have 'volatile' qualifier}}
void operator delete[](void*) volatile; //expected-error {{static member function cannot have 'volatile' qualifier}}
};
}