1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 412187 Formatting function-like macro call in equals initializer

Added IASTExpressions to the exclusion in enterNode of
CodeFormatterVisitor when encountering function like macro calls.

Change-Id: I8ea6c5e7ba955299b0d6ca48c93fac275afa65e3
Reviewed-on: https://git.eclipse.org/r/14213
Reviewed-by: Thomas Corbat <tcorbat@hsr.ch>
IP-Clean: Thomas Corbat <tcorbat@hsr.ch>
Tested-by: Thomas Corbat <tcorbat@hsr.ch>
This commit is contained in:
Thomas Corbat 2013-07-03 12:55:15 +02:00
parent c658e9df68
commit e843235fc4
3 changed files with 27 additions and 5 deletions

View file

@ -3771,7 +3771,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
return true;
} else if (!fInsideMacroArguments && locations[0] instanceof IASTMacroExpansionLocation) {
IASTMacroExpansionLocation location = (IASTMacroExpansionLocation) locations[0];
if (locations.length <= 2 && node instanceof IASTStatement) {
if (locations.length <= 2 &&
(node instanceof IASTStatement || node instanceof IASTExpression)) {
IASTPreprocessorMacroExpansion macroExpansion = location.getExpansion();
IASTFileLocation macroLocation = macroExpansion.getFileLocation();
int macroOffset = macroLocation.getNodeOffset();

View file

@ -24,15 +24,13 @@ const SimpleStruct simpleStruct = { 1, "mySimple", 0.1232 };
\
}
const SimpleStruct array[] = { {
SIZEOF( simpleStruct, num ),
const SimpleStruct array[] = { { SIZEOF(simpleStruct, num),
#if FOO
"foo"
# else
"bar"
#endif
, 0.5 }, {
SIZEOF( simpleStruct, floatNum ), "name", 1.1 } };
, 0.5 }, { SIZEOF(simpleStruct, floatNum), "name", 1.1 } };
// single line outside scope

View file

@ -2965,4 +2965,27 @@ public class CodeFormatterTest extends BaseUITestCase {
public void testDoWhileInMacro_Bug359658() throws Exception {
assertFormatterResult();
}
//#define macro(x) NS::convert(x)
//namespace NS {
//int convert(int arg) {
//return arg;
//}
//}
//int main() {
//int i = macro(42);
//}
//#define macro(x) NS::convert(x)
//namespace NS {
//int convert(int arg) {
// return arg;
//}
//}
//int main() {
// int i = macro(42);
//}
public void testFunctionMacroInInitializerExpression() throws Exception {
assertFormatterResult();
}
}