Fix parsing of function declarations that return pointers.
Check that <op>= only evaluates the left-hand-side once.
diff --git a/libacc/acc.cpp b/libacc/acc.cpp
index f70c7a1..676947e 100644
--- a/libacc/acc.cpp
+++ b/libacc/acc.cpp
@@ -4409,15 +4409,11 @@
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;
}
diff --git a/libacc/tests/data/assignmentop.c b/libacc/tests/data/assignmentop.c
index 10b4637..649edf9 100644
--- a/libacc/tests/data/assignmentop.c
+++ b/libacc/tests/data/assignmentop.c
@@ -33,7 +33,6 @@
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 @@
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;
}
diff --git a/libacc/tests/test.py b/libacc/tests/test.py
index 4be1f4b..7bcbdd4 100644
--- a/libacc/tests/test.py
+++ b/libacc/tests/test.py
@@ -356,6 +356,13 @@
17&= 1 1
17^= 1 16
16|= 1 17
+*f() = *f() + 10;
+f()
+f()
+a = 10
+*f() += 10;
+f()
+a = 10
""")
def testcomma(self):