Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 357423 - Code formatter gets confused by a macro
Summary: Code formatter gets confused by a macro
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-editor (show other bugs)
Version: 8.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 8.0.2   Edit
Assignee: Sergey Prigogin CLA
QA Contact: Anton Leherbauer CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-12 17:42 EDT by Sergey Prigogin CLA
Modified: 2011-09-21 08:10 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Prigogin CLA 2011-09-12 17:42:43 EDT
struct Stream {
    Stream& operator <<(const char*);
};
Stream GetStream();

#define MY_MACRO switch (0) case 0: default: GetStream()

void test() {
    MY_MACRO << "Loooooooooooooooooooooooooong string literal"
             << "another literal.";
}

Formatting the test function results in:

void test() {
    MY_MACRO<< "Loooooooooooooooooooooooooong string literal"
    << "another literal.";
}
Comment 1 Sergey Prigogin CLA 2011-09-12 19:38:09 EDT
Fixed in cdt_8_0 and master > 20110912.
Comment 2 CDT Genie CLA 2011-09-12 20:23:01 EDT
*** cdt git genie on behalf of Sergey Prigogin ***

    Bug 357423 - Code formatter gets confused by a macro.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=7065e4648d6f0ac0621540841207da1f1136ce7f
Comment 3 CDT Genie CLA 2011-09-12 20:23:03 EDT
*** cdt git genie on behalf of Sergey Prigogin ***

    Bug 357423 - Code formatter gets confused by a macro.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=efc55c57d0d12c0f08fefd8a92eab19b30d85675
Comment 4 Sergey Prigogin CLA 2011-09-14 15:03:48 EDT
There is a still a problem if MY_MACRO is defined as:

#define MY_MACRO switch (0) case 0: default: if (bool x = false) ; else GetStream()
Comment 5 CDT Genie CLA 2011-09-14 16:23:01 EDT
*** cdt git genie on behalf of Sergey Prigogin ***

    Bug 357423 - Code formatter gets confused by a macro. Macro involving an
    'if' statement.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=a090d9bd2c113591b8c0a734a78d9f051e297c44
Comment 6 CDT Genie CLA 2011-09-16 15:23:00 EDT
*** cdt git genie on behalf of Sergey Prigogin ***

    Bug 357423 - Code formatter gets confused by a macro. Macro involving an
    'if' statement.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=6c90d86c4bdc56ca59ad9b30ab25967fcd618b34
Comment 7 Sergey Prigogin CLA 2011-09-16 15:31:55 EDT
Fixed in master and cdt_8_0.
Comment 8 Anton Leherbauer CLA 2011-09-20 07:22:19 EDT
I have to reopen this bug. There is a regression in the following case:

#define EXPR(a) a
void f() {
    switch(EXPR(1)) {
    default:
        break;
    }
}
Comment 9 Sergey Prigogin CLA 2011-09-20 20:41:40 EDT
Regression fixed.
Comment 10 CDT Genie CLA 2011-09-20 21:23:02 EDT
*** cdt git genie on behalf of Sergey Prigogin ***

    Bug 357423. Fixed regression.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=e2aef245cdc7dd73235d035ba5b18ee41496ef1e
Comment 11 CDT Genie CLA 2011-09-20 21:23:04 EDT
*** cdt git genie on behalf of Sergey Prigogin ***

    Bug 357423. Fixed regression.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=c71e24757865d49999f87bcd49794e27e9327f53
Comment 12 Anton Leherbauer CLA 2011-09-21 08:10:45 EDT
Thanks!