mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix struct declaration introducing name in namespace scope (#587)
When AST is used to resolve binding for class-name and elaborated-type-specifier is found matching [basic.lookup.elab] rule introducing the class-name, behavior of CPPSemantics.resolveAmbiguities() is different in presence of index. If there is no index, CPPVisitor.createBinding() for ICPPASTElaboratedTypeSpecifier creates binding for class-name as introducing the name. When later lookup finds this binding all is good because binding is declared before the use site. If index is available, lookup for class-name fails in AST too but now matching entry is found in the AST index. When later lookup finds this index binding CPPSemantics.declaredBefore() returns false because it does not look in AST index and only checks project index. To fix this additionally check if ICPPClassType object is in AST index, as we already do for ICPPConstructor. This way declaredBefore() does almost the same thing as isReachableFromAst() and lookup succeeds returning the same binding from index.
This commit is contained in:
parent
4970952382
commit
a7bfdd2802
2 changed files with 36 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2015 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2006, 2023 Wind River Systems, Inc. and others.
|
||||
*
|
||||
* This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License 2.0
|
||||
|
@ -1414,4 +1414,37 @@ public abstract class IndexCPPBindingResolutionBugsTest extends IndexBindingReso
|
|||
public void testIssue_254() throws Exception {
|
||||
checkBindings();
|
||||
}
|
||||
|
||||
// // no header needed
|
||||
|
||||
// void introducing_in_global_ns(struct struct_in_global_ns *arg) {}
|
||||
//
|
||||
// class UsingStructFromGlobalNamespace {
|
||||
// struct_in_global_ns *p;
|
||||
// };
|
||||
//
|
||||
// UsingStructFromGlobalNamespace usingStructFromGlobalNs;
|
||||
//
|
||||
// namespace named {
|
||||
// void introducing_in_named_ns(struct struct_in_named_ns *arg) {}
|
||||
// }
|
||||
//
|
||||
// class UsingStructFromNamespaceNs {
|
||||
// named::struct_in_named_ns *p;
|
||||
// };
|
||||
//
|
||||
// UsingStructFromNamespaceNs usingStructFromNamespaceNs;
|
||||
//
|
||||
// namespace {
|
||||
// void introducing_in_anonymous_ns(struct struct_in_anonymous_ns *arg) {}
|
||||
// }
|
||||
//
|
||||
// class UsingStructFromAnonymousNs {
|
||||
// struct_in_anonymous_ns *p;
|
||||
// };
|
||||
//
|
||||
// UsingStructFromAnonymousNs usingStructFromAnonymousNs;
|
||||
public void testStructNameIntroducedInNamespace() throws Exception {
|
||||
checkBindings();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2016 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2023 IBM Corporation and others.
|
||||
*
|
||||
* This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License 2.0
|
||||
|
@ -2513,7 +2513,7 @@ public class CPPSemantics {
|
|||
IIndexFileSet indexFileSet = tu.getIndexFileSet();
|
||||
if (indexFileSet != null && indexFileSet.containsDeclaration(indexBinding)) {
|
||||
return true;
|
||||
} else if (indexBinding instanceof ICPPConstructor) {
|
||||
} else if (indexBinding instanceof ICPPConstructor || indexBinding instanceof ICPPClassType) {
|
||||
IIndexFileSet astFileSet = tu.getASTFileSet();
|
||||
return astFileSet != null && astFileSet.containsDeclaration(indexBinding);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue