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);
|
ICPPFunction f2= ba.assertNonProblem("func(*b)", 4, ICPPFunction.class);
|
||||||
assertNotSame(f1, f2);
|
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 {
|
protected IASTExpression logicalOrExpression() throws BacktrackException, EndOfFileException {
|
||||||
IASTExpression firstExpression = logicalAndExpression();
|
IASTExpression firstExpression = logicalAndExpression();
|
||||||
while (LT(1) == IToken.tOR) {
|
while (LT(1) == IToken.tOR) {
|
||||||
|
if (shallRejectLogicalOperator()) {
|
||||||
|
throwBacktrack(LA(1));
|
||||||
|
}
|
||||||
|
|
||||||
consume();
|
consume();
|
||||||
IASTExpression secondExpression = logicalAndExpression();
|
IASTExpression secondExpression = logicalAndExpression();
|
||||||
firstExpression = buildBinaryExpression(
|
firstExpression = buildBinaryExpression(
|
||||||
|
@ -956,9 +960,17 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
return firstExpression;
|
return firstExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean shallRejectLogicalOperator() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected IASTExpression logicalAndExpression() throws BacktrackException, EndOfFileException {
|
protected IASTExpression logicalAndExpression() throws BacktrackException, EndOfFileException {
|
||||||
IASTExpression firstExpression = inclusiveOrExpression();
|
IASTExpression firstExpression = inclusiveOrExpression();
|
||||||
while (LT(1) == IToken.tAND) {
|
while (LT(1) == IToken.tAND) {
|
||||||
|
if (shallRejectLogicalOperator()) {
|
||||||
|
throwBacktrack(LA(1));
|
||||||
|
}
|
||||||
|
|
||||||
consume();
|
consume();
|
||||||
IASTExpression secondExpression = inclusiveOrExpression();
|
IASTExpression secondExpression = inclusiveOrExpression();
|
||||||
firstExpression = buildBinaryExpression(
|
firstExpression = buildBinaryExpression(
|
||||||
|
@ -1124,6 +1136,10 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
||||||
protected IASTExpression conditionalExpression() throws BacktrackException, EndOfFileException {
|
protected IASTExpression conditionalExpression() throws BacktrackException, EndOfFileException {
|
||||||
IASTExpression firstExpression = logicalOrExpression();
|
IASTExpression firstExpression = logicalOrExpression();
|
||||||
if (LT(1) == IToken.tQUESTION) {
|
if (LT(1) == IToken.tQUESTION) {
|
||||||
|
if (shallRejectLogicalOperator()) {
|
||||||
|
throwBacktrack(LA(1));
|
||||||
|
}
|
||||||
|
|
||||||
consume();
|
consume();
|
||||||
IASTExpression secondExpression= null;
|
IASTExpression secondExpression= null;
|
||||||
if (LT(1) != IToken.tCOLON) {
|
if (LT(1) != IToken.tCOLON) {
|
||||||
|
|
|
@ -201,16 +201,12 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
|
|
||||||
protected IASTName idExpression() throws EndOfFileException, BacktrackException {
|
protected IASTName idExpression() throws EndOfFileException, BacktrackException {
|
||||||
try {
|
try {
|
||||||
if (true) {
|
|
||||||
rejectLogicalOperatorInTemplateID++;
|
rejectLogicalOperatorInTemplateID++;
|
||||||
}
|
|
||||||
return qualifiedName();
|
return qualifiedName();
|
||||||
} finally {
|
} finally {
|
||||||
if (true) {
|
|
||||||
rejectLogicalOperatorInTemplateID--;
|
rejectLogicalOperatorInTemplateID--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a name.
|
* Parse a name.
|
||||||
|
@ -592,27 +588,9 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IASTExpression conditionalExpression() throws BacktrackException, EndOfFileException {
|
protected boolean shallRejectLogicalOperator() {
|
||||||
final IASTExpression expr= super.conditionalExpression();
|
return onTopInTemplateArgs && rejectLogicalOperatorInTemplateID > 0;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IASTExpression constantExpression() throws EndOfFileException, BacktrackException {
|
protected IASTExpression constantExpression() throws EndOfFileException, BacktrackException {
|
||||||
|
@ -2763,6 +2741,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
int startingOffset = mark.getOffset();
|
int startingOffset = mark.getOffset();
|
||||||
IASTDeclSpecifier declSpecifier = null;
|
IASTDeclSpecifier declSpecifier = null;
|
||||||
IASTDeclarator declarator = null;
|
IASTDeclarator declarator = null;
|
||||||
|
rejectLogicalOperatorInTemplateID++;
|
||||||
try {
|
try {
|
||||||
declSpecifier = declSpecifierSeq(option);
|
declSpecifier = declSpecifierSeq(option);
|
||||||
if (LT(1) != IToken.tEOC) {
|
if (LT(1) != IToken.tEOC) {
|
||||||
|
@ -2777,6 +2756,8 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
||||||
return null;
|
return null;
|
||||||
} catch (BacktrackException bt) {
|
} catch (BacktrackException bt) {
|
||||||
return null;
|
return null;
|
||||||
|
} finally {
|
||||||
|
rejectLogicalOperatorInTemplateID--;
|
||||||
}
|
}
|
||||||
IASTTypeId result = nodeFactory.newTypeId(declSpecifier, declarator);
|
IASTTypeId result = nodeFactory.newTypeId(declSpecifier, declarator);
|
||||||
((ASTNode) result).setOffsetAndLength(startingOffset, figureEndOffset(declSpecifier, declarator) - startingOffset);
|
((ASTNode) result).setOffsetAndLength(startingOffset, figureEndOffset(declSpecifier, declarator) - startingOffset);
|
||||||
|
|
Loading…
Add table
Reference in a new issue