[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Fix the handling of the star in pointer to user defined types fo

From: Théo Cavignac
Subject: [PATCH] Fix the handling of the star in pointer to user defined types for parameter declarations.
Date: Mon, 29 Mar 2021 16:58:49 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1


I would like to submit a small patch to fix a bug I noticed in the handling of the pointer star in parameter declaration.

Since indent don't detect user-defined types at lexing time, the eventual star following such a type is considered to be a binary operator.

As a consequence the formatting is off when it comes to aligning the star on the left (or the right depending on the options.)

For example:

    void f(char * s);

    void g(custom_type * p);

Would become:

    void f (char *s);

    void g (custom_type * p);

with `indent -npro -par`

My patch simply detect that a `*` is being handled as a binary operator in a parameter definition and redirect to the unary operator handler.

It thus provide the expected output:

    void f(char *s);

    void g(custom_type *p);

If you use a lot of typedef as I do and want to fully rely on indent to keep style homogeneous, this small change is very welcome.

I added a regression test named `custom-type-pointer.c`. It tests for function declarations and prototypes, and also check that actual multiplications are not affected.

I had to modify the test `bug-gnu-33364.c` reference because my solution work by trusting `in_decl` which is broken in that test.

Maybe this patch can be useful to others.


Théo Cavignac

PS: I never submitted any patch through a mailing list, hopefully I did everything right.

Attachment: patch
Description: Text document

reply via email to

[Prev in Thread] Current Thread [Next in Thread]