2019-01-04 11:21发布

3条回答
Evening l夕情丶
2楼-- · 2019-01-04 11:32

This is a known bug in GCC: Bug 67224 - UTF-8 support for identifier names in GCC.

The bug report is from 2015 and has a rather long discussion. At some point, it mentions that "There doesn't seem to be sufficient demand for this feature so that companies fund it or volunteers step up to implement it."

So if you found this StackOverflow topic looking for a solution, you might want to add to the discussion over there to show that there is, in fact, demand.

查看更多
Luminary・发光体
3楼-- · 2019-01-04 11:42

As of 4.8, gcc does not support characters outside of the BMP used as identifiers. It seems to be an unnecessary restriction. Also, gcc only supports a very restricted set of character described in ucnid.tab, based on C99 and C++98 (it is not updated to C11 and C++11 yet, it seems).

As described in the manual, -fextended-identifiers is experimental, so it has a higher chance won't work as expected.


Edit:

GCC supported the C11 character set starting from 4.9.0 (svn r204886 to be precise). So OP's second piece of code using \U0001F603 does work. I still can't get the actual code using

查看更多
做自己的国王
4楼-- · 2019-01-04 11:58

However, the standard specifically allows characters from the range 10000-1FFFD in Annex E.1 and doesn't disallow it as an initial character in E.2.

One thing to keep in mind is that just because the C++ standard allows (or disallows) some feature, does not necessarily mean that your compiler supports (or doesn't support) that feature.

查看更多
登录 后发表回答