mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
Resolution of inline friend functions. Bug 284690.
This commit is contained in:
parent
d9f76e60dc
commit
936d9e6b75
3 changed files with 17 additions and 3 deletions
|
@ -7294,7 +7294,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);
|
||||
}
|
||||
|
@ -7330,7 +7330,7 @@ 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);
|
||||
|
|
|
@ -759,7 +759,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) {
|
||||
|
@ -769,6 +769,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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue