Skip to content

Commit 124e9f1

Browse files
committed
Fixed some problems, changed behavior on void types, updated test
1 parent bd1e468 commit 124e9f1

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

clang/lib/Sema/SemaTypeTraits.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "clang/AST/DeclCXX.h"
14+
#include "clang/AST/TemplateBase.h"
1415
#include "clang/AST/Type.h"
1516
#include "clang/Basic/DiagnosticParse.h"
1617
#include "clang/Basic/DiagnosticSema.h"
@@ -1986,9 +1987,11 @@ static ExtractedTypeTraitInfo ExtractTypeTraitFromExpression(const Expr *E) {
19861987
if (Arg.getKind() == TemplateArgument::ArgKind::Pack) {
19871988
for (const auto &InnerArg : Arg.pack_elements())
19881989
Args.push_back(InnerArg.getAsType());
1989-
}
1990-
if (Arg.getKind() == TemplateArgument::ArgKind::Type)
1990+
} else if (Arg.getKind() == TemplateArgument::ArgKind::Type)
19911991
Args.push_back(Arg.getAsType());
1992+
assert((Arg.getKind() == TemplateArgument::ArgKind::Type ||
1993+
Arg.getKind() == TemplateArgument::ArgKind::Pack) &&
1994+
"Unexpected kind");
19921995
}
19931996
return {{Trait.value(), std::move(Args)}};
19941997
}
@@ -2263,12 +2266,19 @@ static void DiagnoseNonTriviallyCopyableReason(Sema &SemaRef,
22632266
static void DiagnoseNonConstructibleReason(
22642267
Sema &SemaRef, SourceLocation Loc,
22652268
const llvm::SmallVector<clang::QualType, 1> &Ts) {
2266-
for (const auto &ArgTy : Ts) {
2267-
if (ArgTy->isVoidType())
2268-
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2269-
<< diag::TraitNotSatisfiedReason::CVVoidType;
2269+
if (Ts.empty()) {
2270+
return;
22702271
}
22712272

2273+
bool ContainsVoid = false;
2274+
for (const QualType &ArgTy : Ts) {
2275+
ContainsVoid |= ArgTy->isVoidType();
2276+
}
2277+
2278+
if (ContainsVoid)
2279+
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2280+
<< diag::TraitNotSatisfiedReason::CVVoidType;
2281+
22722282
QualType T = Ts[0];
22732283
if (T->isFunctionType())
22742284
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)

clang/test/SemaCXX/type-traits-unsatisfied-diags.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ static_assert(__is_constructible(void));
507507
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(void)'}} \
508508
// expected-note@-1 {{because it is a cv void type}}
509509

510+
static_assert(__is_constructible(void, void));
511+
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(void, void)'}} \
512+
// expected-note@-1 {{because it is a cv void type}}
513+
510514
static_assert(__is_constructible(const void));
511515
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(const void)'}} \
512516
// expected-note@-1 {{because it is a cv void type}}

0 commit comments

Comments
 (0)