Skip to content

[BUG] Line number and formatting issues on generated that functions. #282

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
gregmarr opened this issue Mar 14, 2023 · 2 comments
Closed
Assignees
Labels

Comments

@gregmarr
Copy link
Contributor

Describe the bug
Generated .cpp file has incorrect #line numbers, misplaced braces, should be a newline between closing brace and next function. See inline comments for issue descriptions.

To Reproduce
regression-tests/pure2-types-that-parameters.cpp2

 1
 2 myclass : type = {
 3 
 4     operator=: (out this) = { }
 5 
 6     operator=: (out this, that) = {
 7         name = that.name;
 8         addr = that.addr;
 9     }
10
11    operator=: (out this, move that) = {
12        name = that.name;
13        addr = that.addr;
14    }

regression-tests/test-results/pure2-types-that-parameters.cpp

#line 1 "pure2-types-that-parameters.cpp2"

class myclass   {

    public: myclass()         
                              : name{ "Henry" }
                              , addr{ "123 Ford Dr." }
#line 5 "pure2-types-that-parameters.cpp2" // The following braces are from line 4, not 5
{} // Braces are at column 0 instead of normal indentation from function or at source column
    public: explicit myclass(myclass const& that)
        : name{ that.name }
        , addr{ that.addr }
#line 7 "pure2-types-that-parameters.cpp2" // The following brace is from line 6, not 7
{  // Brace is at column 0 instead of normal indentation from function or at source column

    }public: auto operator=(myclass const& that) -> void{name = that.name;addr = that.addr;}  // assignment operator follows immediately after closing brace with no whitespace, generated by line 6, but will be reported as line 9.  Assignments in body are from lines 7 and 8 but will be reported as line 9.  No whitespace inside function body.

    public: explicit myclass(myclass&& that)
        : name{ std::move(that).name }
        , addr{ std::move(that).addr }
#line 12 "pure2-types-that-parameters.cpp2" // The following brace is from line 11, not 12
{

    }public: auto operator=(myclass&& that) -> void{name = std::move(that).name;addr = std::move(that).addr;}  // assignment operator follows immediately after closing brace with no whitespace, generated by line 11, but will be reported as line 14.  Assignments in body are from lines 12 and 13 but will be reported as line 14

Expected something like this

#line 1 "pure2-types-that-parameters.cpp2"

class myclass   {

    public: myclass()         
                              : name{ "Henry" }
                              , addr{ "123 Ford Dr." }
#line 4 "pure2-types-that-parameters.cpp2"
        {}

    public: explicit myclass(myclass const& that)
        : name{ that.name }
        , addr{ that.addr }
#line 6 "pure2-types-that-parameters.cpp2"
                                  {

    }

#line 6 "pure2-types-that-parameters.cpp2"
    public: auto operator=(myclass const& that) -> void {
        name = that.name;
        addr = that.addr;
    }

    public: explicit myclass(myclass&& that)
        : name{ std::move(that).name }
        , addr{ std::move(that).addr }
#line 11 "pure2-types-that-parameters.cpp2"
                                      {

    }

#line 11 "pure2-types-that-parameters.cpp2"
    public: auto operator=(myclass&& that) -> void {
        name = std::move(that).name;
        addr = std::move(that).addr;
    }
@gregmarr gregmarr added the bug Something isn't working label Mar 14, 2023
hsutter added a commit that referenced this issue Mar 20, 2023
See the wiki documentation page: https://github.com/hsutter/cppfront/wiki/Cpp2:-operator=,-this-&-that

See also the new `pure2-types-smf*.cpp2` test cases for examples.

Made Cpp1 assignment "return *this;", closes #277

Changed in<T> to pass fundamental types by value. Only those are known to be always complete. Partly addresses #270.

Also partly improves #282.
@hsutter hsutter self-assigned this Mar 20, 2023
@hsutter
Copy link
Owner

hsutter commented Mar 22, 2023

@gregmarr This should be much improved now -- please check, does it look reasonable enough for now?

@gregmarr
Copy link
Contributor Author

Yes, it is much improved. *** should be 6, and could stand to be indented further, but I'd say it meets the "reasonable enough for now" test.

#line 1 "pure2-types-that-parameters.cpp2"
1 
2 class myclass   {
3 
4    public: myclass(){}
5 
6     public: explicit myclass(myclass const& that)
7         : name{ that.name }
8         , addr{ that.addr }
#line 7 "pure2-types-that-parameters.cpp2"
7 { // ***
8 
9     }
#line 6 "pure2-types-that-parameters.cpp2"
6     public: auto operator=(myclass const& that) -> myclass& {
7         name = that.name;
8         addr = that.addr;
#line 7 "pure2-types-that-parameters.cpp2"
7         
8         return *this;
#line 8 "pure2-types-that-parameters.cpp2"
8 
9     }

zaucy pushed a commit to zaucy/cppfront that referenced this issue Dec 5, 2023
See the wiki documentation page: https://github.com/hsutter/cppfront/wiki/Cpp2:-operator=,-this-&-that

See also the new `pure2-types-smf*.cpp2` test cases for examples.

Made Cpp1 assignment "return *this;", closes hsutter#277

Changed in<T> to pass fundamental types by value. Only those are known to be always complete. Partly addresses hsutter#270.

Also partly improves hsutter#282.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants