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

Bug 366654

Summary: Code formatter fails when structure has attribute before the opening brace
Product: [Tools] CDT Reporter: Eugene Ostroukhov <eostroukhov>
Component: cdt-editorAssignee: Project Inbox <cdt-editor-inbox>
Status: RESOLVED WORKSFORME QA Contact: Anton Leherbauer <aleherb+eclipse>
Severity: normal    
Priority: P3 CC: cdtdoug, yevshif, zeratul976
Version: 8.0   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

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.