push members down does not move code implementation

Answered

Apparently, the code refactoring “push members down” does not actually correctly move the code.

To reproduce the issue, consider following minimal code:

struct A {
    int compute() const noexcept;
};

int A::compute() const noexcept {
    return 4;
}

struct B : A {

    int x;
};

Now, performing a “push members down” of the member function ```A::compute``` results in this code, clearly wrong:

struct A {
};

int A::compute() const noexcept {
    return 4;
}

struct B : A {

    int x;

    int compute() const noexcept;
};

In other words, the refactoring moves the declaration only, not the implementation.

1
3 comments

Hello!

I can't reproduce the issue in CLion 2023.2.2 with a simple project.

The original code:

The resulting code after applying the “Push Members Down…” refactoring on the lines 4 or 7:

Please update CLion to 2023.2.2 if needed, in this version create a default "Hello, World!" project (`File | New Project` > `C++ Executable` > `Create`) and try to reproduce the issue in this project. Does the issue happen?

0

Hi,

thanks for your comment. I am using Clion 2023.2.2.

If I follow exactly your instruction, the problem does not appear.

However, the error persists if I do the following:

 

-create a new project (File→New Project→C++ Executable→Create)

-in the default main.cpp, add the code for struct A and B as above

-*remove* the main() function from the source file

-Refactor→Push members down→select the compute() method to be moved to struct B

 

Then, only the declaration inside the struct is moved, but not the implementation, precisely as in my post.

 

This looks to me a bug, for I don't see why the behavior should be different depending a main() is present or not.

 

The same thing happens if, after creating a default project, I right-click on the project outline “new c++ header file”, selecting also “add to target”. Then if I copy the same code  as above, and try to push A::compute() down, the same problem appears.

0

Thank you for the provided details! I created CPP-35599. Feel free to comment or upvote the issue in order to get updates. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.

0

Please sign in to leave a comment.