Skip to content

Conversation

@brlin-tw
Copy link

@brlin-tw brlin-tw commented Jan 7, 2024

This patch fixes the following compilation error on GCC 12 of the MinGW-w64 toolchain:

wkbre/wkbre.cpp: In function ‘bool IGPlayerChooser(char*, goref*)’:
wkbre/wkbre.cpp:2404:41: error: cannot bind non-const lvalue reference of type ‘ImVec4&’ to an rvalue of type ‘ImVec4’
 2404 |                 OldColorButton("color", ImVec4(1, 1, 1, 1));
      |                                         ^~~~~~~~~~~~~~~~~~
wkbre/wkbre.cpp:1900:47: note:   initializing argument 2 of ‘bool OldColorButton(const char*, ImVec4&, bool)’
 1900 | bool OldColorButton(const char *desc, ImVec4 &col, bool mini = false)
      |                                       ~~~~~~~~^~~

as the pass-by-reference syntax doesn't seem to be necessary. I have little to no C++/Dear ImGui experience so feel free to close this if it's not the case.

@brlin-tw brlin-tw marked this pull request as draft January 7, 2024 18:10
@AdrienTD
Copy link
Owner

AdrienTD commented Jan 7, 2024

The best would have been to use const ImVec4&. This will allow "temporaries" (objects constructed inside a function call argument) to be used. And it would avoid a copy of the entire ImVec4 (though it might be true that in case of temporaries, there is no copy).

But yeah, I made this a while ago when I just started to use C++, hence why there is a lot of bad code and style. (and using the -fpermissive compiler option is something somebody should never use).

@brlin-tw brlin-tw force-pushed the patch/fix-imvec4-compilation-error branch from da17ecf to d5632b5 Compare January 8, 2024 04:55
…value of type ‘ImVec4’" compilation error

This patch fixes the following compilation error on GCC 12:

```
wkbre/wkbre.cpp: In function ‘bool IGPlayerChooser(char*, goref*)’:
wkbre/wkbre.cpp:2404:41: error: cannot bind non-const lvalue reference of type ‘ImVec4&’ to an rvalue of type ‘ImVec4’
 2404 |                 OldColorButton("color", ImVec4(1, 1, 1, 1));
      |                                         ^~~~~~~~~~~~~~~~~~
wkbre/wkbre.cpp:1900:47: note:   initializing argument 2 of ‘bool OldColorButton(const char*, ImVec4&, bool)’
 1900 | bool OldColorButton(const char *desc, ImVec4 &col, bool mini = false)
      |                                       ~~~~~~~~^~~
```

by specifying the proper data type for the `col` parameter of the OldColorButton funtion.

Signed-off-by: 林博仁(Buo-ren, Lin) <Buo.Ren.Lin@gmail.com>
@brlin-tw brlin-tw force-pushed the patch/fix-imvec4-compilation-error branch from d5632b5 to 46ae0dc Compare January 8, 2024 04:58
@brlin-tw brlin-tw marked this pull request as ready for review January 8, 2024 04:59
@brlin-tw
Copy link
Author

brlin-tw commented Jan 8, 2024

@AdrienTD:

The best would have been to use const ImVec4&. This will allow "temporaries" (objects constructed inside a function call argument) to be used. And it would avoid a copy of the entire ImVec4 (though it might be true that in case of temporaries, there is no copy).

Thanks for the guidance, I've updated the branch to include the proper code fix, please review.

@brlin-tw brlin-tw changed the title draft: Fix "cannot bind non-const lvalue reference of type ‘ImVec4&’ to an rvalue of type ‘ImVec4’" compilation error Fix "cannot bind non-const lvalue reference of type ‘ImVec4&’ to an rvalue of type ‘ImVec4’" compilation error Jan 8, 2024
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