Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2066,7 +2066,7 @@ bool Compiler<Emitter>::VisitUnaryExprOrTypeTraitExpr(
Size = CharUnits::One();
else {
if (ArgType->isDependentType() || !ArgType->isConstantSizeType())
return false;
return this->emitInvalid(E);

if (Kind == UETT_SizeOf)
Size = ASTCtx.getTypeSizeInChars(ArgType);
Expand Down
25 changes: 10 additions & 15 deletions clang/test/AST/ByteCode/literals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,31 +261,26 @@ namespace SizeOf {
}

#if __cplusplus >= 201402L
constexpr int IgnoredRejected() { // ref-error {{never produces a constant expression}}
constexpr int IgnoredRejected() { // both-error {{never produces a constant expression}}
int n = 0;
sizeof(int[n++]); // both-warning {{expression result unused}} \
// ref-note 2{{subexpression not valid in a constant expression}}
// both-note 2{{subexpression not valid in a constant expression}}
return n;
}
/// FIXME: This is rejected because the parameter so sizeof() is not constant.
/// produce a proper diagnostic.
static_assert(IgnoredRejected() == 0, ""); // both-error {{not an integral constant expression}} \
// ref-note {{in call to 'IgnoredRejected()'}}
// both-note {{in call to 'IgnoredRejected()'}}
#endif


#if __cplusplus >= 202002L
/// FIXME: The following code should be accepted.
consteval int foo(int n) { // ref-error {{consteval function never produces a constant expression}}
return sizeof(int[n]); // ref-note 3{{not valid in a constant expression}}
}
constinit int var = foo(5); // ref-error {{not a constant expression}} \
// ref-note 2{{in call to}} \
// ref-error {{does not have a constant initializer}} \
// ref-note {{required by 'constinit' specifier}} \
// expected-error {{is not a constant expression}} \
// expected-error {{does not have a constant initializer}} \
// expected-note {{required by 'constinit' specifier}} \
consteval int foo(int n) { // both-error {{consteval function never produces a constant expression}}
return sizeof(int[n]); // both-note 3{{not valid in a constant expression}}
}
constinit int var = foo(5); // both-error {{not a constant expression}} \
// both-note 2{{in call to}} \
// both-error {{does not have a constant initializer}} \
// both-note {{required by 'constinit' specifier}}

#endif
};
Expand Down
Loading