Module Name:    src
Committed By:   rillig
Date:           Sun Nov 21 11:02:25 UTC 2021

Modified Files:
        src/tests/usr.bin/indent: fmt_decl.c

Log Message:
tests/indent: demonstrate wrong formatting of type names in declarations


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/tests/usr.bin/indent/fmt_decl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/indent/fmt_decl.c
diff -u src/tests/usr.bin/indent/fmt_decl.c:1.21 src/tests/usr.bin/indent/fmt_decl.c:1.22
--- src/tests/usr.bin/indent/fmt_decl.c:1.21	Sat Nov 20 11:13:18 2021
+++ src/tests/usr.bin/indent/fmt_decl.c	Sun Nov 21 11:02:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: fmt_decl.c,v 1.21 2021/11/20 11:13:18 rillig Exp $	*/
+/*	$NetBSD: fmt_decl.c,v 1.22 2021/11/21 11:02:25 rillig Exp $	*/
 /* $FreeBSD: head/usr.bin/indent/tests/declarations.0 334478 2018-06-01 09:41:15Z pstef $ */
 
 /*
@@ -531,3 +531,43 @@ int	       *aaaaaaaaaaaaaaaaaaaaaaaaaaaa
 		(void){
 }
 #indent end
+
+
+/*
+ * Before 1990, when C90 standardized function prototypes, a function
+ * declaration or definition did not contain a '*' that may have looked
+ * similar to the binary operator '*' because it was surrounded by two
+ * identifiers.
+ *
+ * As of 2021-11-21, indent interprets the '*' in the function declaration in
+ * line 1 as a binary operator, even though it is followed by a ',' directly.
+ * In the function declaration in line 2, as well as the function definition
+ * in line 4, indent interprets the '*' as a binary operator as well, which
+ * kind of makes sense since it is surrounded by words, but it's still in a
+ * declaration.
+ *
+ * Essentially, as of 2021, indent has missed the last 31 years of advances in
+ * the C programming language.  Instead, the workaround has been to pass all
+ * type names via the options '-ta' and '-T'.
+ */
+#indent input
+void		buffer_add(buffer *, char);
+void		buffer_add(buffer *buf, char ch);
+
+void
+buffer_add(buffer *buf, char ch)
+{
+	*buf->e++ = ch;
+}
+#indent end
+
+#indent run
+void		buffer_add(buffer *, char);
+void		buffer_add(buffer * buf, char ch);
+
+void
+buffer_add(buffer * buf, char ch)
+{
+	*buf->e++ = ch;
+}
+#indent end

Reply via email to