Skip to content
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

Building fails with "error: lvalue required as increment operand" #4129

Closed
nlsweet opened this issue Aug 27, 2024 · 8 comments
Closed

Building fails with "error: lvalue required as increment operand" #4129

nlsweet opened this issue Aug 27, 2024 · 8 comments

Comments

@nlsweet
Copy link

nlsweet commented Aug 27, 2024

Compiler is gcc 8.3.1

Can reproduce on godbolt with this code:

#include "fmt/format.h"

int main() {
  char buffer[4];
  auto result = fmt::format_to(buffer, "{}", 12345);

}

Output on godbolt:

In file included from /opt/compiler-explorer/libs/fmt/trunk/include/fmt/format.h:41,
                 from <source>:2:
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/base.h: In instantiation of 'struct fmt::v11::detail::is_output_iterator<char [4], char, void>':
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/base.h:3025:11:   required by substitution of 'template<class OutputIt, class ... T, typename std::enable_if<fmt::v11::detail::is_output_iterator<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type, char>::value, int>::type <anonymous> > fmt::v11::remove_cvref_t<T> fmt::v11::format_to(OutputIt&&, fmt::v11::format_string<T ...>, T&& ...) [with OutputIt = char (&)[4]; T = {int}; typename std::enable_if<fmt::v11::detail::is_output_iterator<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type, char>::value, int>::type <anonymous> = <missing>]'
<source>:6:51:   required from here
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/base.h:1583:48: error: lvalue required as increment operand
     It, T, void_t<decltype(*std::declval<It&>()++ = std::declval<T>())>>
                             ~~~~~~~~~~~~~~~~~~~^~
/opt/compiler-explorer/libs/fmt/trunk/include/fmt/base.h:1583:48: error: lvalue required as increment operand
Compiler returned: 1

We discovered this issue when trying to build the fmt package after cloning the repo from github. After cloning, mkdir build && cd build && cmake .. && make

Output from this:

[ 16%] Building CXX object test/CMakeFiles/base-test.dir/base-test.cc.o
In file included from /home/nlsweet/external/fmt/test/base-test.cc:12:
/home/nlsweet/external/fmt/include/fmt/base.h: In instantiation of ‘struct fmt::v11::detail::is_output_iterator<char [4], char, void>’:
/home/nlsweet/external/fmt/include/fmt/base.h:2936:11:   required by substitution of ‘template<class OutputIt, class ... T, typename std::enable_if<fmt::v11::detail::is_output_iterator<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type, char>::value, int>::type <anonymous> > fmt::v11::remove_cvref_t<T> fmt::v11::format_to(OutputIt&&, fmt::v11::format_string<T ...>, T&& ...) [with OutputIt = char (&)[4]; T = {int}; typename std::enable_if<fmt::v11::detail::is_output_iterator<typename std::remove_cv<typename std::remove_reference<_Tp>::type>::type, char>::value, int>::type <anonymous> = <missing>]’
/home/nlsweet/external/fmt/test/base-test.cc:729:51:   required from here
/home/nlsweet/external/fmt/include/fmt/base.h:1576:48: error: lvalue required as increment operand
     It, T, void_t<decltype(*std::declval<It&>()++ = std::declval<T>())>>
                             ~~~~~~~~~~~~~~~~~~~^~
/home/nlsweet/external/fmt/include/fmt/base.h:1576:48: error: lvalue required as increment operand
make[2]: *** [test/CMakeFiles/base-test.dir/build.make:76: test/CMakeFiles/base-test.dir/base-test.cc.o] Error 1
@vitaut
Copy link
Contributor

vitaut commented Aug 27, 2024

Please provide an actual godbolt link.

@nlsweet
Copy link
Author

nlsweet commented Aug 27, 2024

Godbolt

@Arghnews
Copy link
Contributor

Arghnews commented Aug 27, 2024

Godbolt

As a workaround, change to &buffer[0] or static_cast<char*>(buffer) there it works fine
@nlsweet

@nlsweet
Copy link
Author

nlsweet commented Aug 27, 2024

Well, that fixes the example on Godbolt, but base-test.cc (and probably other tests) is still broken when applying that change:

[ 16%] Building CXX object test/CMakeFiles/base-test.dir/base-test.cc.o
In file included from /home/nlsweet/external/fmt/test/test-assert.h:17,
                 from /home/nlsweet/external/fmt/test/base-test.cc:9:
/home/nlsweet/external/fmt/test/base-test.cc: In member function ‘virtual void base_test_format_to_array_Test::TestBody()’:
/home/nlsweet/external/fmt/test/base-test.cc:724:49: error: request for member ‘out’ in ‘result’, which is of non-class type ‘char*’
   EXPECT_EQ(4, std::distance(&buffer[0], result.out));
                                                 ^~~
In file included from /home/nlsweet/external/fmt/test/test-assert.h:17,
                 from /home/nlsweet/external/fmt/test/base-test.cc:9:
/home/nlsweet/external/fmt/test/base-test.cc:725:22: error: request for member ‘truncated’ in ‘result’, which is of non-class type ‘char*’
   EXPECT_TRUE(result.truncated);
                      ^~~~~~~~~
In file included from /home/nlsweet/external/fmt/test/test-assert.h:17,
                 from /home/nlsweet/external/fmt/test/base-test.cc:9:
/home/nlsweet/external/fmt/test/base-test.cc:726:32: error: request for member ‘out’ in ‘result’, which is of non-class type ‘char*’
   EXPECT_EQ(buffer + 4, result.out);

@phprus
Copy link
Contributor

phprus commented Aug 27, 2024

This is gcc 8.1 - 8.3 bug.
Works on gcc < 8 or gcc >= 8.4:

https://godbolt.org/z/d11h3zqMq

@nlsweet
Copy link
Author

nlsweet commented Aug 27, 2024

And yet those tests built and ran fine through the 10.2 releases.

Are you suggesting that {fmt} isn't as portable as claimed?

Arghnews added a commit to Arghnews/fmt that referenced this issue Aug 27, 2024
@Arghnews
Copy link
Contributor

@nlsweet I've put in a fix in #4131 that I've tested and now works on gcc 8.3.0, should fix it for you too

@nlsweet
Copy link
Author

nlsweet commented Aug 27, 2024

All tests built and ran (and passed). Thank you, @Arghnews

Arghnews added a commit to Arghnews/fmt that referenced this issue Aug 28, 2024
vitaut pushed a commit that referenced this issue Aug 28, 2024
@vitaut vitaut closed this as completed Aug 28, 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

No branches or pull requests

4 participants