Bug 441839 - [formatter] white spaces / tabs missing in if statement without {}
Summary: [formatter] white spaces / tabs missing in if statement without {}
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-editor (show other bugs)
Version: 8.3.0   Edit
Hardware: Other Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-15 02:52 EDT by Andrea Froelich CLA
Modified: 2020-09-04 15:25 EDT (History)
3 users (show)

See Also:


Attachments
needed header file for testing formatter (6.76 KB, application/octet-stream)
2014-08-25 05:49 EDT, Andrea Froelich CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrea Froelich CLA 2014-08-15 02:52:24 EDT
We have a problem with formatting C++ Code.

Independent from the formatter we are using (K&R, BSD/Allman, GNU, Whitesmiths or a self defined one) we always get a 

if (!this->isOpenRead)
return false;

(the return directly under the if)

while it should be 

if (!this->isOpenRead)
    return false;

(the return with a tab or white spaces in front)

When working with {} it's working fine.

Do you know how we could solve this issue?

Thanks a lot for your help and best regards,

Andrea
Comment 1 Nathan Ridge CLA 2014-08-17 02:31:10 EDT
I cannot reproduce this issue.

I tested the following code, with CDT 8.4:


class Foo {
	bool isOpenRead;

	bool foo() {
		if (!this->isOpenRead)
			return false;
		return true;
	}
};


All of the built-in formatters correctly indented the return statement after the 'if'.
Comment 2 Andrea Froelich CLA 2014-08-19 04:25:12 EDT
Yes, with the example you wrote the formatter is working fine. I found now out that after calling a specific function (we have defined in a header file) the wrong behavior is shown. I will do some more tests and then write the example here.
Comment 3 Andrea Froelich CLA 2014-08-25 05:49:57 EDT
Created attachment 246304 [details]
needed header file for testing formatter
Comment 4 Andrea Froelich CLA 2014-08-25 05:51:06 EDT
Here now the example where we have problems, it's related to a macro that is called.

/*
 * formatter_test.cpp
 *
 *  Created on: Aug 25, 2014
 *      Author: eedanch
 */

#include "test_header.h"

namespace EricssonDsc {
class Foo {
	bool isOpenRead;

	bool foo() {
		FuncTrace;
		if (!this->isOpenRead)
		return false;
		return true;
	}
};
}

If we remove the line with "FuncTrace" then the formatting is correct.

/*
 * formatter_test.cpp
 *
 *  Created on: Aug 25, 2014
 *      Author: eedanch
 */

#include "test_header.h"

namespace EricssonDsc {
class Foo {
	bool isOpenRead;

	bool foo() {
		if (!this->isOpenRead)
			return false;
		return true;
	}
};
}
Comment 5 Nathan Ridge CLA 2014-08-25 11:10:25 EDT
Thanks, I can reproduce the issue with this example.