build: Only allow ASCII identifiers #19094

pull laanwj wants to merge 1 commits into bitcoin:master from laanwj:2020_05_no_extended_identifiers changing 1 files +3 −0
  1. laanwj commented at 5:37 PM on May 28, 2020: 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.

  2. build: Only allow ASCII identifiers
    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.
    399d84da37
  3. laanwj added the label Build system on May 28, 2020
  4. sipa commented at 6:09 PM on May 28, 2020: 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).

  5. MarcoFalke commented at 6:12 PM on May 28, 2020: 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

  6. MarcoFalke commented at 6:13 PM on May 28, 2020: member

    Sorry, I meant ℭ𝔬𝔫𝔠𝔒𝔭𝔱 π”„β„­π”Ž

  7. laanwj commented at 6:15 PM on May 28, 2020: member

    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.

  8. jonatack commented at 6:44 PM on May 28, 2020: member

    ACK 399d84da3708719b063953107bab0f5f6493ad

    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

  9. MarcoFalke commented at 6:56 PM on May 28, 2020: 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

  10. practicalswift commented at 7:11 PM on May 28, 2020: contributor

    ACK 399d84da3708719b063953107bab0f5f6493addb -- patch looks correct

  11. promag commented at 10:54 PM on May 28, 2020: member

    ACK 399d84da3708719b063953107bab0f5f6493addb.

  12. fanquake approved
  13. fanquake commented at 12:42 AM on May 29, 2020: member

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

  14. fanquake merged this on May 29, 2020
  15. fanquake closed this on May 29, 2020

  16. PastaPastaPasta referenced this in commit 2cc2d87d2d on Sep 17, 2021
  17. PastaPastaPasta referenced this in commit 9b0d6dc9dd on Sep 19, 2021
  18. thelazier referenced this in commit cbc7276b5c on Sep 25, 2021
  19. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me