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/include/clang/AST/ExprCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -2777,7 +2777,7 @@ class TypeTraitExpr final
ArrayRef<TypeSourceInfo *> Args, SourceLocation RParenLoc,
std::variant<bool, APValue> Value);

TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) {}
TypeTraitExpr(EmptyShell Empty, bool IsStoredAsBool);

size_t numTrailingObjects(OverloadToken<TypeSourceInfo *>) const {
return getNumArgs();
Expand Down
12 changes: 10 additions & 2 deletions clang/lib/AST/ExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,8 @@ TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
if (TypeTraitExprBits.IsBooleanTypeTrait)
TypeTraitExprBits.Value = std::get<bool>(Value);
else
*getTrailingObjects<APValue>() = std::get<APValue>(std::move(Value));
::new (getTrailingObjects<APValue>())
APValue(std::get<APValue>(std::move(Value)));

TypeTraitExprBits.NumArgs = Args.size();
assert(Args.size() == TypeTraitExprBits.NumArgs &&
Expand All @@ -1884,6 +1885,13 @@ TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind,
"Only int values are supported by clang");
}

TypeTraitExpr::TypeTraitExpr(EmptyShell Empty, bool IsStoredAsBool)
: Expr(TypeTraitExprClass, Empty) {
TypeTraitExprBits.IsBooleanTypeTrait = IsStoredAsBool;
if (!IsStoredAsBool)
::new (getTrailingObjects<APValue>()) APValue();
}

TypeTraitExpr *TypeTraitExpr::Create(const ASTContext &C, QualType T,
SourceLocation Loc,
TypeTrait Kind,
Expand All @@ -1909,7 +1917,7 @@ TypeTraitExpr *TypeTraitExpr::CreateDeserialized(const ASTContext &C,
unsigned NumArgs) {
void *Mem = C.Allocate(totalSizeToAlloc<APValue, TypeSourceInfo *>(
IsStoredAsBool ? 0 : 1, NumArgs));
return new (Mem) TypeTraitExpr(EmptyShell());
return new (Mem) TypeTraitExpr(EmptyShell(), IsStoredAsBool);
}

CUDAKernelCallExpr::CUDAKernelCallExpr(Expr *Fn, CallExpr *Config,
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ std::optional<unsigned> Sema::GetDecompositionElementCount(QualType T,
llvm::APSInt TupleSize(Ctx.getTypeSize(Ctx.getSizeType()));
switch (isTupleLike(*this, Loc, T, TupleSize)) {
case IsTupleLike::Error:
return {};
return std::nullopt;
case IsTupleLike::TupleLike:
return TupleSize.getExtValue();
case IsTupleLike::NotTupleLike:
Expand All @@ -1706,7 +1706,7 @@ std::optional<unsigned> Sema::GetDecompositionElementCount(QualType T,
RD->fields(), [](FieldDecl *FD) { return !FD->isUnnamedBitField(); });

if (CheckMemberDecompositionFields(*this, Loc, OrigRD, T, BasePair))
return true;
return std::nullopt;

return NumFields;
}
Expand Down
4 changes: 2 additions & 2 deletions clang/test/SemaCXX/builtin-structured-binding-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ static_assert(__builtin_structured_binding_size(S5) == 2);
// expected-error@-1 {{static assertion failed due to requirement '__builtin_structured_binding_size(S5) == 2'}} \
// expected-note@-1 {{expression evaluates to '1 == 2'}}
static_assert(__builtin_structured_binding_size(S6) == 2);
// expected-error@-1 {{static assertion failed due to requirement '__builtin_structured_binding_size(S6) == 2'}} \
// expected-error@-1 {{cannot decompose class type 'S6' because it has an anonymous union member}} \
// expected-note@-1 {{expression evaluates to '1 == 2'}}
// expected-error@-1 {{type 'S6' cannot be decomposed}} \
// expected-error@-1 {{static assertion expression is not an integral constant expression}} \
// expected-note@#note-anon-union {{declared here}}
static_assert(__builtin_structured_binding_size(S7) == 1);

Expand Down
Loading