Is there an error with parser access expressions in a user-defined integer literal in Clang and GCC?

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?

+7
c ++ c ++ 14 grammar user-defined-literals compiler-bug
source share

No one has answered this question yet.

See similar questions:

eleven
Compilation error when using a user literal member

or similar:

49
Benefits of using a custom literal for strings instead of a string literal
23
Ambiguous Member Access Expression: Is Klang Rejecting Valid Code?
thirteen
C ++ 17: function of explicit conversion versus explicit constructor + implicit conversions - have the rules changed?
12
How to declare a function whose return type is inferred?
eleven
Initialization of the static data member constexpr of the base class using the static data member constexpr of the derived class
eleven
Deduction guides, templates, and subobjects: which compiler is right?
4
Brackets and non-character template arguments in C ++ 14
4
Constexpr error in clang but not in gcc?
0
C ++: Is this a clang namespace leak error?
-2
Why is this code not working? The output does not print

All Articles