mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
Create problem for id-expressions resolving to types, bug 261175.
This commit is contained in:
parent
01ab0bb184
commit
727408d5c0
5 changed files with 40 additions and 35 deletions
|
@ -6560,7 +6560,6 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertTrue(!bar_ft.isConst()); assertTrue(!bar_ft.isVolatile());
|
||||
}
|
||||
|
||||
|
||||
// void test1(float f);
|
||||
// void test1(void);
|
||||
// void blabla() {
|
||||
|
@ -6577,4 +6576,18 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
final String code= getAboveComment();
|
||||
parseAndCheckBindings(code);
|
||||
}
|
||||
|
||||
// enum E {e1};
|
||||
// typedef int TInt;
|
||||
// void select(int);
|
||||
// void test() {
|
||||
// int a= TInt(1);
|
||||
// E e= E(0);
|
||||
// void* h;
|
||||
// select (int (h) + 1);
|
||||
// }
|
||||
public void testSimpleTypeConstructorExpressions() throws Exception {
|
||||
final String code= getAboveComment();
|
||||
parseAndCheckBindings(code);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5969,4 +5969,15 @@ public class AST2Tests extends AST2BaseTest {
|
|||
assertSame(s1, t.getType());
|
||||
}
|
||||
}
|
||||
|
||||
// typedef int TInt;
|
||||
// int a= TInt; //ref
|
||||
public void testTypeAsExpressionIsProblem_261175() throws Exception {
|
||||
final String code= getAboveComment();
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
|
||||
bh.assertProblem("TInt; //ref", 4);
|
||||
|
||||
bh= new BindingAssertionHelper(code, false);
|
||||
bh.assertProblem("TInt; //ref", 4);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,14 +13,11 @@ package org.eclipse.cdt.internal.core.dom.parser;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplatedTypeTemplateParameter;
|
||||
import org.eclipse.cdt.core.parser.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
|
@ -109,13 +106,7 @@ public abstract class ASTAmbiguousNode extends ASTNode {
|
|||
IBinding b= name.resolvePreBinding();
|
||||
if (b instanceof IProblemBinding) {
|
||||
issues++;
|
||||
} else if (b instanceof IType && name.getPropertyInParent() == IASTIdExpression.ID_NAME) {
|
||||
// mstodo misused types, should be part of postResolution.
|
||||
IASTNode grand= name.getParent().getParent();
|
||||
if (!(grand instanceof ICPPASTTemplatedTypeTemplateParameter)) {
|
||||
issues++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception t) {
|
||||
issues++;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.IASTAmbiguityParent;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
|
@ -98,7 +97,6 @@ public class CPPASTSimpleTypeConstructorExpression extends ASTNode implements
|
|||
}
|
||||
|
||||
public IType getExpressionType() {
|
||||
return CPPVisitor.getExpressionType(this);
|
||||
return new CPPBasicType(st, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -316,18 +316,8 @@ public class CPPSemantics {
|
|||
}
|
||||
|
||||
if (data.considerConstructors) {
|
||||
ICPPClassType cls= null;
|
||||
// if (binding instanceof ITypedef) {
|
||||
// // mstodo constructor off typedef
|
||||
// IType t= SemanticUtil.getUltimateTypeViaTypedefs((IType) binding);
|
||||
// if (t instanceof ICPPClassType) {
|
||||
// cls= (ICPPClassType) t;
|
||||
// }
|
||||
// } else
|
||||
if (binding instanceof ICPPClassType) {
|
||||
cls= (ICPPClassType) binding;
|
||||
}
|
||||
if (cls != null) {
|
||||
ICPPClassType cls= (ICPPClassType) binding;
|
||||
try {
|
||||
if (data.astName instanceof ICPPASTTemplateId && cls instanceof ICPPClassTemplate) {
|
||||
if (data.tu != null) {
|
||||
|
@ -401,16 +391,18 @@ public class CPPSemantics {
|
|||
binding = new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE);
|
||||
}
|
||||
}
|
||||
// mstodo misused types, important for ambiguity resolution.
|
||||
// } else if (namePropertyInParent == IASTIdExpression.ID_NAME) {
|
||||
// if (binding instanceof IType) {
|
||||
// IASTNode parent= name.getParent().getParent();
|
||||
// if (parent instanceof ICPPASTTemplatedTypeTemplateParameter) {
|
||||
// // default for template template parameter is an id-expression, which is a type.
|
||||
// } else {
|
||||
// binding= new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE);
|
||||
// }
|
||||
// }
|
||||
} else if (namePropertyInParent == IASTIdExpression.ID_NAME) {
|
||||
if (binding instanceof IType) {
|
||||
IASTNode parent= name.getParent().getParent();
|
||||
if (parent instanceof ICPPASTTemplatedTypeTemplateParameter) {
|
||||
// default for template template parameter is an id-expression, which is a type.
|
||||
} else if (data.considerConstructors &&
|
||||
(binding instanceof ICPPUnknownType || binding instanceof ITypedef || binding instanceof IEnumeration)) {
|
||||
// constructor or simple-type constructor
|
||||
} else {
|
||||
binding= new ProblemBinding(data.astName, IProblemBinding.SEMANTIC_INVALID_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue