mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Nested template-id ambiguity, bug 259501.
This commit is contained in:
parent
f22dca4261
commit
4c5c6bc7d3
3 changed files with 38 additions and 26 deletions
|
@ -6331,4 +6331,19 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
ICPPFunction f2= ba.assertNonProblem("func(*b)", 4, ICPPFunction.class);
|
||||
assertNotSame(f1, f2);
|
||||
}
|
||||
|
||||
// struct C {int a;};
|
||||
// void myfunc(C c) {
|
||||
// return c < c.a ||
|
||||
// (c == c.a && (c<c.a || (c == c.a && (c<c.a || (c == c.a && (c<c.a ||
|
||||
// (c == c.a && (c<c.a || (c == c.a && (c<c.a || (c == c.a && (c<c.a ||
|
||||
// (c == c.a && (c<c.a || (c == c.a && (c<c.a || (c == c.a && (c<c.a ||
|
||||
// (c == c.a && (c<c.a || (c == c.a && (c<c.a || (c == c.a && (c<c.a ||
|
||||
// (c == c.a && (c<c.a || (c == c.a && (c<c.a || (c == c.a && (c<c.a
|
||||
// ))))))))))))))))))))))))))))));
|
||||
// }
|
||||
public void testNestedTemplateIDAmbiguity_259501() throws Exception {
|
||||
final String code= getAboveComment();
|
||||
parseAndCheckBindings(code);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -947,6 +947,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
protected IASTExpression logicalOrExpression() throws BacktrackException, EndOfFileException {
|
||||
IASTExpression firstExpression = logicalAndExpression();
|
||||
while (LT(1) == IToken.tOR) {
|
||||
if (shallRejectLogicalOperator()) {
|
||||
throwBacktrack(LA(1));
|
||||
}
|
||||
|
||||
consume();
|
||||
IASTExpression secondExpression = logicalAndExpression();
|
||||
firstExpression = buildBinaryExpression(
|
||||
|
@ -956,9 +960,17 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
return firstExpression;
|
||||
}
|
||||
|
||||
protected boolean shallRejectLogicalOperator() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected IASTExpression logicalAndExpression() throws BacktrackException, EndOfFileException {
|
||||
IASTExpression firstExpression = inclusiveOrExpression();
|
||||
while (LT(1) == IToken.tAND) {
|
||||
if (shallRejectLogicalOperator()) {
|
||||
throwBacktrack(LA(1));
|
||||
}
|
||||
|
||||
consume();
|
||||
IASTExpression secondExpression = inclusiveOrExpression();
|
||||
firstExpression = buildBinaryExpression(
|
||||
|
@ -1124,6 +1136,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
protected IASTExpression conditionalExpression() throws BacktrackException, EndOfFileException {
|
||||
IASTExpression firstExpression = logicalOrExpression();
|
||||
if (LT(1) == IToken.tQUESTION) {
|
||||
if (shallRejectLogicalOperator()) {
|
||||
throwBacktrack(LA(1));
|
||||
}
|
||||
|
||||
consume();
|
||||
IASTExpression secondExpression= null;
|
||||
if (LT(1) != IToken.tCOLON) {
|
||||
|
|
|
@ -201,14 +201,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
|
||||
protected IASTName idExpression() throws EndOfFileException, BacktrackException {
|
||||
try {
|
||||
if (true) {
|
||||
rejectLogicalOperatorInTemplateID++;
|
||||
}
|
||||
rejectLogicalOperatorInTemplateID++;
|
||||
return qualifiedName();
|
||||
} finally {
|
||||
if (true) {
|
||||
rejectLogicalOperatorInTemplateID--;
|
||||
}
|
||||
rejectLogicalOperatorInTemplateID--;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -592,28 +588,10 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected IASTExpression conditionalExpression() throws BacktrackException, EndOfFileException {
|
||||
final IASTExpression expr= super.conditionalExpression();
|
||||
if (onTopInTemplateArgs && rejectLogicalOperatorInTemplateID > 0) {
|
||||
// bug 104706, don't allow usage of logical operators in template argument lists.
|
||||
if (expr instanceof IASTConditionalExpression) {
|
||||
final ASTNode node = (ASTNode) expr;
|
||||
throwBacktrack(node.getOffset(), node.getLength());
|
||||
}
|
||||
else if (expr instanceof IASTBinaryExpression) {
|
||||
IASTBinaryExpression bexpr= (IASTBinaryExpression) expr;
|
||||
switch (bexpr.getOperator()) {
|
||||
case IASTBinaryExpression.op_logicalAnd:
|
||||
case IASTBinaryExpression.op_logicalOr:
|
||||
final ASTNode node = (ASTNode) expr;
|
||||
throwBacktrack(node.getOffset(), node.getLength());
|
||||
}
|
||||
}
|
||||
}
|
||||
return expr;
|
||||
protected boolean shallRejectLogicalOperator() {
|
||||
return onTopInTemplateArgs && rejectLogicalOperatorInTemplateID > 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected IASTExpression constantExpression() throws EndOfFileException, BacktrackException {
|
||||
final boolean wasOnTop= onTopInTemplateArgs;
|
||||
|
@ -2763,6 +2741,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
int startingOffset = mark.getOffset();
|
||||
IASTDeclSpecifier declSpecifier = null;
|
||||
IASTDeclarator declarator = null;
|
||||
rejectLogicalOperatorInTemplateID++;
|
||||
try {
|
||||
declSpecifier = declSpecifierSeq(option);
|
||||
if (LT(1) != IToken.tEOC) {
|
||||
|
@ -2777,6 +2756,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
return null;
|
||||
} catch (BacktrackException bt) {
|
||||
return null;
|
||||
} finally {
|
||||
rejectLogicalOperatorInTemplateID--;
|
||||
}
|
||||
IASTTypeId result = nodeFactory.newTypeId(declSpecifier, declarator);
|
||||
((ASTNode) result).setOffsetAndLength(startingOffset, figureEndOffset(declSpecifier, declarator) - startingOffset);
|
||||
|
|
Loading…
Add table
Reference in a new issue