Skip to content

build: Only allow ASCII identifiers - #19094

Merged
fanquake merged 1 commit into
bitcoin:masterfrom
laanwj:2020_05_no_extended_identifiers
May 29, 2020
Merged

fanquake merged 1 commit into
bitcoin:masterfrom
laanwj:2020_05_no_extended_identifiers

Conversation

@laanwj

@laanwj laanwj commented May 28, 2020

Copy link
Copy Markdown
Member

While emoji and other symbols in C++ identifers (as accepted by newer compilers) are fun, they might create confusion during code review, for example because some symbols look very similar. Forbid such extended identifiers for now.

This is done by providing -fno-extended-identifiers. Thanks to sipa for suggesting this compiler flag.

While emoji and other symbols in C++ identifers (as accepted by newer
compilers) are fun, they might create confusion during code review, for
example because some symbols look very similar. Forbid such extended
identifiers for now.

This is done by providing `-fno-extended-identifiers`. Thanks to sipa
for suggesting this compiler flag.
@sipa

sipa commented May 28, 2020

Copy link
Copy Markdown
Member

ACK, though as long as we have at least a GCC before 10.0 in our CI, such identifiers won't work regardless.

Note that this flag also does not exist for clang (which seems to have no way of disallowing such identifiers, or non-ascii input in general).

@maflcko

maflcko commented May 28, 2020 •

Copy link
Copy Markdown
Member

Concept ACK. The same is enforced for the python functional tests (emojis in symbol names are not allowed by python, but strings may contain arbitrary utf-8 characters).

Edit: It looks like python3 does allow some non-ascii unicode: https://docs.python.org/3/reference/lexical_analysis.html#identifiers

@maflcko

maflcko commented May 28, 2020

Copy link
Copy Markdown
Member

Sorry, I meant ℭ𝔬𝔫𝔠𝔢𝔭𝔱 𝔄ℭ𝔎

@laanwj

laanwj commented May 28, 2020

Copy link
Copy Markdown
Member Author

ACK, though as long as we have at least a GCC before 10.0 in our CI, such identifiers won't work regardless.

You're right with regard to CI. Then it's mostly useful for people developing locally, I suppose. I tend to prefer problems being flagged while compiling locally to having to PR and wait for travis to fail.

@jonatack jonatack left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 399d84d

sanity check that -fno-extended-identifiers was not present in build configure on master and is present in this branch

checking whether C++ compiler accepts -fno-extended-identifiers... yes

  CC            = /usr/bin/ccache gcc
  CFLAGS        = -g -O2
  CPPFLAGS      =   -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2  -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS
  CXX           = /usr/bin/ccache g++ -std=c++11
  CXXFLAGS      =   -fstack-reuse=none -Wstack-protector -fstack-protector-all
                    -Wall -Wextra -Wformat -Wvla -Wswitch -Wredundant-decls
                    -Wunused-variable -Wdate-time -Wsign-compare
                    -Wno-unused-parameter -Wno-implicit-fallthrough  
                    -g -O2 -fno-extended-identifiers
  LDFLAGS       = -pthread  -Wl,-z,relro -Wl,-z,now -pie  
  ARFLAGS       = cr

edit: gcc version 8.3.0 on debian

@maflcko

maflcko commented May 28, 2020

Copy link
Copy Markdown
Member

The gcc 10 release notes kindly include an example to test against https://gcc.gnu.org/gcc-10/changes.html

gcc 10:

scheduler.cpp:74:18: error: stray ‘\317’ in program
   74 | static const int π = 3;
      |                  ^
scheduler.cpp:75:11: error: stray ‘\303’ in program
   75 | int get_naïve_pi() {
      |           ^
scheduler.cpp:76:10: error: stray ‘\317’ in program
   76 |   return π;
      |          ^
scheduler.cpp:74:21: error: expected unqualified-id before ‘=’ token
   74 | static const int π = 3;
      |                    ^
scheduler.cpp:75:13: error: expected initializer before ‘ve_pi’
   75 | int get_naïve_pi() {
      |            ^~~~~

clang 10: compiles emoji and utf-8 without warning

@practicalswift

Copy link
Copy Markdown
Contributor

ACK 399d84d -- patch looks correct

@promag

promag commented May 28, 2020

Copy link
Copy Markdown
Contributor

ACK 399d84d.

@fanquake fanquake left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 399d84d - seems like a good sanity check to enable.

@fanquake
fanquake merged commit fc1fb4d into bitcoin:master May 29, 2020
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 19, 2021
399d84d build: Only allow ASCII identifiers (Wladimir J. van der Laan)

Pull request description:

  While emoji and other symbols in C++ identifers (as accepted by newer compilers) are fun, they might create confusion during code review, for example because some symbols look very similar. Forbid such extended identifiers for now.

  This is done by providing `-fno-extended-identifiers`. Thanks to sipa for suggesting this compiler flag.

ACKs for top commit:
  practicalswift:
    ACK 399d84d -- patch looks correct
  promag:
    ACK 399d84d.
  jonatack:
    ACK 399d84d
  fanquake:
    ACK 399d84d - seems like a good sanity check to enable.

Tree-SHA512: 62bfbe8c7e0284ed505c2c8789c1ae74997202d90595f298c2ee1917e5d69fa9b7196a9404ba2cff61f3162b2bbb5616a1591bed3f0534c58617e22009291933
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants