Skip to content

Commit 099d896

Browse files
Sirraidesys-ce-bb
authored andcommitted
[Clang] Look through type sugar when accessing FunctionProtoType
1 parent 0f3c5a0 commit 099d896

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20853,7 +20853,7 @@ static void FixDependencyOfIdExpressionsInLambdaWithDependentObjectParameter(
2085320853
if (MD->getType().isNull())
2085420854
continue;
2085520855

20856-
const auto *Ty = cast<FunctionProtoType>(MD->getType());
20856+
const auto *Ty = MD->getType()->getAs<FunctionProtoType>();
2085720857
if (!Ty || !MD->isExplicitObjectMemberFunction() ||
2085820858
!Ty->getParamType(0)->isDependentType())
2085920859
continue;

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ void Sema::MarkThisReferenced(CXXThisExpr *This) {
14941494
if (MD->getType().isNull())
14951495
return false;
14961496

1497-
const auto *Ty = cast<FunctionProtoType>(MD->getType());
1497+
const auto *Ty = MD->getType()->getAs<FunctionProtoType>();
14981498
return Ty && MD->isExplicitObjectMemberFunction() &&
14991499
Ty->getParamType(0)->isDependentType();
15001500
}

clang/test/SemaCXX/cxx2b-deducing-this.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,18 @@ void TestMutationInLambda() {
312312
l1();
313313
l2();
314314
}
315+
316+
// Check that we don't crash if the lambda has type sugar.
317+
const auto l15 = [=](this auto&&) [[clang::annotate_type("foo")]] [[clang::annotate_type("bar")]] {
318+
return x;
319+
};
320+
321+
const auto l16 = [=]() [[clang::annotate_type("foo")]] [[clang::annotate_type("bar")]] {
322+
return x;
323+
};
324+
325+
l15();
326+
l16();
315327
}
316328

317329
struct Over_Call_Func_Example {

clang/test/SemaCXX/lambda-expressions.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,3 +762,12 @@ template auto t::operator()<int>(int a) const; // expected-note {{in instantiati
762762

763763
}
764764
#endif
765+
766+
namespace GH84473_bug {
767+
void f1() {
768+
int b;
769+
(void) [=] [[gnu::regcall]] () { // expected-warning {{an attribute specifier sequence in this position is a C++23 extension}}
770+
(void) b;
771+
};
772+
}
773+
}

0 commit comments

Comments
 (0)