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

Declaration - expression ambiguity with function call on lhs of binary expression, bug 252695.

This commit is contained in:
Markus Schorn 2008-10-30 11:07:20 +00:00
parent 70431722fe
commit a831e865be
4 changed files with 35 additions and 6 deletions

View file

@ -6186,4 +6186,25 @@ public class AST2CPPTests extends AST2BaseTest {
assertSame(decl, func);
}
}
// class MyClass{
// public:
// int v;
// int& operator () (int i){ return v; }
// int& operator () (int i, int j){ return v; }
// };
//
// int main(MyClass c, int i){
// c(i,i)= 0;
// c(i) = 0;
// }
public void testFunctionCallOnLHS_252695() throws Exception {
final String code = getAboveComment();
IASTTranslationUnit tu= parseAndCheckBindings(code, ParserLanguage.CPP, true);
IASTFunctionDefinition fdef= getDeclaration(tu, 1);
IASTExpressionStatement exstmt= getStatement(fdef, 0);
assertInstance(exstmt.getExpression(), IASTBinaryExpression.class);
exstmt= getStatement(fdef, 1);
assertInstance(exstmt.getExpression(), IASTBinaryExpression.class);
}
}

View file

@ -117,8 +117,14 @@ public class IndexBugsTests extends BaseTestCase {
return TestSourceReader.createFile(container, new Path(fileName), contents);
}
private void waitForIndexer() {
assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEX_WAIT_TIME, NPM));
private void waitForIndexer() throws InterruptedException {
final IIndexManager indexManager = CCorePlugin.getIndexManager();
long waitms= 1;
while (waitms < 2000 && indexManager.isIndexerSetupPostponed(fCProject)) {
Thread.sleep(waitms);
waitms*=2;
}
assertTrue(indexManager.joinIndexer(INDEX_WAIT_TIME, NPM));
}
protected Pattern[] getPattern(String qname) {

View file

@ -100,6 +100,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
protected boolean supportExtendedSizeofOperator;
protected final IBuiltinBindingsProvider builtinBindingsProvider;
protected boolean functionCallCanBeLValue= false;
/**
* Marks the beginning of the current declaration. It is important to clear the mark whenever we
* enter a nested declaration, in order to avoid holding on to all the tokens.
@ -1648,9 +1650,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
// At this point we know we have an ambiguity.
// Attempt to resolve some ambiguities that are easy to detect.
// A * B = C;
// foo() = x;
// These can get parsed as expressions but the lvalue doesn't make sense
// A * B = C; // A*B cannot be a lvalue.
// foo() = x; // foo() cannot be a lvalue in c, in c++ it can.
if (expressionStatement.getExpression() instanceof IASTBinaryExpression) {
IASTBinaryExpression exp = (IASTBinaryExpression) expressionStatement.getExpression();
if (exp.getOperator() == IASTBinaryExpression.op_assign) {
@ -1659,7 +1660,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
&& ((IASTBinaryExpression) lhs).getOperator() == IASTBinaryExpression.op_multiply) {
return ds;
}
if (lhs instanceof IASTFunctionCallExpression) {
if (lhs instanceof IASTFunctionCallExpression && !functionCallCanBeLValue) {
return ds;
}
}

View file

@ -206,6 +206,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
supportParameterInfoBlock= config.supportParameterInfoBlock();
supportExtendedSizeofOperator= config.supportExtendedSizeofOperator();
supportFunctionStyleAsm= config.supportFunctionStyleAssembler();
functionCallCanBeLValue= true;
this.index= index;
}