llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.92k stars 11.52k forks source link

ClangCL can't use UDL with /std:c++latest #39895

Open steveire opened 5 years ago

steveire commented 5 years ago
Bugzilla Link 40549
Version trunk
OS Windows NT
CC @efriedma-quic,@zygoloid,@rnk

Extended Description

This occurs while trying to implement a user-defined literal. Attempting to compile code without char8_t and with

A a2 = u8"\u4F60\u597D"_sv;

results in

u8.cpp(24,28): error: no matching literal operator for call to 'operator""_sv' with arguments of types 'const char8_t *' and 'unsigned long long', and no matching literal operator template A a2 = u8"\u4F60\u597D"_sv;

Trying to add an overload with char8_t results in:

u8.cpp(10,1): error: cannot mangle this built-in char8_t type yet A operator "" _sv(const char8_t* str, INT len) ^~~~~~~~~~ 1 error generated.

So, currently UDL can't be used with /std:c++latest

struct A { A() {} };

define INT unsigned long long

ifdef TRY_U8

A operator "" _sv(const char8_t* str, INT len) { return A{}; }

endif

A operator "" _sv(const char* str, INT len) { return A{}; }

int main() { A a1 = "hello"_sv;

ifdef TRY_U8

A a2 = u8"\u4F60\u597D"_sv;

endif

}

ec04fc15-fa35-46f2-80e1-5d271f2ef708 commented 5 years ago

This doesn't affect all UDLs; only 'u8' UDLs are a problem. This is happening because u8 character and string literals changed type (from char to char8_t) in C++20, and we don't yet know what mangling MS is going to give the type char8_t.