The following code appears to be valid C ++, adopted by all major compilers:
#include <string> #include <iostream> auto main() -> int { using namespace std::string_literals; std::cout << "Hello"s.length(); }
Below, however, both versions of trunk Clang and GCC are rejected (when adopting 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 problem string to (42s).count() or 42s .count() fixes the problem. A similar situation arises with complex UDLs (again, Clang and GCC rejected by VC reject):
#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 an error parsing whole literals in Clang and GCC?
c ++ c ++ 14 grammar user-defined-literals compiler-bug
Andy prowl
source share