1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 527396: Parser includes curly brace when parsing noexcept functions

Change-Id: I0d2626cccf5b093f2f3cc9fbcbeaedbb21ebd508
Signed-off-by: Hansruedi Patzen <hansruedi.patzen@hsr.ch>
This commit is contained in:
Hansruedi Patzen 2017-11-17 13:14:55 +01:00 committed by Nathan Ridge
parent 19b4848e08
commit 3319c8596e
2 changed files with 58 additions and 4 deletions

View file

@ -58,6 +58,7 @@ import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock;
@ -647,7 +648,61 @@ public class DOMLocationTests extends AST2TestBase {
assertSoleLocation(problems[1], code, "\"deprecated include\"");
assertSoleLocation(problems[2], code, "#invalid");
}
public void testBug527396_1() throws Exception {
String code = "void foo() noexcept {}"; //$NON-NLS-1$
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
ICPPASTFunctionDefinition definition = (ICPPASTFunctionDefinition) tu.getDeclarations()[0];
ICPPASTDeclarator declarator = (ICPPASTDeclarator) definition.getDeclarator();
String rawDeclarator = "foo() noexcept"; //$NON-NLS-1$
assertSoleLocation(declarator, code.indexOf(rawDeclarator), rawDeclarator.length());
}
public void testBug527396_2() throws Exception {
String code = "void foo() noexcept(false) {}"; //$NON-NLS-1$
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
ICPPASTFunctionDefinition definition = (ICPPASTFunctionDefinition) tu.getDeclarations()[0];
ICPPASTDeclarator declarator = (ICPPASTDeclarator) definition.getDeclarator();
String rawDeclarator = "foo() noexcept(false)"; //$NON-NLS-1$
assertSoleLocation(declarator, code.indexOf(rawDeclarator), rawDeclarator.length());
}
public void testBug527396_3() throws Exception {
String code = "void foo() {}"; //$NON-NLS-1$
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
ICPPASTFunctionDefinition definition = (ICPPASTFunctionDefinition) tu.getDeclarations()[0];
ICPPASTDeclarator declarator = (ICPPASTDeclarator) definition.getDeclarator();
String rawDeclarator = "foo()"; //$NON-NLS-1$
assertSoleLocation(declarator, code.indexOf(rawDeclarator), rawDeclarator.length());
}
public void testBug527396_4() throws Exception {
String code = "void foo() noexcept;"; //$NON-NLS-1$
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
IASTSimpleDeclaration definition = (IASTSimpleDeclaration) tu.getDeclarations()[0];
ICPPASTDeclarator declarator = (ICPPASTDeclarator) definition.getDeclarators()[0];
String rawDeclarator = "foo() noexcept"; //$NON-NLS-1$
assertSoleLocation(declarator, code.indexOf(rawDeclarator), rawDeclarator.length());
}
public void testBug527396_5() throws Exception {
String code = "void foo() noexcept(false);"; //$NON-NLS-1$
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
IASTSimpleDeclaration definition = (IASTSimpleDeclaration) tu.getDeclarations()[0];
ICPPASTDeclarator declarator = (ICPPASTDeclarator) definition.getDeclarators()[0];
String rawDeclarator = "foo() noexcept(false)"; //$NON-NLS-1$
assertSoleLocation(declarator, code.indexOf(rawDeclarator), rawDeclarator.length());
}
public void testBug527396_6() throws Exception {
String code = "void foo();"; //$NON-NLS-1$
IASTTranslationUnit tu = parse(code, ParserLanguage.CPP);
IASTSimpleDeclaration definition = (IASTSimpleDeclaration) tu.getDeclarations()[0];
ICPPASTDeclarator declarator = (ICPPASTDeclarator) definition.getDeclarators()[0];
String rawDeclarator = "foo()"; //$NON-NLS-1$
assertSoleLocation(declarator, code.indexOf(rawDeclarator), rawDeclarator.length());
}
// int main(void){
// #define one 1
// int integer = one;

View file

@ -4659,15 +4659,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
// noexcept specification
if (LT(1) == IToken.t_noexcept) {
consume(); // noexcept
IASTExpression expression;
IASTExpression expression = ICPPASTFunctionDeclarator.NOEXCEPT_DEFAULT;
endOffset = getEndOffset();
if (LT(1) == IToken.tLPAREN) {
consume(); // (
expression = expression();
consume(IToken.tRPAREN); //)
} else {
expression = ICPPASTFunctionDeclarator.NOEXCEPT_DEFAULT;
endOffset = getEndOffset();
}
endOffset = getEndOffset();
fc.setNoexceptExpression((ICPPASTExpression) expression);
}