Skip to content
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

Fix 21218 - protection attributes should be emitted to C++ headers #11804

Merged
merged 3 commits into from
Oct 15, 2020

Conversation

MoonlightSentinel
Copy link
Contributor

Properly track the current protection while writing struct/class members and add public:, protected: or private: as necessary.

package and package(...) is currently mapped to protected as there is no real equivalent in C++, better suggestions are welcome.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @MoonlightSentinel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
21218 normal dtoh: protection attributes should be emitted to headers

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#11804"

@12345swordy
Copy link
Contributor

Try mapping package to c++ namespace?

@MoonlightSentinel
Copy link
Contributor Author

MoonlightSentinel commented Sep 28, 2020

How would that work given that C++ doesn't allow namespaces inside aggregates?

EDIT: They also affect the mangling so using the generated header would result in linker errors.

@@ -15,6 +15,7 @@ template <typename T>
struct A
{
// Ignoring var x alignment 0
public:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably redundant to have public on a struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a bug caused by the current template handling (gonna fix that in a later PR).

@@ -6496,6 +6559,7 @@ struct Target
bool isReturnOnStack(TypeFunction* tf, bool needsThis);
uint64_t parameterSize(const Loc& loc, Type* t);
void applyInRefParams(TypeFunction* tf);
private:
enum class TargetInfoKeys
Copy link
Member

@ibuclaw ibuclaw Sep 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than marking it private, I guess it shouldn't be emitted at all. (Though there could be something public that depends on it).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to emit it just in case. We could detect if they are used outside for public declarations (but im not sure if that is worth it....)

src/dmd/frontend.h Outdated Show resolved Hide resolved
Copy link
Member

@ibuclaw ibuclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Granted that private has two different meanings in C++ and D, I'd probably just restrict the use of private to just fields. Final functions (do not appear in the vtable) that are also private should not be present anywhere. Probably the same applies to private type declarations.

@MoonlightSentinel MoonlightSentinel force-pushed the dtoh-protection branch 3 times, most recently from 7e50b79 to 66f1c22 Compare October 2, 2020 23:43
@MoonlightSentinel MoonlightSentinel force-pushed the dtoh-protection branch 2 times, most recently from 224a5b6 to d999c2f Compare October 10, 2020 12:27
@ibuclaw
Copy link
Member

ibuclaw commented Oct 12, 2020

@MoonlightSentinel - looks like some tests are still failing, so I'll hold back until they're resolved. ;-)

@MoonlightSentinel
Copy link
Contributor Author

None of those were caused by this PR ;-)

(Rebased and it should be green now aside from the known Azure failure)

Properly track the current protection while writing struct/class members
and add `public:`, `protected:` or `private:` as necessary.

`package` and `package(...)` is currently mapped to `protected` as there
is no real equivalent in C++.
@dlang-bot dlang-bot merged commit 4cdb960 into dlang:master Oct 15, 2020
@MoonlightSentinel MoonlightSentinel deleted the dtoh-protection branch February 28, 2021 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants