llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-format] version 17 trips up on templated base class uniform initialization.

Open joeatodd opened this issue 3 years ago • 11 comments

Running clang-format test.cpp (i.e. default style rules) with version 17 on the following reproducer:

template <int Dim>
struct Base{};

template <int Dim>
struct Derived : public Base<Dim>{

  Derived() : Base<Dim>{} {
    // Derived ctor impl
  }
};

produces:

template <int Dim> struct Base {};

template <int Dim> struct Derived : public Base<Dim> {

  Derived() : Base<Dim> {}
  {
    // Derived ctor impl
  }
};

but it ought to produce:

template <int Dim> struct Base {};

template <int Dim> struct Derived : public Base<Dim> {

  Derived() : Base<Dim>{} {
    // Derived ctor impl
  }
};

Version 16 produces this correct output.

I played around with this reproducer a little. I think its the combination of the <Dim> template argument and the {} uniform initialization of the derived class which is confusing clang-format. Removing the former or replacing the latter with () produces expected output.

Both the versions mentioned here are from the downstream DPC++ project: Working: clang-format version 17.0.0 (https://github.com/intel/llvm.git 21ca00fb1cc5408b2428e3c386aa5137ed551fdb) Broken: clang-format version 16.0.0 (https://github.com/intel/llvm.git 751acf357ed192a2f9de5171ccdf4a69510cff37)

joeatodd avatar Jul 26 '23 18:07 joeatodd

@llvm/issue-subscribers-clang-format

llvmbot avatar Jul 26 '23 19:07 llvmbot

I've bisected this to 6dcde658b2380d7ca1451ea5d1099af3e294ea16

rymiel avatar Jul 26 '23 21:07 rymiel

I've submitted a fix for review here: https://reviews.llvm.org/D156705

Sorry for the regression!

galenelias avatar Aug 01 '23 20:08 galenelias

/cherry-pick

owenca avatar Aug 16 '23 06:08 owenca

/cherry-pick 0a6c271

@owenca for next time - you need to specify the sha or multiple sha's with the command.

tru avatar Aug 18 '23 07:08 tru

Failed to cherry-pick: 0a6c271

https://github.com/llvm/llvm-project/actions/runs/5900206633

Please manually backport the fix and push it to your github fork. Once this is done, please add a comment like this:

/branch <user>/<repo>/<branch>

llvmbot avatar Aug 18 '23 08:08 llvmbot

/cherry-pick 400da11

owenca avatar Aug 18 '23 08:08 owenca

/cherry-pick 0a6c271

@owenca for next time - you need to specify the sha or multiple sha's with the command.

Oops! Thanks for pointing out. Fixed above.

owenca avatar Aug 18 '23 08:08 owenca

/branch llvm/llvm-project-release-prs/issue64134

llvmbot avatar Aug 18 '23 08:08 llvmbot

Failed to cherry-pick: 0a6c271

https://github.com/llvm/llvm-project/actions/runs/5900335578

Please manually backport the fix and push it to your github fork. Once this is done, please add a comment like this:

/branch <user>/<repo>/<branch>

llvmbot avatar Aug 18 '23 08:08 llvmbot

/pull-request llvm/llvm-project-release-prs#607

llvmbot avatar Aug 18 '23 08:08 llvmbot