Skip to content

[clang-format] incorrect formatting of type trait in assigment #132248

@stmuench

Description

@stmuench

$ cat bug.cpp

#include <cstdint>
#include <type_traits>

namespace foo
{

enum class TypeKind : std::uint8_t
{
    KindA = 0,
    KindB
};

constexpr auto kTypeKind =
#ifdef TYPE_KIND_A
    TypeKind::KindA;
#else
    TypeKind::KindB;
#endif

namespace detail
{
constexpr auto kBpfMtu = 1512;
constexpr auto kIoSockMtu = 1518;

constexpr std::uint16_t kMTU = std::conditional<kTypeKind == TypeKind::KindA,
                                                std::integral_constant<std::uint16_t, kBpfMtu>,
                                                std::integral_constant<std::uint16_t, kIoSockMtu>>::type::value;
}  // namespace detail

}  // namespace foo

run: clang-format bug.cpp

expected would be something like:

constexpr std::uint16_t kMTU = std::conditional<kTypeKind == TypeKind::KindA,
                                                std::integral_constant<std::uint16_t, kBpfMtu>,
                                                std::integral_constant<std::uint16_t, kIoSockMtu>>::type::value;

actual formatting:

constexpr std::uint16_t kMTU = std::conditional < kTypeKind == TypeKind::KindA,
                        std::integral_constant<std::uint16_t, kBpfMtu>,
                        std::integral_constant < std::uint16_t,
                        kIoSockMtu >> ::type::value;

Worked fine with clang-format-18.
Occurs for clang-format-19 and 20.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions