mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-08 11:03:28 +02:00
Inline friend functions, bug 284690.
This commit is contained in:
parent
b3c11fe78f
commit
03df93edb2
3 changed files with 24 additions and 23 deletions
|
@ -7336,4 +7336,14 @@ public class AST2CPPTests extends AST2BaseTest {
|
||||||
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
|
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
|
||||||
ba.assertProblem("enum_name", 9);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1288,9 +1288,8 @@ public class CPPSemantics {
|
||||||
IASTDeclarator[] declarators = simpleDeclaration.getDeclarators();
|
IASTDeclarator[] declarators = simpleDeclaration.getDeclarators();
|
||||||
IScope dtorScope= scope;
|
IScope dtorScope= scope;
|
||||||
if (declSpec.isFriend()) {
|
if (declSpec.isFriend()) {
|
||||||
// Friends are added to an enclosing scope. They have to be added such that they are
|
// Friends are added to an enclosing scope. Here we have to do that, because when this scope is re-populated
|
||||||
// picked up when this scope is re-populated during ambiguity resolution, while the
|
// during ambiguity resolution, the enclosing scope is otherwise left as it is (without the friend).
|
||||||
// enclosing scope is left as it is.
|
|
||||||
try {
|
try {
|
||||||
while (dtorScope != null && dtorScope.getKind() == EScopeKind.eClassType)
|
while (dtorScope != null && dtorScope.getKind() == EScopeKind.eClassType)
|
||||||
dtorScope= dtorScope.getParent();
|
dtorScope= dtorScope.getParent();
|
||||||
|
|
|
@ -578,10 +578,15 @@ public class CPPVisitor extends ASTQueries {
|
||||||
boolean isFriendDecl= false;
|
boolean isFriendDecl= false;
|
||||||
ICPPScope scope = (ICPPScope) getContainingNonTemplateScope(name);
|
ICPPScope scope = (ICPPScope) getContainingNonTemplateScope(name);
|
||||||
try {
|
try {
|
||||||
if (parent instanceof IASTSimpleDeclaration && scope instanceof ICPPClassScope) {
|
if (scope instanceof ICPPClassScope) {
|
||||||
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) parent).getDeclSpecifier();
|
if (parent instanceof IASTSimpleDeclaration) {
|
||||||
if (declSpec.isFriend()) {
|
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTSimpleDeclaration) parent).getDeclSpecifier();
|
||||||
isFriendDecl= true;
|
isFriendDecl= declSpec.isFriend();
|
||||||
|
} else if (parent instanceof IASTFunctionDefinition) {
|
||||||
|
ICPPASTDeclSpecifier declSpec = (ICPPASTDeclSpecifier) ((IASTFunctionDefinition) parent).getDeclSpecifier();
|
||||||
|
isFriendDecl= declSpec.isFriend();
|
||||||
|
}
|
||||||
|
if (isFriendDecl) {
|
||||||
try {
|
try {
|
||||||
while (scope.getKind() == EScopeKind.eClassType) {
|
while (scope.getKind() == EScopeKind.eClassType) {
|
||||||
scope = (ICPPScope) getParentScope(scope, name.getTranslationUnit());
|
scope = (ICPPScope) getParentScope(scope, name.getTranslationUnit());
|
||||||
|
@ -769,10 +774,6 @@ public class CPPVisitor extends ASTQueries {
|
||||||
} else if (parent instanceof IASTForStatement) {
|
} else if (parent instanceof IASTForStatement) {
|
||||||
return ((IASTForStatement) parent).getScope();
|
return ((IASTForStatement) parent).getScope();
|
||||||
} else if (parent instanceof IASTCompositeTypeSpecifier) {
|
} else if (parent instanceof IASTCompositeTypeSpecifier) {
|
||||||
if (node instanceof IASTFunctionDefinition &&
|
|
||||||
((ICPPASTDeclSpecifier) ((IASTFunctionDefinition) node).getDeclSpecifier()).isFriend()) {
|
|
||||||
return getContainingScope(parent);
|
|
||||||
}
|
|
||||||
return ((IASTCompositeTypeSpecifier) parent).getScope();
|
return ((IASTCompositeTypeSpecifier) parent).getScope();
|
||||||
} else if (parent instanceof ICPPASTNamespaceDefinition) {
|
} else if (parent instanceof ICPPASTNamespaceDefinition) {
|
||||||
return ((ICPPASTNamespaceDefinition) parent).getScope();
|
return ((ICPPASTNamespaceDefinition) parent).getScope();
|
||||||
|
@ -806,19 +807,10 @@ public class CPPVisitor extends ASTQueries {
|
||||||
while (parent.getParent() instanceof IASTDeclarator)
|
while (parent.getParent() instanceof IASTDeclarator)
|
||||||
parent = parent.getParent();
|
parent = parent.getParent();
|
||||||
ASTNodeProperty prop = parent.getPropertyInParent();
|
ASTNodeProperty prop = parent.getPropertyInParent();
|
||||||
if (prop == IASTSimpleDeclaration.DECLARATOR) {
|
if (prop == IASTSimpleDeclaration.DECLARATOR)
|
||||||
return dtor.getFunctionScope();
|
return dtor.getFunctionScope();
|
||||||
} else if (prop == IASTFunctionDefinition.DECLARATOR) {
|
else if (prop == IASTFunctionDefinition.DECLARATOR)
|
||||||
IASTFunctionDefinition funcDef = (IASTFunctionDefinition) parent.getParent();
|
return ((IASTCompoundStatement) ((IASTFunctionDefinition) parent.getParent()).getBody()).getScope();
|
||||||
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) {
|
} else if (parent instanceof ICPPASTTemplateDeclaration) {
|
||||||
return CPPTemplates.getContainingScope(node);
|
return CPPTemplates.getContainingScope(node);
|
||||||
|
|
Loading…
Add table
Reference in a new issue