This is an archive of the discontinued LLVM Phabricator instance.

clang-format: Support `if CONSTEXPR` if CONSTEXPR is a macro.
ClosedPublic

Authored by thakis on Jul 24 2019, 10:28 AM.

Details

Summary

This is like r305666 (which added support for if constexpr) except
that it allows a macro name after the if.

This is slightly tricky for two reasons:

  1. r305666 didn't add test coverage for all cases where it added a kw_constexpr, so I had to figure out what all the added cases were for. I now added tests for all if constexpr bits that didn't have tests. (This took a while, see e.g. https://reviews.llvm.org/D65223)
  1. Parsing if <ident> ( as an if means that #if defined( and #if __has_include( parse as ifs too. Add some special-case code to prevent this from happening where it's incorrect.

Fixes PR39248.

Diff Detail

Event Timeline

thakis created this revision.Jul 24 2019, 10:28 AM
thakis edited the summary of this revision. (Show Details)Jul 24 2019, 10:36 AM
thakis edited the summary of this revision. (Show Details)
klimek accepted this revision.Jul 25 2019, 5:17 PM

I am surprised this works as well as it does, but tests seem to indicate it does, so... LG (minus potentially reducing some duplication :)

clang/lib/Format/TokenAnnotator.cpp
2415

Do we want to pull out a function for the repeated condition?

This revision is now accepted and ready to land.Jul 25 2019, 5:17 PM
thakis marked an inline comment as done.Jul 26 2019, 7:39 PM

Thanks, landing with your suggestion applied.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2019, 7:41 PM