Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorSergey Prigogin2009-08-09 20:43:41 -0400
committerSergey Prigogin2009-08-09 20:43:41 -0400
commita5e5281adedad1144177ad1dd2d559379bc2e552 (patch)
treeab98d29b29d7693afeeaefc08a644c1a5da36b05 /core
parent998d50a356171cc151e8b1f74b78a24ee8cc2b8a (diff)
downloadorg.eclipse.cdt-a5e5281adedad1144177ad1dd2d559379bc2e552.tar.gz
org.eclipse.cdt-a5e5281adedad1144177ad1dd2d559379bc2e552.tar.xz
org.eclipse.cdt-a5e5281adedad1144177ad1dd2d559379bc2e552.zip
Resolution of inline friend functions. Bug 284690.
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java6
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FriendCollector.java10
3 files changed, 22 insertions, 8 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 710153ea87..c6437ab595 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
@@ -7201,12 +7201,6 @@ public class AST2CPPTests extends AST2BaseTest {
parseAndCheckBindings(code, ParserLanguage.CPP);
}
-
- // typedef enum enum_name enum_name;
- public void testTypedefRecursion_285457() throws Exception {
- BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
- ba.assertProblem("enum_name", 9);
- }
// class A {
// friend inline void m(A p) {}
@@ -7215,7 +7209,7 @@ public class AST2CPPTests extends AST2BaseTest {
// void test(A a) {
// m(a);
// }
- public void _testInlineFriendFunction_284690() throws Exception {
+ public void testInlineFriendFunction_284690() throws Exception {
final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.CPP);
}
@@ -7251,4 +7245,10 @@ public class AST2CPPTests extends AST2BaseTest {
assertEquals(IBasicType.t_int, ((ICPPBasicType) t3).getType());
assertEquals(ICPPBasicType.IS_LONG, ((ICPPBasicType) t3).getQualifierBits());
}
+
+ // typedef enum enum_name enum_name;
+ public void testTypedefRecursion_285457() throws Exception {
+ BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
+ ba.assertProblem("enum_name", 9);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
index 62e471c9ee..9fde713b53 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java
@@ -763,7 +763,7 @@ public class CPPVisitor extends ASTQueries {
while (node != null) {
if (node instanceof IASTName && !(node instanceof ICPPASTQualifiedName)) {
return getContainingScope((IASTName) node);
- }
+ }
if (node instanceof IASTDeclaration) {
IASTNode parent = node.getParent();
if (parent instanceof IASTTranslationUnit) {
@@ -773,6 +773,10 @@ public class CPPVisitor extends ASTQueries {
} else if (parent instanceof IASTForStatement) {
return ((IASTForStatement) parent).getScope();
} else if (parent instanceof IASTCompositeTypeSpecifier) {
+ if (node instanceof IASTFunctionDefinition &&
+ ((ICPPASTDeclSpecifier) ((IASTFunctionDefinition) node).getDeclSpecifier()).isFriend()) {
+ return getContainingScope(parent);
+ }
return ((IASTCompositeTypeSpecifier) parent).getScope();
} else if (parent instanceof ICPPASTNamespaceDefinition) {
return ((ICPPASTNamespaceDefinition) parent).getScope();
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FriendCollector.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FriendCollector.java
index 49a5f5f94b..8f4ed03347 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FriendCollector.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/FriendCollector.java
@@ -7,12 +7,15 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
+import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
@@ -61,6 +64,13 @@ class FriendCollector extends ASTVisitor {
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
return PROCESS_CONTINUE;
}
+ } else if (declaration instanceof IASTFunctionDefinition) {
+ IASTFunctionDefinition funcDefinition = (IASTFunctionDefinition) declaration;
+ ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) funcDefinition.getDeclSpecifier();
+ if (declSpec.isFriend()) {
+ IASTFunctionDeclarator declarator = funcDefinition.getDeclarator();
+ ASTInternal.addName(fScope, declarator.getName());
+ }
}
return PROCESS_SKIP;
}

Back to the top