Skip to content

Clang-Format misplace '&' character in member function arguments when using [[nodiscard]] attribute on class. #45588

@llvmbot

Description

@llvmbot
Bugzilla Link 46243
Version 10.0
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @mydeveloperday

Extended Description

When using the [[no_discard]] attribute between the class / struct keyword and the type name, the reference '&' will be misplaced in declared member functions taking types references as parameters.

For example, if I have the PointerAlignment attribute set to Left:

struct Toto
{
    Toto(Object& obj);
    void Function(Object& obj1, Object& obj2);
};

when "[[nodiscard]]" is added, becomes:

struct [[nodiscard]] Toto
{
    Toto(Object & obj);
    void Function(Object & obj1, Object & obj2);
};

(note the space between 'Object' and '&').

This bug only happens if 'Object' is not a primitive type (so can be class, a struct, templated or not, an enum, an enum class, an alias), if the reference is not constant, if the function is not an operator (can be a constructor, a member function, a static member function) and if the argument is not put after another argument which is a primitive type, a primitive type reference or any constant type reference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions