Skip to content

Commit 70d6e7c

Browse files
authored
[Clang] Rewrite SourceLocExpr in default args (#93383)
In order for their dependency to be computed correctly, SourceLocExpr should refer to the context in which they are used. Fixes #92680
1 parent cf9eeb6 commit 70d6e7c

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ Bug Fixes to C++ Support
794794
Fixes (#GH87210), (GH89541).
795795
- Clang no longer tries to check if an expression is immediate-escalating in an unevaluated context.
796796
Fixes (#GH91308).
797+
- Fix a crash caused by a regression in the handling of ``source_location``
798+
in dependent contexts. Fixes (#GH92680).
797799

798800
Bug Fixes to AST Handling
799801
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaExpr.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5506,6 +5506,15 @@ struct EnsureImmediateInvocationInDefaultArgs
55065506
// cause it to incorrectly point it to the outermost class
55075507
// in the case of nested struct initialization.
55085508
ExprResult TransformCXXThisExpr(CXXThisExpr *E) { return E; }
5509+
5510+
// Rewrite to source location to refer to the context in which they are used.
5511+
ExprResult TransformSourceLocExpr(SourceLocExpr *E) {
5512+
if (E->getParentContext() == SemaRef.CurContext)
5513+
return E;
5514+
return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
5515+
E->getBeginLoc(), E->getEndLoc(),
5516+
SemaRef.CurContext);
5517+
}
55095518
};
55105519

55115520
ExprResult Sema::BuildCXXDefaultArgExpr(SourceLocation CallLoc,

clang/test/SemaCXX/source_location.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,3 +912,20 @@ auto g() {
912912
}
913913

914914
}
915+
916+
namespace GH92680 {
917+
918+
struct IntConstuctible {
919+
IntConstuctible(std::source_location = std::source_location::current());
920+
};
921+
922+
template <typename>
923+
auto construct_at(IntConstuctible) -> decltype(IntConstuctible()) {
924+
return {};
925+
}
926+
927+
void test() {
928+
construct_at<IntConstuctible>({});
929+
}
930+
931+
}

0 commit comments

Comments
 (0)