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

Bug 353022

Summary: AbortFormatting exception formatting switch without braces
Product: [Tools] CDT Reporter: Marc-AndrĂ© Laperle <malaperle>
Component: cdt-coreAssignee: Marco Stornelli <marco.stornelli>
Status: RESOLVED FIXED QA Contact: Doug Schaefer <cdtdoug>
Severity: normal    
Priority: P3 CC: eclipse.sprigogin, marco.stornelli, yevshif
Version: 8.0   
Target Milestone: 9.8.0   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/142349
https://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=1cd5180642ada741ec45500ec3aba26f8855fb36
Whiteboard:

Description Marc-André Laperle CLA 2011-07-25 13:16:27 EDT
Using CDT 8.0.0.201107220206

1. Paste this code in an editor:

void foo()
{
switch(0)
default:
{

}
}

2. Format the code (ctrl+shift+F)
3. Exception occurs:

org.eclipse.cdt.internal.formatter.AbortFormatting: [2/15] Unexpected token type, expecting:12, actual:Token type=71  image =default offset=23
	at org.eclipse.cdt.internal.formatter.Scribe.printNextToken(Scribe.java:1623)
	at org.eclipse.cdt.internal.formatter.CodeFormatterVisitor.formatOpeningBrace(CodeFormatterVisitor.java:3983)
	at org.eclipse.cdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatterVisitor.java:3458)
	at org.eclipse.cdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatterVisitor.java:950)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTSwitchStatement.accept(CPPASTSwitchStatement.java:95)
	at org.eclipse.cdt.internal.formatter.CodeFormatterVisitor.formatStatements(CodeFormatterVisitor.java:4040)
	at org.eclipse.cdt.internal.formatter.CodeFormatterVisitor.formatOpenedBlock(CodeFormatterVisitor.java:3939)
	at org.eclipse.cdt.internal.formatter.CodeFormatterVisitor.formatBlock(CodeFormatterVisitor.java:3914)
	at org.eclipse.cdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatterVisitor.java:1370)
	at org.eclipse.cdt.internal.formatter.CodeFormatterVisitor.formatDeclaration(CodeFormatterVisitor.java:646)
	at org.eclipse.cdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatterVisitor.java:636)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition.accept(CPPASTFunctionDefinition.java:164)
	at org.eclipse.cdt.internal.formatter.CodeFormatterVisitor.formatDeclarations(CodeFormatterVisitor.java:506)
	at org.eclipse.cdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatterVisitor.java:450)
	at org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit.accept(ASTTranslationUnit.java:271)
	at org.eclipse.cdt.internal.formatter.CodeFormatterVisitor.format(CodeFormatterVisitor.java:396)
	at org.eclipse.cdt.internal.formatter.CCodeFormatter.format(CCodeFormatter.java:158)
	at org.eclipse.cdt.internal.corext.util.CodeFormatterUtil.format(CodeFormatterUtil.java:129)
	at org.eclipse.cdt.internal.ui.text.CFormattingStrategy.format(CFormattingStrategy.java:62)
	at org.eclipse.jface.text.formatter.MultiPassContentFormatter.formatMaster(MultiPassContentFormatter.java:193)
Comment 1 Eclipse Genie CLA 2019-05-17 14:29:42 EDT
New Gerrit change created: https://git.eclipse.org/r/142349