Skip to content

Commit 61c7a69

Browse files
committed
[clang][Interp] Fix sizeof of reference types
1 parent df856e4 commit 61c7a69

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,12 @@ bool ByteCodeExprGen<Emitter>::VisitUnaryExprOrTypeTraitExpr(
10851085

10861086
if (Kind == UETT_SizeOf) {
10871087
QualType ArgType = E->getTypeOfArgument();
1088+
1089+
// C++ [expr.sizeof]p2: "When applied to a reference or a reference type,
1090+
// the result is the size of the referenced type."
1091+
if (const auto *Ref = ArgType->getAs<ReferenceType>())
1092+
ArgType = Ref->getPointeeType();
1093+
10881094
CharUnits Size;
10891095
if (ArgType->isVoidType() || ArgType->isFunctionType())
10901096
Size = CharUnits::One();

clang/test/AST/Interp/literals.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ namespace PointerComparison {
216216
}
217217

218218
namespace SizeOf {
219+
static_assert(alignof(char&) == 1);
220+
219221
constexpr int soint = sizeof(int);
220222
constexpr int souint = sizeof(unsigned int);
221223
static_assert(soint == souint, "");

0 commit comments

Comments
 (0)