Skip to content

Commit 8aa95e2

Browse files
committed
Add method-specific diagnostics
to diagnose virtual function failures
1 parent fb70b44 commit 8aa95e2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

clang/lib/Sema/SemaTypeTraits.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,6 +2345,13 @@ static void DiagnoseNonStandardLayoutReason(Sema &SemaRef, SourceLocation Loc,
23452345
if (D->isPolymorphic()) {
23462346
SemaRef.Diag(Loc, diag::note_unsatisfied_trait_reason)
23472347
<< diag::TraitNotSatisfiedReason::VirtualFunction;
2348+
2349+
for (const CXXMethodDecl *Method : D->methods()) {
2350+
if (Method->isVirtual()) {
2351+
SemaRef.Diag(Method->getLocation(), diag::note_defined_here) << Method;
2352+
break;
2353+
}
2354+
}
23482355
}
23492356
for (const FieldDecl *Field : D->fields()) {
23502357
if (!Field->getType()->isStandardLayoutType()) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,13 @@ static_assert(__is_trivially_copyable(S12));
491491

492492
namespace standard_layout_tests {
493493
struct WithVirtual { // #sl-Virtual
494-
virtual void foo();
494+
virtual void foo(); // #sl-Virtual-Foo
495495
};
496496
static_assert(__is_standard_layout(WithVirtual));
497497
// expected-error@-1 {{static assertion failed due to requirement '__is_standard_layout(standard_layout_tests::WithVirtual)'}} \
498498
// expected-note@-1 {{'WithVirtual' is not standard-layout}} \
499499
// expected-note@-1 {{because it has a virtual function}} \
500+
// expected-note@#sl-Virtual-Foo {{'foo' defined here}} \
500501
// expected-note@#sl-Virtual {{'WithVirtual' defined here}}
501502

502503
struct MixedAccess { // #sl-Mixed
@@ -520,6 +521,7 @@ static_assert(__is_standard_layout(VB));
520521
// expected-note@-1 {{because it has a non-standard-layout base 'VirtualBase'}} \
521522
// expected-note@-1 {{because it has a virtual function}}
522523
// expected-note@#sl-VB {{'VB' defined here}}
524+
// expected-note@#sl-VB {{'~VB' defined here}}
523525

524526
union U { // #sl-U
525527
public:

0 commit comments

Comments
 (0)