mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06: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:
parent
19b4848e08
commit
3319c8596e
2 changed files with 58 additions and 4 deletions
|
@ -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.IASTUnaryExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
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.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.ICPPASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionWithTryBlock;
|
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[1], code, "\"deprecated include\"");
|
||||||
assertSoleLocation(problems[2], code, "#invalid");
|
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){
|
// int main(void){
|
||||||
// #define one 1
|
// #define one 1
|
||||||
// int integer = one;
|
// int integer = one;
|
||||||
|
|
|
@ -4659,15 +4659,14 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
// noexcept specification
|
// noexcept specification
|
||||||
if (LT(1) == IToken.t_noexcept) {
|
if (LT(1) == IToken.t_noexcept) {
|
||||||
consume(); // noexcept
|
consume(); // noexcept
|
||||||
IASTExpression expression;
|
IASTExpression expression = ICPPASTFunctionDeclarator.NOEXCEPT_DEFAULT;
|
||||||
|
endOffset = getEndOffset();
|
||||||
if (LT(1) == IToken.tLPAREN) {
|
if (LT(1) == IToken.tLPAREN) {
|
||||||
consume(); // (
|
consume(); // (
|
||||||
expression = expression();
|
expression = expression();
|
||||||
consume(IToken.tRPAREN); //)
|
consume(IToken.tRPAREN); //)
|
||||||
} else {
|
endOffset = getEndOffset();
|
||||||
expression = ICPPASTFunctionDeclarator.NOEXCEPT_DEFAULT;
|
|
||||||
}
|
}
|
||||||
endOffset = getEndOffset();
|
|
||||||
fc.setNoexceptExpression((ICPPASTExpression) expression);
|
fc.setNoexceptExpression((ICPPASTExpression) expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue