aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-04-27 16:15:11 -0700
committerMichael Forney <mforney@mforney.org>2019-04-27 16:15:11 -0700
commit9b52864932ec81033b5c9d34a81828d54192b958 (patch)
tree0ff70afba3dfa895f31a6940468123e1fa69704a
parent231137aceb65c4b1ca0b54dd599f1f8b8c5c9342 (diff)
downloadcproc-9b52864932ec81033b5c9d34a81828d54192b958.tar.xz
Fix some function declarator corner cases
-rw-r--r--decl.c11
-rw-r--r--test/abstract-function-declarator.c16
-rw-r--r--test/abstract-function-declarator.qbe0
3 files changed, 26 insertions, 1 deletions
diff --git a/decl.c b/decl.c
index 3ebf51a..35ba57a 100644
--- a/decl.c
+++ b/decl.c
@@ -462,8 +462,17 @@ declaratortypes(struct scope *s, struct list *result, char **name, bool allowabs
switch (tok.kind) {
case TLPAREN:
next();
- if (allowabstract && tok.kind != TMUL && (tok.kind != TIDENT || istypename(s, tok.lit)))
+ switch (tok.kind) {
+ case TMUL:
+ case TLPAREN:
+ break;
+ case TIDENT:
+ if (!allowabstract || !istypename(s, tok.lit))
+ break;
+ /* fallthrough */
+ default:
goto func;
+ }
declaratortypes(s, result, name, allowabstract);
expect(TRPAREN, "after parenthesized declarator");
break;
diff --git a/test/abstract-function-declarator.c b/test/abstract-function-declarator.c
new file mode 100644
index 0000000..b6808a6
--- /dev/null
+++ b/test/abstract-function-declarator.c
@@ -0,0 +1,16 @@
+typedef int x;
+
+void f1(int(x));
+void f1(int (*)(int));
+
+void f2(int(y));
+void f2(int);
+
+void f3(int((*)));
+void f3(int *);
+
+void f4(int((*x)));
+void f4(int *);
+
+void f5(int((x)));
+void f5(int (*)(int));
diff --git a/test/abstract-function-declarator.qbe b/test/abstract-function-declarator.qbe
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/abstract-function-declarator.qbe