Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMarkus Schorn2009-08-18 09:40:21 -0400
committerMarkus Schorn2009-08-18 09:40:21 -0400
commite9bfe64b6e81182e0d0b78dcb7c124e35bbd6f23 (patch)
tree97119e0bfcbc7864dda4545ebe6c7dda2c6b5f10 /core
parent91a83e0c2b0c17de835b55a8b951ecea4df092de (diff)
downloadorg.eclipse.cdt-e9bfe64b6e81182e0d0b78dcb7c124e35bbd6f23.tar.gz
org.eclipse.cdt-e9bfe64b6e81182e0d0b78dcb7c124e35bbd6f23.tar.xz
org.eclipse.cdt-e9bfe64b6e81182e0d0b78dcb7c124e35bbd6f23.zip
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.java10
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java5
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java32
3 files changed, 24 insertions, 23 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 c6437ab595..b3f7f2f604 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
@@ -7251,4 +7251,14 @@ public class AST2CPPTests extends AST2BaseTest {
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
ba.assertProblem("enum_name", 9);
}
+
+ // class CL {
+ // typedef int x;
+ // friend void test() {
+ // x a; // problem on x
+ // }
+ // };
+ public void testLookupFromInlineFriend_284690() throws Exception {
+ parseAndCheckBindings(getAboveComment(), ParserLanguage.CPP);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
index c7320e211d..33d8156f28 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java
@@ -1470,9 +1470,8 @@ public class CPPSemantics {
IASTDeclarator[] declarators = simpleDeclaration.getDeclarators();
IScope dtorScope= scope;
if (declSpec.isFriend()) {
- // Friends are added to an enclosing scope. They have to be added such that they are
- // picked up when this scope is re-populated during ambiguity resolution, while the
- // enclosing scope is left as it is.
+ // Friends are added to an enclosing scope. Here we have to do that, because when this scope is re-populated
+ // during ambiguity resolution, the enclosing scope is otherwise left as it is (without the friend).
try {
while (dtorScope != null && dtorScope.getKind() == EScopeKind.eClassType)
dtorScope= dtorScope.getParent();
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 e65ac2a250..b1729a40d3 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
@@ -580,10 +580,15 @@ public class CPPVisitor extends ASTQueries {
boolean isFriendDecl= false;
ICPPScope scope = (ICPPScope) getContainingNonTemplateScope(name);
try {
- if (parent instanceof IASTSimpleDeclaration && scope instanceof ICPPClassScope) {
- ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) parent).getDeclSpecifier();
- if (declSpec.isFriend()) {
- isFriendDecl= true;
+ if (scope instanceof ICPPClassScope) {
+ if (parent instanceof IASTSimpleDeclaration) {
+ ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) parent).getDeclSpecifier();
+ isFriendDecl= declSpec.isFriend();
+ } else if (parent instanceof IASTFunctionDefinition) {
+ ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition) parent).getDeclSpecifier();
+ isFriendDecl= declSpec.isFriend();
+ }
+ if (isFriendDecl) {
try {
while (scope.getKind() == EScopeKind.eClassType) {
scope = (ICPPScope) getParentScope(scope, name.getTranslationUnit());
@@ -773,10 +778,6 @@ 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();
@@ -810,19 +811,10 @@ public class CPPVisitor extends ASTQueries {
while (parent.getParent() instanceof IASTDeclarator)
parent = parent.getParent();
ASTNodeProperty prop = parent.getPropertyInParent();
- if (prop == IASTSimpleDeclaration.DECLARATOR) {
+ if (prop == IASTSimpleDeclaration.DECLARATOR)
return dtor.getFunctionScope();
- } else if (prop == IASTFunctionDefinition.DECLARATOR) {
- IASTFunctionDefinition funcDef = (IASTFunctionDefinition) parent.getParent();
- ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) funcDef.getDeclSpecifier();
- if (declSpec.isFriend()) {
- parent = funcDef.getParent();
- if (parent instanceof IASTCompositeTypeSpecifier) {
- return ((IASTCompositeTypeSpecifier) parent).getScope();
- }
- }
- return ((IASTCompoundStatement) funcDef.getBody()).getScope();
- }
+ else if (prop == IASTFunctionDefinition.DECLARATOR)
+ return ((IASTCompoundStatement) ((IASTFunctionDefinition) parent.getParent()).getBody()).getScope();
}
} else if (parent instanceof ICPPASTTemplateDeclaration) {
return CPPTemplates.getContainingScope(node);

Back to the top