/*
* Parse and validate C declarations.
- * Copyright © 2011-2012 Nick Bowler
+ * Copyright © 2011-2012, 2020 Nick Bowler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* if a declarator could be interpreted as something other than a function,
* do that.
*
- * - The function declarator has a null child declarator.
- * - The function declarator has exactly one parameter, and is not variadic.
- * - The function parameter has a type specifier, and it is a typedef name.
- * - The function parameter has no other declaration specifiers.
- * - The function parameter does not declare an identifier.
- *
* Since cdecl99 supports things like [*] in any context (in C, such constructs
* are only valid in function parameter lists), we don't treat them specially
* here.
return false; /* e.g. int (int) */
if (d->u.function.parameters->specifiers->next)
return false; /* e.g. int (size_t const) */
+ if (d->u.function.parameters->declarators->type == CDECL_DECL_POINTER)
+ return false; /* e.g. int (x *) */
return true;
}
--- /dev/null
+# Copyright © 2020 Nick Bowler
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+AT_BANNER([C declarations])
+
+m4_define([CHECK_DECL],
+[AT_DATA([expout], [[$2]m4_newline])
+AT_CHECK([cdecl99 -e 'explain $1'], [0], [expout])])
+
+m4_define([SIMPLE_DECL],
+[AT_SETUP([$1])
+CHECK_DECL([$1], [$2])
+AT_CLEANUP])
+
+SIMPLE_DECL([int (x*)], [type function (pointer to x) returning int])
m4_divert_pop([PREPARE_TESTS])
m4_include([tests/general.at])
+m4_include([tests/decl-good.at])
m4_include([tests/decl-bad.at])