Fix parsing of function declarations that return pointers.

Check that <op>= only evaluates the left-hand-side once.
This commit is contained in:
Jack Palevich 2009-07-31 15:58:19 -07:00
parent 47cbea9c69
commit 96138992ac
3 changed files with 10 additions and 11 deletions

View file

@ -4409,15 +4409,11 @@ class Compiler : public ErrorSink {
Type* acceptDecl2(Type* pType, tokenid_t& declName,
bool nameAllowed, bool nameRequired,
bool& reportFailure) {
int ptrCounter = 0;
while (accept('*')) {
ptrCounter++;
pType = createType(TY_POINTER, pType, NULL);
}
pType = acceptDecl3(pType, declName, nameAllowed, nameRequired,
reportFailure);
while (ptrCounter-- > 0) {
pType = createType(TY_POINTER, pType, NULL);
}
return pType;
}

View file

@ -33,7 +33,6 @@ void testAssignment() {
printf("16|= 1 %d\n", a);
}
/* Can't use because int* f() is not parsed as a function decl.
int a;
int* f() {
@ -43,24 +42,21 @@ int* f() {
void testEval() {
a = 0;
printf("*f() = *f() + 10;");
printf("*f() = *f() + 10;\n");
*f() = *f() + 10;
printf("a = %d\n", a);
}
void testOpEval() {
a = 0;
printf("*f() += 10;");
printf("*f() += 10;\n");
*f() += 10;
printf("a = %d\n", a);
}
*/
int main() {
testAssignment();
/*
testEval();
testOpEval();
*/
return 0;
}

View file

@ -356,6 +356,13 @@ result: 0""", """2 *= 5 10
17&= 1 1
17^= 1 16
16|= 1 17
*f() = *f() + 10;
f()
f()
a = 10
*f() += 10;
f()
a = 10
""")
def testcomma(self):