Skip to content

[CI] Fix clang-18 C++23 build of cppfront #1187

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

Merged
merged 3 commits into from
Jul 30, 2024

Conversation

bluetarpmedia
Copy link
Contributor

@bluetarpmedia bluetarpmedia commented Jul 30, 2024

Some constructors and destructors have to be defaulted/written out-of-line in order to compile successfully with clang 18 in C++23 mode, due to forward declaring types and using them with unique_ptr.

Fixes this build error.

Similar issue as solved by this previous PR: #1088

EDIT: This only fixes the CI build of cppfront; I'll create a separate PR to update the regression tests.

Neil Henderson added 3 commits July 30, 2024 11:18
The `declaration_node` definition for the `unique_ptr` member is not yet visible if the ctor is written inline.
@bluetarpmedia bluetarpmedia changed the title Fix clang-18 C++23 build of cppfront [CI] Fix clang-18 C++23 build of cppfront Jul 30, 2024
@hsutter
Copy link
Owner

hsutter commented Jul 30, 2024

Thanks! But this is only needed for the destructor, right? Not the constructor?

@bluetarpmedia
Copy link
Contributor Author

It's needed for both in this case.

Here's a repro showing the ctor issue:

#include <memory>

struct MyType;

struct Owner
{
    std::unique_ptr<MyType> mine_;

    Owner() {}
};

struct MyType
{
    int value = 0;
};

int main()
{
    Owner o;
}

Relevant hint from the error:

<source>:9:5: note: in instantiation of member function 'std::unique_ptr<MyType>::~unique_ptr' requested here
    9 |     Owner() {}

I think it needs to be able to destruct the unique_ptr in case the ctor throws?

Fixed version:

#include <memory>

struct MyType;

struct Owner
{
    std::unique_ptr<MyType> mine_;

    Owner();
};

struct MyType
{
    int value = 0;
};

Owner::Owner() {}

int main()
{
    Owner o;
}

@hsutter
Copy link
Owner

hsutter commented Jul 30, 2024

I think it needs to be able to destruct the unique_ptr in case the ctor throws?

That reasoning makes sense to me. Then I wondered, 'why do other types in parse.h only have to put the dtor out of line for this?' I looked, and I think the answer is because those types don't have a user-declared constructor... bingo.

So I think this makes sense. Thanks!

@hsutter hsutter merged commit a8d70c1 into hsutter:main Jul 30, 2024
20 of 29 checks passed
@bluetarpmedia bluetarpmedia deleted the parameter-declaration-node-ctor branch July 31, 2024 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants