Skip to content

Clang format produces code which does not compile with clang #151102

@SamCoutteauHybrid

Description

@SamCoutteauHybrid

When using the clang-format options:

IntegerLiteralSeparator:
  BinaryMinDigits: 16
  Binary: 8
  Decimal: 3
  DecimalMinDigits: 6
  Hex: 2
  HexMinDigits: 8

To insert decimal separators it can produce the following code.

#if __cpp_lib_source_location < 201'907L

where a decimal separator is added in the preprocessor constant.

It seems clang cannot compile this unless at least c++14 is used.

https://godbolt.org/z/f1zYWd778

However even when setting:

Standard: c++11 

clang format still adds the decimal separator.

Further more

#if __cpp_lib_source_location < 201'907L
#endif

works using:

  • clang -std=c++14 -E test.hpp

does not work using

  • clang -std=c++11 -E test.hpp
  • clang-scan-deps -format=p1689 -- clang -std=c++14 test.hpp

So it seems clang-format is producing wrong results and clang-scan-deps is ignoring -std=c++14

Metadata

Metadata

Assignees

Labels

clang-formatinvalid-code-generationTool (e.g. clang-format) produced invalid code that no longer compiles

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions