mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 397210 - Name resolution problem with 'auto' and constructor
initializer
This commit is contained in:
parent
e43adf39dd
commit
d798ab8f2a
3 changed files with 21 additions and 15 deletions
|
@ -587,8 +587,8 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
return problemBinding;
|
||||
}
|
||||
|
||||
public <T extends IBinding> T assertNonProblemOnFirstIdentifier(String section, Class<T> type, Class... cs) {
|
||||
return assertNonProblem(section, getIdentifierLength(section), type, cs);
|
||||
public <T extends IBinding> T assertNonProblemOnFirstIdentifier(String section, Class... cs) {
|
||||
return assertNonProblem(section, getIdentifierLength(section), cs);
|
||||
}
|
||||
|
||||
public IBinding assertNonProblemOnFirstIdentifier(String section) {
|
||||
|
@ -678,7 +678,7 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
return selector.findImplicitName(offset, len);
|
||||
}
|
||||
|
||||
public <T extends IASTNode> T assertNode(String context, String nodeText, Class<T> type, Class... cs) {
|
||||
public <T extends IASTNode> T assertNode(String context, String nodeText, Class... cs) {
|
||||
if (context == null) {
|
||||
context = contents;
|
||||
}
|
||||
|
@ -688,11 +688,11 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
assertTrue("Node \"" + nodeText + "\" not found", nodeOffset >= 0);
|
||||
IASTNodeSelector selector = tu.getNodeSelector(null);
|
||||
IASTNode node = selector.findNode(offset + nodeOffset, nodeText.length());
|
||||
return assertType(node, type, cs);
|
||||
return assertType(node, cs);
|
||||
}
|
||||
|
||||
public <T extends IASTNode> T assertNode(String nodeText, Class<T> type, Class... cs) {
|
||||
return assertNode(contents, nodeText, type, cs);
|
||||
public <T extends IASTNode> T assertNode(String nodeText, Class... cs) {
|
||||
return assertNode(contents, nodeText, cs);
|
||||
}
|
||||
|
||||
private String renderProblemID(int i) {
|
||||
|
@ -713,31 +713,30 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
return "Unknown problem ID";
|
||||
}
|
||||
|
||||
public <T extends IBinding> T assertNonProblem(String section, int len, Class<T> type, Class... cs) {
|
||||
public <T extends IBinding> T assertNonProblem(String section, int len, Class... cs) {
|
||||
if (len <= 0)
|
||||
len += section.length();
|
||||
IBinding binding= binding(section, len);
|
||||
assertTrue("ProblemBinding for name: " + section.substring(0, len),
|
||||
!(binding instanceof IProblemBinding));
|
||||
return assertType(binding, type, cs);
|
||||
return assertType(binding, cs);
|
||||
}
|
||||
|
||||
public <T extends IBinding> T assertNonProblem(String section, Class<T> type, Class... cs) {
|
||||
return assertNonProblem(section, section.length(), type, cs);
|
||||
public <T extends IBinding> T assertNonProblem(String section, Class... cs) {
|
||||
return assertNonProblem(section, section.length(), cs);
|
||||
}
|
||||
|
||||
public <T extends IBinding> T assertNonProblem(String context, String name, Class<T> type, Class... cs) {
|
||||
public <T extends IBinding> T assertNonProblem(String context, String name, Class... cs) {
|
||||
IBinding binding= binding(context, name);
|
||||
assertTrue("ProblemBinding for name: " + name, !(binding instanceof IProblemBinding));
|
||||
return assertType(binding, type, cs);
|
||||
return assertType(binding, cs);
|
||||
}
|
||||
|
||||
public <T, U extends T> U assertType(T obj, Class<U> type, Class... cs) {
|
||||
assertInstance(obj, type);
|
||||
public <T, U extends T> U assertType(T obj, Class... cs) {
|
||||
for (Class c : cs) {
|
||||
assertInstance(obj, c);
|
||||
}
|
||||
return type.cast(obj);
|
||||
return (U) obj;
|
||||
}
|
||||
|
||||
private IBinding binding(String section, int len) {
|
||||
|
|
|
@ -8405,6 +8405,7 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
// }
|
||||
// struct A {};
|
||||
// A a;
|
||||
// auto c(a);
|
||||
// auto b = a;
|
||||
// const auto *p = &b, q = "";
|
||||
// static auto d = 0.0;
|
||||
|
@ -8418,6 +8419,8 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
|
||||
ICPPVariable b= bh.assertNonProblem("b =", 1);
|
||||
assertEquals("A", ASTTypeUtil.getType(b.getType()));
|
||||
ICPPVariable c= bh.assertNonProblem("c(a)", "c");
|
||||
assertEquals("A", ASTTypeUtil.getType(c.getType()));
|
||||
ICPPVariable p= bh.assertNonProblem("p =", 1);
|
||||
assertEquals("const A *", ASTTypeUtil.getType(p.getType()));
|
||||
ICPPVariable q= bh.assertNonProblem("q =", 1);
|
||||
|
|
|
@ -2038,6 +2038,10 @@ public class CPPVisitor extends ASTQueries {
|
|||
IASTInitializer initClause= declarator.getInitializer();
|
||||
if (initClause instanceof IASTEqualsInitializer) {
|
||||
autoInitClause= (ICPPASTInitializerClause) ((IASTEqualsInitializer) initClause).getInitializerClause();
|
||||
} else if (initClause instanceof ICPPASTConstructorInitializer) {
|
||||
IASTInitializerClause[] arguments = ((ICPPASTConstructorInitializer) initClause).getArguments();
|
||||
if (arguments.length == 1)
|
||||
autoInitClause = (ICPPASTInitializerClause) arguments[0];
|
||||
} else if (initClause instanceof ICPPASTInitializerClause) {
|
||||
autoInitClause= (ICPPASTInitializerClause) initClause;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue