Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

clang-format can introduce */ outside of comment, rejected by some compilers #51494

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR52527
Status CONFIRMED
Importance P enhancement
Reported by Peter Dillinger (peterd@fb.com)
Reported on 2021-11-16 12:33:49 -0800
Last modified on 2021-11-18 00:05:56 -0800
Version 12.0
Hardware All All
CC dblaikie@gmail.com, djasper@google.com, klimek@google.com, llvm-bugs@lists.llvm.org, mydeveloperday@gmail.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
When I use clang-format-diff.py on this:

void Foo(void (* /*fn*/)()) {}

I get this:

void Foo(void (*/*fn*/)()) {}

Which is rejected by MSVC at least under some configurations and versions.

Context:
https://app.circleci.com/pipelines/github/facebook/rocksdb/10051/workflows/cef8bc6a-faa4-45bd-9821-7fdc483985fb/jobs/241183

c:\users\circleci\project\db\db_block_cache_test.cc(395): warning C4138: '*/'
found outside of comment
c:\users\circleci\project\db\db_block_cache_test.cc(395): error C2220: warning
treated as error - no 'object' file generated

My work-around:
https://github.com/pdillinger/rocksdb/commit/c9885d2614d664f331cd998038e8e8f94a847d92
Quuxplusone commented 3 years ago
This is a bug I think, we need to add a space between the * and the /* block
comment.

I think we can fix this by adding

  if (Left.is(tok::star) && Right.is(TT_BlockComment))
    return true;

to

bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
                                         const FormatToken &Right);
Quuxplusone commented 3 years ago

Possible fix

https://reviews.llvm.org/D114142