summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2013-08-25 19:46:12 (EDT)
committerSergey Prigogin2013-08-27 20:12:59 (EDT)
commit06cea4bc3c13d2ba9b259734295b702769c07604 (patch)
treec2dcc95302686586ef2e8260dc4ebcc941898456
parent652ce4748e778444f2dcc608f9b8e536dab2abcb (diff)
downloadorg.eclipse.cdt-06cea4bc3c13d2ba9b259734295b702769c07604.zip
org.eclipse.cdt-06cea4bc3c13d2ba9b259734295b702769c07604.tar.gz
org.eclipse.cdt-06cea4bc3c13d2ba9b259734295b702769c07604.tar.bz2
Bug 400940 - Friend constructor reported as syntax errorrefs/changes/37/15837/4
Change-Id: I0cbe6b9285b1e26abb985e6582e534132acb0c6c Signed-off-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-on: https://git.eclipse.org/r/15837 Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java13
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java18
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java6
3 files changed, 27 insertions, 10 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
index 20c9fe2..814d5f5 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
@@ -9801,6 +9801,19 @@ public class AST2CPPTests extends AST2TestBase {
public void testFriendTemplateParameter() throws Exception {
parseAndCheckBindings();
}
+
+ // struct foo {
+ // foo();
+ // ~foo();
+ // };
+ //
+ // class bar {
+ // friend foo::foo();
+ // friend foo::~foo();
+ // };
+ public void testFriendConstructorDestructor_400940() throws Exception {
+ parseAndCheckBindings();
+ }
// struct S {
// virtual void mFuncDecl() final;
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
index 2b0793b..d917ffa 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java
@@ -1620,16 +1620,16 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
} catch (BacktrackException e) {
if (acceptEmpty) {
backup(dtorMark1);
- return result.set(declspec1, null, null);
+ dtor1= null;
+ } else {
+ // try second variant, if possible
+ if (dtorMark2 == null)
+ throw e;
+
+ backup(dtorMark2);
+ dtor2= initDeclarator(declspec2, option);
+ return result.set(declspec2, dtor2, dtorMark2);
}
-
- // try second variant, if possible
- if (dtorMark2 == null)
- throw e;
-
- backup(dtorMark2);
- dtor2= initDeclarator(declspec2, option);
- return result.set(declspec2, dtor2, dtorMark2);
}
// first variant was a success. If possible, try second 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 4298ba0..0af4aab 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
@@ -2632,7 +2632,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
SHORT= 0x20, UNSIGNED= 0x40, SIGNED= 0x80, COMPLEX= 0x100, IMAGINARY= 0x200,
VIRTUAL= 0x400, EXPLICIT= 0x800, FRIEND= 0x1000, THREAD_LOCAL= 0x2000;
private static final int FORBID_IN_EMPTY_DECLSPEC =
- CONST | RESTRICT | VOLATILE | SHORT | UNSIGNED | SIGNED | COMPLEX | IMAGINARY | FRIEND | THREAD_LOCAL;
+ CONST | RESTRICT | VOLATILE | SHORT | UNSIGNED | SIGNED | COMPLEX | IMAGINARY | THREAD_LOCAL;
/**
* This function parses a declaration specifier sequence, as according to
@@ -3282,6 +3282,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
if (CharArrayUtils.equals(nchars, start, nchars.length-start, currentClassName))
return;
}
+
+ // Accept constructors and destructors of other classes as friends
+ if (declspec instanceof ICPPASTDeclSpecifier && ((ICPPASTDeclSpecifier) declspec).isFriend())
+ return;
} else if (isQualified) {
// Accept qualified constructor or destructor outside of class body
return;