-
Notifications
You must be signed in to change notification settings - Fork 6
export classes with pure virtual destructors #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// RUN: %idt --export-macro IDT_TEST_ABI %s 2>&1 | %FileCheck %s | ||
|
||
// PureVirtualClass should get annotated because it contains a pure virtual | ||
// destructor with an out-of-line definition. | ||
|
||
// CHECK: PureVirtualDestructor.hh:[[@LINE+1]]:8: remark: unexported public interface 'PureVirtualClass' | ||
struct PureVirtualClass { | ||
// CHECK-NOT: PureVirtualDestructor.hh:[[@LINE-1]]:{{.*}} | ||
|
||
// CHECK-NOT: PureVirtualDestructor.hh:[[@LINE+1]]:{{.*}} | ||
virtual ~PureVirtualClass() = 0; | ||
// CHECK-NOT: PureVirtualDestructor.hh:[[@LINE-1]]:{{.*}} | ||
|
||
// CHECK-NOT: PureVirtualDestructor.hh:[[@LINE+1]]:{{.*}} | ||
virtual void virtualMethod() = 0; | ||
}; | ||
|
||
// AnotherPureVirtualClass should get NOT get annotated because its pure virtual | ||
// destructor has an out-of-line definition within this translation unit. | ||
|
||
// CHECK-NOT: PureVirtualDestructor.hh:[[@LINE+1]]:{{.*}} | ||
struct AnotherPureVirtualClass { | ||
// CHECK-NOT: PureVirtualDestructor.hh:[[@LINE+1]]:{{.*}} | ||
virtual ~AnotherPureVirtualClass() = 0; | ||
|
||
// CHECK-NOT: PureVirtualDestructor.hh:[[@LINE+1]]:{{.*}} | ||
virtual void virtualMethod() = 0; | ||
}; | ||
|
||
// CHECK-NOT: PureVirtualDestructor.hh:[[@LINE+1]]:{{.*}} | ||
AnotherPureVirtualClass::~AnotherPureVirtualClass() {} | ||
|
||
// YetAnotherPureVirtualClass should get NOT get annotated because its pure | ||
// virtual destructor has an out-of-line defaulted definition within this | ||
// translation unit. | ||
|
||
// CHECK-NOT: PureVirtualDestructor.hh:[[@LINE+1]]:{{.*}} | ||
struct YetAnotherPureVirtualClass { | ||
// CHECK-NOT: PureVirtualDestructor.hh:[[@LINE+1]]:{{.*}} | ||
virtual ~YetAnotherPureVirtualClass() = 0; | ||
|
||
// CHECK-NOT: PureVirtualDestructor.hh:[[@LINE+1]]:{{.*}} | ||
virtual void virtualMethod() = 0; | ||
}; | ||
|
||
// CHECK-NOT: PureVirtualDestructor.hh:[[@LINE+1]]:{{.*}} | ||
YetAnotherPureVirtualClass::~YetAnotherPureVirtualClass() = default; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow this comment. Why is this the case? Are you referring to the ELF specific behaviour of the virtual dtor serving as a key function? If so, that is an itanium ABI specific behaviour. We can query the C++ model that is in use for evaluating this then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, nothing ABI specific. I will rework this comment so it is more clear.
My intent was to explain that we have two cases for the implementation of a pure virtual destructor. Since pure virtual destructors are the only pure virtual methods that require an implementation (afaict), we know there must be one somewhere. If it is in the translation unit, we don't have to export it:
If it is not in the translation unit, we assume the destructor implementation is in a .cpp file somewhere, so it does need to be exported.
Alternatively: we could just ALWAYS export classes that have pure virtual functions. This may lead to exporting a bit more than necessary, but will also catch the case where a class has other pure virtual functions with implementations. Does that sound better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, the case now makes more sense! If we can get away with it, that would be nice ... but, doesn't the virtual dtor result in a vtable which also needs to be exported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct. This change results in a class getting exported whenever it has a pure virtual dtor.
Having given this more thought, I think we should stick with the more constrained case and export only when there is a pure virtual dtor. If we export a class whenever it contains any pure virtual function, that's going to export a lot more unnecessarily.