diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -5427,11 +5427,31 @@ } } +static bool CheckTypeTraitArgNumber(TypeTrait Kind, size_t N) { + if (Kind <= UTT_Last) + return N == 1; + if (Kind <= BTT_Last && Kind != BTT_ReferenceBindsToTemporary) + return N == 2; + switch (Kind) { + case clang::BTT_ReferenceBindsToTemporary: + case clang::TT_IsConstructible: + case clang::TT_IsNothrowConstructible: + case clang::TT_IsTriviallyConstructible: { + return N >= 1; + } + default: + llvm_unreachable("not a TT"); + } +} + ExprResult Sema::BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, ArrayRef Args, SourceLocation RParenLoc) { QualType ResultType = Context.getLogicalOperationType(); + if (!CheckTypeTraitArgNumber(Kind, Args.size())) + return ExprError(); + if (Kind <= UTT_Last && !CheckUnaryTypeTraitTypeCompleteness( *this, Kind, KWLoc, Args[0]->getType())) return ExprError(); diff --git a/clang/test/SemaCXX/type-trait-eval-crash-issue-57008.cpp b/clang/test/SemaCXX/type-trait-eval-crash-issue-57008.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaCXX/type-trait-eval-crash-issue-57008.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only %s + +// Shouldn't crash here +// Reported by https://github.com/llvm/llvm-project/issues/57008 +template bool b = __is_constructible(Ts...); +bool x = b<>;