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

gcc-4.9.x using c++1y - error: call to non-constexpr function #6868

Closed
th0ma7 opened this issue May 19, 2022 · 4 comments
Closed

gcc-4.9.x using c++1y - error: call to non-constexpr function #6868

th0ma7 opened this issue May 19, 2022 · 4 comments

Comments

@th0ma7
Copy link
Contributor

th0ma7 commented May 19, 2022

Please provide the following information

libtorrent version (or branch): using 2.0.6

platform/architecture: any (armv7, v8, ppc, x86_64, i686)

compiler and compiler version: gcc-4.9.4 and gcc-4.9.3

please describe what symptom you see, what you would expect to see instead and
how to reproduce it.

Synology Linux NAS using DSM-v6.x uses an older gcc-4.9.x (while newer DSM-7.x uses gcc-7.5). Issue is only occurring on DSM-6 with older gcc using -std=c++1y option to achieve c++14 "equivalence".

error is the following to which I hope there may be a workaround it for this older compiler c++1y:

../../include/libtorrent/file_storage.hpp:238:78: error: call to non-constexpr function ‘const _Tp& std::min(const _Tp&, const _Tp&) [with _      Tp = long int]’

See full log for more details: build-aarch64-6.1.log

Thnx in advance!

@NotTsunami
Copy link
Contributor

NotTsunami commented May 21, 2022

Changing constexpr to const for the affected line should work (See documentation for [std::min](https://en.cppreference.com/w/cpp/algorithm/min)):

static constexpr std::int64_t max_file_size = (std::min)(
I'm wondering if the issue lies in c++1y being an earlier state of c++14.

See Arvid's comment. It's still a constant expression, this is likely a GCC issue.

@th0ma7
Copy link
Contributor Author

th0ma7 commented May 21, 2022

I created a new v2-gcc49-c++1y branch and gave that a shot:

236                 static const std::int64_t max_file_size = (std::min)(
237                         (std::int64_t(1) << 48) - 1
238                         , std::int64_t((std::numeric_limits<int>::max)() / 2) * default_block_size);

And still getting that same error:

      ../../include/libtorrent/file_storage.hpp:238:78: error: call to non-constexpr function ‘const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = long int]’

My C++ programming are quite far behind me but isn't line 238 , std::int64_t((std::numeric_limits<int>::max)() / 2) * default_block_size); character 78 be right before * ?

EDIT: Just noticed, character 78 closes the (std::min)(

@arvidn
Copy link
Owner

arvidn commented May 21, 2022

the calculation of the constant has to be done at compile time, as a constrexpr value. As I'm sure you can see, that is a constant expression. However, it seems GCC 4.9 had not yet marked min() as a constexpr function. You could implement your own min() that is constexpr in that same header to see if that solves it. But I suspect this is not the only thing preventing libtorrent from building on GCC 4.9

@th0ma7
Copy link
Contributor Author

th0ma7 commented Sep 10, 2022

Closing this issue as I ended-up using libtorent 1.2.x for GCC-4.9+ builds and version 2.x for newer Synology Linux DSM which comes with GCC-7.5. Getting version 2 to build on such old GCC was just too much of a pain (and probably not worth the effort as libtorrent 1.x is still maintained).

Thnx.

@th0ma7 th0ma7 closed this as completed Sep 10, 2022
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

3 participants