1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 403153 - C structure whose first declaration is inside a structure

C does not have a notion of structure scope, so the declared structure
has file scope in spite of being declared inside a structure.

Change-Id: I39b9dfe36c7da19b70e79e0a1cd822d91832dcd8
This commit is contained in:
Nathan Ridge 2018-02-27 00:43:13 -05:00
parent bcc81b20c1
commit 107bfee755
2 changed files with 37 additions and 0 deletions

View file

@ -100,6 +100,7 @@ import org.eclipse.cdt.core.dom.ast.IMacroBinding;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IPointerType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IProblemType;
import org.eclipse.cdt.core.dom.ast.IQualifierType;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
@ -7716,4 +7717,32 @@ public class AST2Tests extends AST2TestBase {
BindingAssertionHelper helper = getAssertionHelper(C);
helper.assertProblem("s.waldo", "waldo");
}
// struct gendisk {
// struct request_queue *queue;
// };
//
// typedef struct request_queue request_queue_t;
//
// typedef void (request_fn_proc) (request_queue_t *q);
//
// struct request_queue {
// request_fn_proc *request_fn;
// };
//
// int main() {
// struct gendisk *gd = 0;
//
// // The expression type of *gd->queue-request_fn is a CProblemType
// // with message "Failure to determine type of expression"
// (*gd->queue->request_fn)(0);
//
// return 0;
// }
public void testProblemExpressionType_403153() throws Exception {
BindingAssertionHelper helper = getAssertionHelper(C);
IASTExpression expr = helper.assertNode("*gd->queue->request_fn");
assertNotNull(expr);
assertFalse(expr.getExpressionType() instanceof IProblemType);
}
}

View file

@ -1145,6 +1145,14 @@ public class CVisitor extends ASTQueries {
private static IASTNode findDefinition(IASTNode decl, char[] declName, int beginAtLoc) {
IASTNode blockItem = getContainingBlockItem(decl);
IASTNode parent = blockItem.getParent();
if (parent instanceof IASTCompositeTypeSpecifier) {
// C does not have a notion of structure scope.
// Types names declared in a structure have file scope.
parent = parent.getParent(); // This will be the declaration
if (parent != null) {
parent = parent.getParent();
}
}
IASTNode[] list = null;
if (parent instanceof IASTCompoundStatement) {
IASTCompoundStatement compound = (IASTCompoundStatement) parent;