Skip to content

Commit f807494

Browse files
committed
[clang][Interp] Fix SourceLocExpr used in CXXDefaultInitExprs
... when initializing. Fixes a problem pointed out in https://reviews.llvm.org/D156045/
1 parent 91fdb20 commit f807494

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,12 +2152,11 @@ bool ByteCodeExprGen<Emitter>::VisitCXXMemberCallExpr(
21522152
template <class Emitter>
21532153
bool ByteCodeExprGen<Emitter>::VisitCXXDefaultInitExpr(
21542154
const CXXDefaultInitExpr *E) {
2155-
2155+
SourceLocScope<Emitter> SLS(this, E);
21562156
if (Initializing)
21572157
return this->visitInitializer(E->getExpr());
21582158

21592159
assert(classify(E->getType()));
2160-
SourceLocScope<Emitter> SLS(this, E);
21612160
return this->visit(E->getExpr());
21622161
}
21632162

clang/test/AST/Interp/builtin-functions.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,15 @@ namespace SourceLocation {
248248
};
249249

250250
static_assert(Foo{}.a == __LINE__, "");
251+
252+
struct AA {
253+
int n = __builtin_LINE();
254+
};
255+
struct B {
256+
AA a = {};
257+
};
258+
constexpr void f() {
259+
constexpr B c = {};
260+
static_assert(c.a.n == __LINE__ - 1, "");
261+
}
251262
}

0 commit comments

Comments
 (0)