Skip to content

Commit afcf464

Browse files
committed
[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: #79748
1 parent 46068f5 commit afcf464

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

clang/lib/Sema/SemaType.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5914,8 +5914,10 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
59145914
//
59155915
// ... for instance.
59165916
if (IsQualifiedFunction &&
5917-
!(Kind == Member && !D.isExplicitObjectMemberFunction() &&
5918-
D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static) &&
5917+
(Kind != Member || D.isExplicitObjectMemberFunction() ||
5918+
D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static ||
5919+
(D.getContext() == clang::DeclaratorContext::Member &&
5920+
D.isStaticMember())) &&
59195921
!IsTypedefName && D.getContext() != DeclaratorContext::TemplateArg &&
59205922
D.getContext() != DeclaratorContext::TemplateTypeArg) {
59215923
SourceLocation Loc = D.getBeginLoc();

clang/test/SemaCXX/function-type-qual.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,10 @@ void instantiateArrayDecay() {
3737
int a[1];
3838
arrayDecay(a);
3939
}
40+
41+
namespace GH79748 {
42+
typedef decltype(sizeof(0)) size_t;
43+
struct A {
44+
void* operator new(size_t bytes) const; //expected-error {{static member function cannot have 'const' qualifier}}
45+
};
46+
}

0 commit comments

Comments
 (0)