Bug 498475 - CDT formatter not handling bool
Summary: CDT formatter not handling bool
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-editor (show other bugs)
Version: 8.8.1   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-26 05:01 EDT by John Anderson CLA
Modified: 2020-09-04 15:16 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Anderson CLA 2016-07-26 05:01:09 EDT
Formatter->Line Wrapping->Function calls is configured to 'Wrap only when necessary' and 'indent on column'.

Line Width is set to 80 characters.

When the formatter is applied to a function prototype, similar to the following, it wraps as expected e.g.

static uint16_t validateMessage (uint16_t numBytes, uint8_t * pMsg,
                                 bool ignoreSeq);

When the formatter is applied for a second time the bool part of the prototype is then aligned to column 1 e.g. 

static uint16_t validateMessage (uint16_t numBytes, uint8_t * pMsg,
bool ignoreSeq);

The workaround is to define a new type e.g. BOOL_t and use this throughout the code rather than bool. Formatting is then retained on subsequent formats.
Comment 1 Nathan Ridge CLA 2016-07-26 13:33:15 EDT
I can't reproduce this problem. I get the initial result you describe, and then it stays that way.

Is this a C++ project or a C project?
Comment 2 John Anderson CLA 2016-07-27 02:21:48 EDT
Hi Nathan,

Yes this is a C project.
I tried this in Luna in Windows. I did not have quick keys enabled and so used the Source->Format menu to reformat this snippet. This did not exhibit this problem.

Then I set Ctrl + Shift + F in Preferences->Keys: 
Command=format Binding=Ctrl+Shift+F When=In Windows Category=Source User=U
Comment 3 Nathan Ridge CLA 2016-07-27 02:24:57 EDT
(In reply to John Anderson from comment #2)
> Yes this is a C project.

If it's a C project, how is "bool" defined? It's not a built-in type in C.
Comment 4 John Anderson CLA 2016-07-27 02:39:21 EDT
When I reapply the format using the quick keys then the problem arises.
First time, format is ok and the second time its as explained earlier.

Thanks Nathan for looking into this.
Comment 5 John Anderson CLA 2016-07-27 02:40:41 EDT
Bool is defined from <stdbool.h> which has is defined from _Bool. 

Interestingly, this problem does not arise if I use _Bool for the data type.
Comment 6 John Anderson CLA 2016-07-27 03:39:31 EDT
Nathan, I'm back with Mars in Debian this morning. I removed all quick keys for formatting and the problem still occurs. So my earlier may be a 'red herring'.

The following snippet goes from this...

    for (i = 0; i < NUM_BINS; i++)
    {
        pMem[i] = (uint8_t *) malloc (MAX_RECORDS * MAX_RECORD_SIZE);
        pData[i] = (uint8_t **) malloc (MAX_RECORDS * sizeof(pData));

        if (NULL == pMem[i] || NULL == pData[i])
        {
            printf ("Failed to allocate memory for pData[] : %s, %s, %d\n",
                    __FILE__, __FUNCTION__, __LINE__);
            abort ();
        }
    }


to this...

    for (i = 0; i < NUM_BINS; i++)
    {
        pMem[i] = (uint8_t *) malloc (MAX_RECORDS * MAX_RECORD_SIZE);
        pData[i] = (uint8_t **) malloc (MAX_RECORDS * sizeof(pData));

        if (NULL == pMem[i] || NULL == pData[i])
        {
            printf ("Failed to allocate memory for pData[] : %s, %s, %d\n",
            __FILE__,
                    __FUNCTION__, __LINE__);
            abort ();
        }
    }
Comment 7 Nathan Ridge CLA 2016-07-28 00:58:27 EDT
Thanks, I can reproduce the issue now. I believe it's a duplicate of bug 459301.
Comment 8 John Anderson CLA 2016-07-28 02:18:25 EDT
Always great when its reproducible :).

Good luck with fixing this.