Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorNathan Ridge2013-08-25 23:46:12 +0000
committerSergey Prigogin2013-08-28 00:43:08 +0000
commit07709b85cecce140764d4e89aa2da1aa3bf3cbfc (patch)
tree936534caf1711a3f6f5f48fd602bc0b40bc83ffd /core
parent2c5fcc3d856c571613317d68dcc66ddba5f9d114 (diff)
downloadorg.eclipse.cdt-07709b85cecce140764d4e89aa2da1aa3bf3cbfc.tar.gz
org.eclipse.cdt-07709b85cecce140764d4e89aa2da1aa3bf3cbfc.tar.xz
org.eclipse.cdt-07709b85cecce140764d4e89aa2da1aa3bf3cbfc.zip
Bug 400940 - Friend constructor reported as syntax error
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>
Diffstat (limited to 'core')
-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 20c9fe2090f..814d5f52120 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 2b0793b547b..d917ffaaafd 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 4298ba09e0d..0af4aabf979 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;

Back to the top