7

The following code appears to be valid C++, accepted by all major compilers:

#include <string>
#include <iostream>

auto main()
    -> int
{
    using namespace std::string_literals;
    std::cout << "Hello"s.length();
}

The following, however, is rejected by both trunk versions of Clang and GCC (while being accepted by VC14):

#include <chrono>
#include <iostream>

auto main()
    -> int
{
    using namespace std::chrono_literals;
    std::cout << 42s.count(); // COMPILER ERROR HERE WITH CLANG AND GCC
}

Changing the problematic line to (42s).count() or 42s .count() fixes the problem. A similar situation occurs with complex UDLs (again, rejected by Clang and GCC, accepted by VC):

#include <complex>
#include <iostream>

auto main()
    -> int
{
    using namespace std::complex_literals;
    std::cout << 42i.imag(); // COMPILER ERROR HERE WITH CLANG AND GCC
}

Is there a bug with parsing integer literals in Clang and GCC?

Andy Prowl
  • 124,023
  • 23
  • 387
  • 451

0 Answers0