Skip to content

Commit 711df55

Browse files
committed
Address review comments
1 parent e3b23f5 commit 711df55

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,8 @@ def note_unsatisfied_trait_reason
18291829
"%PrivateProtectedDirectBase{has a %select{private|protected}1 direct base}|"
18301830
"%NotClassOrUnion{is not a class or union type}|"
18311831
"%NotMarkedFinal{is not marked 'final'}|"
1832+
"%PointerType{is a pointer type}|"
1833+
"%ArrayType{is an array type}|"
18321834
"%UnionType{is a union type}|"
18331835
"%NotStructOrClass{is not a struct or class type}|"
18341836
"%OverridesAllPureVirtual{overrides all pure virtual functions from base class %1}"

clang/lib/Sema/SemaTypeTraits.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,8 +2780,7 @@ static void DiagnoseNonAbstractReason(Sema &SemaRef, SourceLocation Loc,
27802780
// If this type has any abstract base classes, their respective virtual
27812781
// functions must have been overridden.
27822782
for (const CXXBaseSpecifier &B : D->bases()) {
2783-
assert(B.getType()->getAsCXXRecordDecl() && "invalid base?");
2784-
if (B.getType()->getAsCXXRecordDecl()->isAbstract()) {
2783+
if (B.getType()->castAsCXXRecordDecl()->isAbstract()) {
27852784
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
27862785
<< diag::TraitNotSatisfiedReason::OverridesAllPureVirtual
27872786
<< B.getType() << B.getSourceRange();
@@ -2811,6 +2810,8 @@ static void DiagnoseNonAbstractReason(Sema &SemaRef, SourceLocation Loc,
28112810
}
28122811

28132812
if (SemaRef.Context.getAsArrayType(T)) {
2813+
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2814+
<< diag::TraitNotSatisfiedReason::ArrayType;
28142815
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
28152816
<< diag::TraitNotSatisfiedReason::NotStructOrClass;
28162817
return;
@@ -2824,6 +2825,14 @@ static void DiagnoseNonAbstractReason(Sema &SemaRef, SourceLocation Loc,
28242825
return;
28252826
}
28262827

2828+
if (T->isPointerType()) {
2829+
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2830+
<< diag::TraitNotSatisfiedReason::PointerType;
2831+
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
2832+
<< diag::TraitNotSatisfiedReason::NotStructOrClass;
2833+
return;
2834+
}
2835+
28272836
if (!T->isStructureOrClassType()) {
28282837
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
28292838
<< diag::TraitNotSatisfiedReason::NotStructOrClass;

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,10 @@ static_assert(__is_abstract(Overrides));
991991
// expected-note@-1 {{because it overrides all pure virtual functions from base class 'Abstract1'}} \
992992
// expected-note@-1 {{because it overrides all pure virtual functions from base class 'Abstract2'}} \
993993
994+
static_assert(__is_abstract(NonAbstract));
995+
// expected-error@-1 {{static assertion failed due to requirement '__is_abstract(is_abstract_tests::NonAbstract)'}} \
996+
// expected-note@-1 {{'NonAbstract' is not abstract}}
997+
994998
// Inheriting over two levels reports the last class only although the source of the pure virtual function
995999
// is the top-most base.
9961000
struct Derived : Abstract1 {
@@ -1012,7 +1016,7 @@ static_assert(__is_abstract(I));
10121016
// expected-note@-1 {{'I' (aka 'int') is not abstract}} \
10131017
// expected-note@-1 {{because it is not a struct or class type}}
10141018

1015-
using Fty = void(); // function type
1019+
using Fty = void();
10161020
static_assert(__is_abstract(Fty));
10171021
// expected-error@-1 {{static assertion failed due to requirement '__is_abstract(void ())'}} \
10181022
// expected-note@-1 {{'Fty' (aka 'void ()') is not abstract}} \
@@ -1023,6 +1027,7 @@ using Arr = int[3];
10231027
static_assert(__is_abstract(Arr));
10241028
// expected-error@-1 {{static assertion failed due to requirement '__is_abstract(int[3])'}} \
10251029
// expected-note@-1 {{'Arr' (aka 'int[3]') is not abstract}} \
1030+
// expected-note@-1 {{because it is an array type}} \
10261031
// expected-note@-1 {{because it is not a struct or class type}}
10271032

10281033
using Ref = int&;
@@ -1036,7 +1041,14 @@ using Ptr = int*;
10361041
static_assert(__is_abstract(Ptr));
10371042
// expected-error@-1 {{static assertion failed due to requirement '__is_abstract(int *)'}} \
10381043
// expected-note@-1 {{'Ptr' (aka 'int *') is not abstract}} \
1044+
// expected-note@-1 {{because it is a pointer type}} \
10391045
// expected-note@-1 {{because it is not a struct or class type}}
10401046

1047+
union U { int x; float y;};
1048+
static_assert(__is_abstract(U));
1049+
// expected-error@-1 {{static assertion failed due to requirement '__is_abstract(is_abstract_tests::U)'}} \
1050+
// expected-note@-1 {{'U' is not abstract}} \
1051+
// expected-note@-1 {{because it is a union type}} \
1052+
// expected-note@-1 {{because it is not a struct or class type}}
10411053

10421054
}

0 commit comments

Comments
 (0)