Skip to content

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

Closed
llvm/llvm-project-release-prs
#607
@joeatodd

Description

@joeatodd

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions