This is an archive of the discontinued LLVM Phabricator instance.

[clang-format][regression][PR47461] ifdef causes catch to be seen as a function
ClosedPublic

Authored by MyDeveloperDay on Sep 8 2020, 9:07 AM.

Details

Summary

https://bugs.llvm.org/show_bug.cgi?id=47461

The following change D80940: [clang-format] [PR46159] Linux kernel 'C' code uses 'try' as a variable name, allow clang-format to handle such cases caused a regression in code which ifdef's around the try and catch block cause incorrect brace placement around the catch

#ifdef NO_EXCEPTIONS
  try
#endif
  {
  }
#ifdef NO_EXCEPTIONS
  catch (...) {
    // This is not a small function
    bar = 1;
  }
#endif
}

The brace after the catch will be placed on a newline

Diff Detail

Event Timeline

MyDeveloperDay requested review of this revision.Sep 8 2020, 9:07 AM
MyDeveloperDay created this revision.

Note to self, other things could cause the same issue

try // comment
{
try /* comment */
{

Minimize other places where try could be incorrectly seen as an identifier

try // foo 
{

or

try /* foo */

LGTM.
Don't we risk any other side effects?

curdeius accepted this revision.Sep 17 2020, 2:16 AM
This revision is now accepted and ready to land.Sep 17 2020, 2:16 AM

LGTM.
Don't we risk any other side effects?

There could be, but maybe we can address them as we see them.

The original reason for including this was so that the Linux kernel could use try as a variable, I'm trying not to break that but I'm not convinced that

int try /* abc */ = 0;

would consider try as a variable any more. my hope is they don't do that..