Skip to content

Enhancement: Make the default constructor of projection classes not construct implementation class objects #28

@YexuanXiao

Description

@YexuanXiao

Currently, the default constructor of projected types constructs an object of the implementation class, which is inconsistent with the conventions of the C++ standard library (e.g., optional, indirect, and polymorphic). According to C++ standard library conventions, the default constructor should be equivalent to constructing with nullptr, and a constructor taking std::inplace_t should be provided. Thus, the C++/WinRT convention conflicts with the standard library convention, introducing an exception and making the code harder to maintain.

This change is a significant breaking change, so an additional "migration mode" is required to migrate existing code. Provide a new option -stdlib-style-constructor. When this option is enabled, the default constructor is equivalent to using nullptr as the argument, and a version taking std::inplace_t is provided for direct construction of the implementation class. Additionally, provide a new option -stdlib-style-constructor-migrate. When this option is enabled, the default constructor is deleted, and a version with std::inplace_t is provided.

Migration steps: First, enable the -stdlib-style-constructor-migrate option and, based on compiler information, change all initializations that use the default constructor to use std::inplace initialization. Second, enable -stdlib-style-constructor. The stdlib-style-constructor should become the default for any new project and should be permanently disabled in the future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementAdjust existing featureshelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions