Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHansruedi Patzen2017-11-17 07:14:55 -0500
committerNathan Ridge2017-11-24 13:25:00 -0500
commit3319c8596e69fd30084d44a1f364beae61c6768d (patch)
treeca3a32d51846864c8c38cf87f5c26ec7ff5a0018
parent19b4848e08c13928c1bda7235c10e77e54edf98e (diff)
downloadorg.eclipse.cdt-3319c8596e69fd30084d44a1f364beae61c6768d.tar.gz
org.eclipse.cdt-3319c8596e69fd30084d44a1f364beae61c6768d.tar.xz
org.eclipse.cdt-3319c8596e69fd30084d44a1f364beae61c6768d.zip
Bug 527396: Parser includes curly brace when parsing noexcept functions
Change-Id: I0d2626cccf5b093f2f3cc9fbcbeaedbb21ebd508 Signed-off-by: Hansruedi Patzen <hansruedi.patzen@hsr.ch>
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java55
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java7
2 files changed, 58 insertions, 4 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java
index 6136c3b48f..1b9512e9cc 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationTests.java
@@ -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;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
index 2fc22a307c..6afe8cca26 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
@@ -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);
}

Back to the top