Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 361768

Summary: Use of two sequential macros in C++ code formats incorrectly
Product: [Tools] CDT Reporter: Geoff Alexander <gdlxn>
Component: cdt-editorAssignee: Marco Stornelli <marco.stornelli>
Status: RESOLVED FIXED QA Contact: Anton Leherbauer <aleherb+eclipse>
Severity: normal    
Priority: P3 CC: cdtdoug, gdlxn, jonah, yevshif, zeratul976
Version: 8.0   
Target Milestone: 9.8.0   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/138425
https://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=d1bd979a00673bcb6fcaa001200ee32cf3def041
Whiteboard:
Attachments:
Description Flags
Eclipse workspace containing small example illustrating the problem none

Description Geoff Alexander CLA 2011-10-24 00:59:49 EDT

    
Comment 1 Geoff Alexander CLA 2011-10-24 01:13:42 EDT
Created attachment 205779 [details]
Eclipse workspace containing small example illustrating the problem
Comment 2 Geoff Alexander CLA 2011-10-24 01:19:08 EDT
Build Identifier: 20110916-0149

We sometimes have two sequential macro usages as in the following code:

    public:
      inline bool operator!=(const Term& r) const {
        LLTP_ASSERT1((_type == function) || (_type == variable));
        LLTP_ASSERT1((r._type == function) || (r._type == variable));
        return !(*this == r);
      }

Under Eclipse CDT 8.0 this formats incorrectly on the first format:

    public:
      inline bool operator!=(const Term& r) const {
        LLTP_ASSERT1((_type == function) || (_type == variable)); LLTP_ASSERT1((r._type == function) || (r._type == variable));
        return !(*this == r);
      }

A second format gives

    public:
      inline bool operator!=(const Term& r) const {
        LLTP_ASSERT1((_type == function) || (_type == variable));LLTP_ASSERT1((r._type == function) || (r._type == variable));
        return !(*this == r);
      }

I've attached an Eclipse workspace containing a small example illustrating the problem.
Comment 3 Nathan Ridge CLA 2015-03-31 04:11:38 EDT
Looks like the problem is related to the macro having an empty expansion.
Comment 4 Geoff Alexander CLA 2015-04-03 16:56:21 EDT
Thanks Nathan.  Based on your comment, I'm able to work around the problem by using the # Symbols tab of the C/C++ General -> Paths and Symbols preferences to ensure that the problematic macros aren't empty. However, even though I'm able to work around the problem, I still think that this problem should be fixed.
Comment 5 Nathan Ridge CLA 2015-04-03 17:00:37 EDT
Agreed - this is a bug in the formatter.
Comment 6 Eclipse Genie CLA 2019-03-09 12:07:45 EST
New Gerrit change created: https://git.eclipse.org/r/138425
Comment 8 Jonah Graham CLA 2019-04-08 12:54:46 EDT
Thank you for the fix Marco!