This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Fix template arguments in macros
ClosedPublic

Authored by sstwcw on Sep 15 2022, 9:39 AM.

Details

Summary

Fixes https://github.com/llvm/llvm-project/issues/57738

old

#define FOO(typeName, realClass)                               \
  {                                                            \
#typeName, foo < FooType>(new foo <realClass>(#typeName))  \
  }

new

#define FOO(typeName, realClass)                                \
  { #typeName, foo<FooType>(new foo<realClass>(#typeName)) }

Previously, when an UnwrappedLine began with a hash in a macro
definition, the program incorrectly assumed the line was a preprocessor
directive. It should be stringification.

The rule in spaceRequiredBefore was added in 8b5297117b. Its purpose is
to add a space in an include directive. It also added a space to a
template opener when the line began with a stringification hash. So we
changed it.

Diff Detail

Event Timeline

sstwcw created this revision.Sep 15 2022, 9:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 15 2022, 9:39 AM
sstwcw requested review of this revision.Sep 15 2022, 9:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 15 2022, 9:39 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
sstwcw added a project: Restricted Project.Sep 15 2022, 9:42 AM
This revision is now accepted and ready to land.Sep 15 2022, 12:45 PM
owenpan accepted this revision.Sep 15 2022, 8:07 PM
owenpan added inline comments.
clang/unittests/Format/FormatTest.cpp
9803–9805

And perhaps move it to the end of the test.

This revision was automatically updated to reflect the committed changes.