Skip to content

Commit

Permalink
[Clang][Sema] Fix crash with const qualified member operator new
Browse files Browse the repository at this point in the history
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: llvm#79748
  • Loading branch information
shafik committed Feb 1, 2024
1 parent 46068f5 commit 571ca73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions clang/lib/Sema/SemaType.cpp
Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions clang/test/SemaCXX/function-type-qual.cpp
Expand Up @@ -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}}
};
}

0 comments on commit 571ca73

Please sign in to comment.