aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNeil Booth <neil@daikokuya.co.uk>2002-06-22 11:08:20 +0000
committerNeil Booth <neil@gcc.gnu.org>2002-06-22 11:08:20 +0000
commit847c76c86abab21f77c80bf224c35869f6a12736 (patch)
treed5cc8fde896535a17af7b0bd1b7317936cbd2e85 /gcc
parent112bae7721708444619bfd87e881226918d9fd1b (diff)
downloadgcc-847c76c86abab21f77c80bf224c35869f6a12736.zip
gcc-847c76c86abab21f77c80bf224c35869f6a12736.tar.gz
gcc-847c76c86abab21f77c80bf224c35869f6a12736.tar.bz2
cpptrad.c (struct fun_macro): Add line number.
* cpptrad.c (struct fun_macro): Add line number. (scan_out_logical_line): Set it, and use it to report unterminated macro invocations. testsuite: * gcc.dg/cpp/trad/comment-2.c. gcc.dg/cpp/trad/funlike-2.c, gcc.dg/cpp/trad/funlike.c, gcc.dg/cpp/trad/funlike-3.c, gcc.dg/cpp/trad/literals-1.c, gcc.dg/cpp/trad/literals-2.c, gcc.dg/cpp/trad/macroargs.c, gcc.dg/cpp/trad/quote.c: New tests. From-SVN: r54907
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/cpptrad.c10
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.dg/cpp/trad/comment-2.c11
-rw-r--r--gcc/testsuite/gcc.dg/cpp/trad/funlike-2.c23
-rw-r--r--gcc/testsuite/gcc.dg/cpp/trad/funlike-3.c12
-rw-r--r--gcc/testsuite/gcc.dg/cpp/trad/funlike.c25
-rw-r--r--gcc/testsuite/gcc.dg/cpp/trad/literals-1.c28
-rw-r--r--gcc/testsuite/gcc.dg/cpp/trad/literals-2.c8
-rw-r--r--gcc/testsuite/gcc.dg/cpp/trad/macroargs.c24
-rw-r--r--gcc/testsuite/gcc.dg/cpp/trad/quote.c6
11 files changed, 157 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ea2f1e5..0d3a098 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2002-06-22 Neil Booth <neil@daikokuya.co.uk>
+
+ * cpptrad.c (struct fun_macro): Add line number.
+ (scan_out_logical_line): Set it, and use it to report unterminated
+ macro invocations.
+
2002-06-21 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* genautomata.c (copy_node, VLA_PTR_CREATE, VLA_PTR_EXPAND,
diff --git a/gcc/cpptrad.c b/gcc/cpptrad.c
index b3413d0..22320c4 100644
--- a/gcc/cpptrad.c
+++ b/gcc/cpptrad.c
@@ -59,6 +59,9 @@ struct fun_macro
/* The offset of the macro name in the output buffer. */
size_t offset;
+ /* The line the macro name appeared on. */
+ unsigned int line;
+
/* Zero-based index of argument being currently lexed. */
unsigned int argc;
};
@@ -586,6 +589,7 @@ scan_out_logical_line (pfile, macro)
{
maybe_start_funlike (pfile, node, out_start, &fmacro);
lex_state = ls_fun_open;
+ fmacro.line = pfile->line;
continue;
}
else
@@ -721,9 +725,9 @@ scan_out_logical_line (pfile, macro)
_cpp_release_buff (pfile, fmacro.buff);
if (lex_state == ls_fun_close)
- cpp_error (pfile, DL_ERROR,
- "unterminated argument list invoking macro \"%s\"",
- NODE_NAME (fmacro.node));
+ cpp_error_with_line (pfile, DL_ERROR, fmacro.line, 0,
+ "unterminated argument list invoking macro \"%s\"",
+ NODE_NAME (fmacro.node));
}
/* Push a context holding the replacement text of the macro NODE on
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 75b2189..52b8c9b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2002-06-22 Neil Booth <neil@daikokuya.co.uk>
+
+ * gcc.dg/cpp/trad/comment-2.c. gcc.dg/cpp/trad/funlike-2.c,
+ gcc.dg/cpp/trad/funlike.c, gcc.dg/cpp/trad/funlike-3.c,
+ gcc.dg/cpp/trad/literals-1.c, gcc.dg/cpp/trad/literals-2.c,
+ gcc.dg/cpp/trad/macroargs.c, gcc.dg/cpp/trad/quote.c: New tests.
+
2002-06-21 Neil Booth <neil@daikokuya.co.uk>
* gcc.dg/cpp/trad: New directory with traditional tests copied
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/comment-2.c b/gcc/testsuite/gcc.dg/cpp/trad/comment-2.c
new file mode 100644
index 0000000..8d54e3a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/trad/comment-2.c
@@ -0,0 +1,11 @@
+/* Test for warning of nested comments. */
+
+/* { dg-do preprocess } */
+
+/* { dg-options "-traditional-cpp -Wcomments" }
+
+/* /* */ /* { dg-warning "within comment" } */
+
+/*
+
+ /* { dg-warning "within comment" } */
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/funlike-2.c b/gcc/testsuite/gcc.dg/cpp/trad/funlike-2.c
new file mode 100644
index 0000000..edcf2ab
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/trad/funlike-2.c
@@ -0,0 +1,23 @@
+/* Test that nested commas and parentheses in macro arguments are
+ OK. */
+
+/* { dg-do preprocess } */
+
+#define f(x) x
+#define g(x, y) x y
+
+#if f((1)) != 1
+# error /* { dg-bogus "error" "nested parens 1" } */
+#endif
+
+#if f((1, 2)) != 2
+# error /* { dg-bogus "error" "nested comma 1" } */
+#endif
+
+#if g(, (1)) != 1
+# error /* { dg-bogus "error" "nested parens 2" } */
+#endif
+
+#if g((1, 2), + 3) != 5
+# error /* { dg-bogus "error" "nested comma 2" } */
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/funlike-3.c b/gcc/testsuite/gcc.dg/cpp/trad/funlike-3.c
new file mode 100644
index 0000000..5300afb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/trad/funlike-3.c
@@ -0,0 +1,12 @@
+/* Test that function-like macros are restricted to directives, and
+ that unterminated ones are warned about. */
+
+/* { dg-do preprocess } */
+
+#define f(x) x
+
+#if 2 f(/* { dg-error "unterminated" "unterminated macro in directive" } */
+)
+#endif
+
+f( /* { dg-error "unterminated" "unterminated macro" } */
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/funlike.c b/gcc/testsuite/gcc.dg/cpp/trad/funlike.c
new file mode 100644
index 0000000..db550d5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/trad/funlike.c
@@ -0,0 +1,25 @@
+/* Test that undefined names evaluate to zero, that macros after a
+ funlike macro are expanded, and that if it is a '(' the funlike
+ macro is not treated as such. */
+
+/* { dg-do preprocess } */
+
+#define f(x) x
+#define h != 0
+#define i
+#define paren (
+
+#if f != 0
+# error /* { dg-bogus "error" "undefined name" } */
+#endif
+
+#if f h
+# error /* { dg-bogus "error" "h not expanded" } */
+#endif
+
+#if f i
+# error /* { dg-bogus "error" "empty macro" } */
+#endif
+
+#if f paren 6) /* { dg-error "missing binary" "macro-expanded parenthesis" } */
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/literals-1.c b/gcc/testsuite/gcc.dg/cpp/trad/literals-1.c
new file mode 100644
index 0000000..7fde0d5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/trad/literals-1.c
@@ -0,0 +1,28 @@
+/* Test that (what looks like) comments are not recognised in literals
+ and that quotes within quotes do not confused the preprocessor. */
+
+/* { dg-do run } */
+
+extern void abort (void);
+
+int main ()
+{
+ const char *str1 = "/*";
+ const char *str2 = "'";
+
+ if (str1[0] != '/' || str1[1] != '*' || str1[2] != '\0')
+ abort ();
+
+ if (str2[0] != '\'' || str2[1] != '\0')
+ abort ();
+
+#if '"' != '\"'
+# error /* { dg-bogus "error" "double quote in charconst" } */
+#endif
+
+#if !'\''
+# error quote /* { dg-bogus "quote" "quote in charconst" } */
+#endif
+
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/literals-2.c b/gcc/testsuite/gcc.dg/cpp/trad/literals-2.c
new file mode 100644
index 0000000..807bb0d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/trad/literals-2.c
@@ -0,0 +1,8 @@
+/* Test that unterminated quotes in CPP expressions are
+ recognized. */
+
+/* { dg-do preprocess } */
+
+/* { dg-error "missing terminating" "bad charconst" { target *-*-* } 7 } */
+#if 'x
+#endif
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/macroargs.c b/gcc/testsuite/gcc.dg/cpp/trad/macroargs.c
new file mode 100644
index 0000000..12effa7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/trad/macroargs.c
@@ -0,0 +1,24 @@
+/* Test that whitespace in arguments is preserved, and that each
+ newline in macro arguments become a space. */
+
+/* { dg-do run } */
+
+#define f(x, y) "x y"
+
+extern void abort (void);
+
+int main ()
+{
+ const char *str1 = f( foo ,bar);
+ const char *str2 = f(
+foo
+,bar);
+
+ if (strcmp (str1, " foo bar"))
+ abort ();
+
+ if (strcmp (str1, str2))
+ abort ();
+
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/quote.c b/gcc/testsuite/gcc.dg/cpp/trad/quote.c
new file mode 100644
index 0000000..f8e6170
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/trad/quote.c
@@ -0,0 +1,6 @@
+/* Test that unterminated quotes are OK when only preprocessing. */
+
+/* { dg-do preprocess } */
+
+/* { dg-bogus "unterminated" } */ 'x
+/* { dg-bogus "unterminated" } */ "x