Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2009-08-17 00:15:31 -0400
committerSergey Prigogin2009-08-17 00:15:31 -0400
commitebd406ce915fc8c4936be69b38890bd4e3e3dc97 (patch)
tree115527ff91789fac2749b90015f9b792eb708ec1
parentd22f951e455dae592102866f886cbdda50f1870d (diff)
downloadorg.eclipse.cdt-ebd406ce915fc8c4936be69b38890bd4e3e3dc97.tar.gz
org.eclipse.cdt-ebd406ce915fc8c4936be69b38890bd4e3e3dc97.tar.xz
org.eclipse.cdt-ebd406ce915fc8c4936be69b38890bd4e3e3dc97.zip
Bug 286741.
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java14
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPVisitor.java15
2 files changed, 26 insertions, 3 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
index 7bd7fc4d7e..6e4cbb63ff 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
@@ -4107,4 +4107,18 @@ public class AST2TemplateTests extends AST2BaseTest {
final String code = getAboveComment();
parseAndCheckBindings(code, ParserLanguage.CPP);
}
+
+ // template <typename T>
+ // struct A {
+ // typedef A<T> Self;
+ // friend Self f(Self p) { return Self(); }
+ // };
+ //
+ // void test(A<int> x) {
+ // f(x);
+ // }
+ public void testInlineFriendFunction_286741() throws Exception {
+ final String code = getAboveComment();
+ parseAndCheckBindings(code, ParserLanguage.CPP);
+ }
}
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 45331c5bbf..e65ac2a250 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
@@ -810,10 +810,19 @@ 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)
- return ((IASTCompoundStatement) ((IASTFunctionDefinition) parent.getParent()).getBody()).getScope();
+ } 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 (parent instanceof ICPPASTTemplateDeclaration) {
return CPPTemplates.getContainingScope(node);

Back to the top