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

DecimalUtil.cpp compilation failure #11358

Open
Super-long opened this issue Oct 28, 2024 · 1 comment
Open

DecimalUtil.cpp compilation failure #11358

Super-long opened this issue Oct 28, 2024 · 1 comment
Labels
build triage Newly created issue that needs attention.

Comments

@Super-long
Copy link

Problem description

I tried to compile velox using bazel(3.7.1).

From the bazel log, DecimalUtil.h:365 line calls std::to_chars with input parameter type (char*&, char*, facebook::velox::uint128_t&)
using uint128_t = __uint128_t;

I looked up https://en.cppreference.com/w/cpp/utility/to_chars
and found that the third argument to std::to_chars does not support __uint128_t, which also means that implicit type conversion occurs, but too many convertible types leads to mutation errors, and both 10.2 and 11.2 compile with errors, which is as expected, since neither of the charconv files has an overload for __uint128_t, as opposed to the cppreference documentation.

How should the code here compile through?

System information

tlinux is centos-compatible.

Velox System Info v0.0.2
Commit: eaff500
CMake Version: 2.8.12
System: Linux-3.10.107-1-tlinux2_kvm_guest-0056
Arch: x86_64
C++ Compiler: /opt/rh/devtoolset-10/root/usr/bin/c++
C++ Compiler Version: 10.2.1
C Compiler: /opt/rh/devtoolset-10/root/usr/bin/cc
C Compiler Version: 10.2.1
CMake Prefix Path: /usr/local;/usr;/;/usr;/usr/local

CMake log

In file included from external/velox/velox/type/DecimalUtil.cpp:17:
external/velox/velox/type/DecimalUtil.h: In static member function 'static size_t facebook::velox::DecimalUtil::castToString(T, int32_t, int32_t, char*)':
external/velox/velox/type/DecimalUtil.h:366:75: error: call of overloaded 'to_chars(char*&, char*, facebook::velox::uint128_t&)' is ambiguous
  366 |             std::to_chars(writePosition, writePosition + maxSize, fraction);
      |                                                                           ^
In file included from external/velox/velox/type/DecimalUtil.h:19,
                 from external/velox/velox/type/DecimalUtil.cpp:17:
/opt/rh/devtoolset-10/root/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/charconv:366:1: note: candidate: 'std::to_chars_result std::to_chars(char*, char*, char, int)'
  366 | _GLIBCXX_TO_CHARS(char)
      | ^~~~~~~~~~~~~~~~~
/opt/rh/devtoolset-10/root/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/charconv:367:1: note: candidate: 'std::to_chars_result std::to_chars(char*, char*, signed char, int)'
  367 | _GLIBCXX_TO_CHARS(signed char)
      | ^~~~~~~~~~~~~~~~~
/opt/rh/devtoolset-10/root/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/charconv:368:1: note: candidate: 'std::to_chars_result std::to_chars(char*, char*, unsigned char, int)'
  368 | _GLIBCXX_TO_CHARS(unsigned char)
      | ^~~~~~~~~~~~~~~~~
/opt/rh/devtoolset-10/root/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/charconv:369:1: note: candidate: 'std::to_chars_result std::to_chars(char*, char*, short int, int)'
  369 | _GLIBCXX_TO_CHARS(signed short)
      | ^~~~~~~~~~~~~~~~~
/opt/rh/devtoolset-10/root/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/charconv:370:1: note: candidate: 'std::to_chars_result std::to_chars(char*, char*, short unsigned int, int)'
  370 | _GLIBCXX_TO_CHARS(unsigned short)
      | ^~~~~~~~~~~~~~~~~
/opt/rh/devtoolset-10/root/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/charconv:371:1: note: candidate: 'std::to_chars_result std::to_chars(char*, char*, int, int)'
  371 | _GLIBCXX_TO_CHARS(signed int)
      | ^~~~~~~~~~~~~~~~~
/opt/rh/devtoolset-10/root/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/charconv:372:1: note: candidate: 'std::to_chars_result std::to_chars(char*, char*, unsigned int, int)'
  372 | _GLIBCXX_TO_CHARS(unsigned int)
      | ^~~~~~~~~~~~~~~~~
/opt/rh/devtoolset-10/root/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/charconv:373:1: note: candidate: 'std::to_chars_result std::to_chars(char*, char*, long int, int)'
  373 | _GLIBCXX_TO_CHARS(signed long)
      | ^~~~~~~~~~~~~~~~~
/opt/rh/devtoolset-10/root/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/charconv:374:1: note: candidate: 'std::to_chars_result std::to_chars(char*, char*, long unsigned int, int)'
  374 | _GLIBCXX_TO_CHARS(unsigned long)
      | ^~~~~~~~~~~~~~~~~
/opt/rh/devtoolset-10/root/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/charconv:375:1: note: candidate: 'std::to_chars_result std::to_chars(char*, char*, long long int, int)'
  375 | _GLIBCXX_TO_CHARS(signed long long)
      | ^~~~~~~~~~~~~~~~~
/opt/rh/devtoolset-10/root/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/charconv:376:1: note: candidate: 'std::to_chars_result std::to_chars(char*, char*, long long unsigned int, int)'
  376 | _GLIBCXX_TO_CHARS(unsigned long long)
      | ^~~~~~~~~~~~~~~~~
/opt/rh/devtoolset-10/root/usr/lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/charconv:397:19: note: candidate: 'std::to_chars_result std::to_chars(char*, char*, bool, int)' (deleted)
  397 |   to_chars_result to_chars(char*, char*, bool, int = 10) = delete;
      |                   ^~~~~~~~
external/velox/velox/type/DecimalUtil.cpp: In static member function 'static int32_t facebook::velox::DecimalUtil::toByteArray(facebook::velox::int128_t, char*)':
external/velox/velox/type/DecimalUtil.cpp:81:14: warning: comparison of integer expressions of different signedness: 'int32_t' {aka 'int'} and 'long unsigned int' [-Wsign-compare]
   81 |   if (length <= sizeof(int64_t)) {
@Super-long Super-long added build triage Newly created issue that needs attention. labels Oct 28, 2024
@Super-long
Copy link
Author

Super-long commented Oct 28, 2024

#include <charconv>
#include <iostream>
#include <array>


void show_to_chars(auto... format_args)
{
    const size_t buf_size = 10;
    char buf[buf_size]{};
    std::to_chars_result result = std::to_chars(buf, buf + buf_size, format_args...);
 
    if (result.ec != std::errc())
        std::cout << std::make_error_code(result.ec).message() << '\n';
    else
    {
        std::string_view str(buf, result.ptr - buf);
        std::cout << str << '\n';
    }
}

int main() {
    __int128 num = static_cast<__int128>(1234567890123456789LL) * 1000000000000000000LL + 987654321098765432LL;
    show_to_chars(42);
    show_to_chars(+3.14159F);
    show_to_chars(-3.14159, std::chars_format::fixed);
    show_to_chars(num);


    return 0;
}

Such code would report the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build triage Newly created issue that needs attention.
Projects
None yet
Development

No branches or pull requests

1 participant