Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 366654 - Code formatter fails when structure has attribute before the opening brace
Summary: Code formatter fails when structure has attribute before the opening brace
Status: RESOLVED WORKSFORME
Alias: None
Product: CDT
Classification: Tools
Component: cdt-editor (show other bugs)
Version: 8.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Anton Leherbauer CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-13 21:04 EST by Eugene Ostroukhov CLA
Modified: 2016-12-29 18:27 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eugene Ostroukhov CLA 2011-12-13 21:04:49 EST
Following declaration causes code formatter to fail with an exception:
typedef struct __attribute__((aligned(8)))
{
    unsigned int l, a;
} LA32;

Exception stack trace:
org.eclipse.cdt.internal.formatter.AbortFormatting: [22/1] Unexpected token type, expecting:12, actual:Token type=1  image =__attribute__ offset=895
	at org.eclipse.cdt.internal.formatter.Scribe.printNextToken(Scribe.java:1623)
	at org.eclipse.cdt.internal.formatter.CodeFormatterVisitor.formatOpeningBrace(CodeFormatterVisitor.java:3984)
	at org.eclipse.cdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatterVisitor.java:1872)
	at org.eclipse.cdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatterVisitor.java:851)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompositeTypeSpecifier.accept(CPPASTCompositeTypeSpecifier.java:155)
...


Attached to the bug is a lazy formatter fix - it will simply skip everything until the opening brace is found.
Comment 1 Nathan Ridge CLA 2015-07-23 20:57:31 EDT
I can't reproduce the exception.

The resut of the formatting may be a bit strange:

typedef struct
    __attribute__((aligned(8)))
    {
        unsigned int l, a;
    } LA32;

but I believe that's covered by bug 467346.
Comment 2 Nathan Ridge CLA 2016-12-29 18:27:21 EST
Closing per comment 1. Feel free to reopen if you're still seeing this.