summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/cpp/strify2.c
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gcc.dg/cpp/strify2.c
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gcc.dg/cpp/strify2.c')
-rw-r--r--gcc/testsuite/gcc.dg/cpp/strify2.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/cpp/strify2.c b/gcc/testsuite/gcc.dg/cpp/strify2.c
new file mode 100644
index 000000000..c24220c70
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/strify2.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc. */
+
+/* { dg-do run } */
+/* { dg-options "-std=c99 -pedantic-errors" } */
+
+/* Tests a whole bunch of things are correctly stringified. */
+
+extern int strcmp (const char *, const char *);
+extern int puts (const char *);
+extern void abort (void);
+#define err(str) do { puts(str); abort(); } while (0)
+
+#define str(x) #x
+#define xstr(x) str(x)
+#define strvar(...) #__VA_ARGS__
+
+#define glibc_str(x) glibc_str2 (w, x)
+#define glibc_str2(w, x) #x
+#define ver GLIBC_2.2
+
+int main (int argc, char *argv[])
+{
+ str (\); /* { dg-warning "valid string" "str(\\)" } */
+ str (\\); /* OK. */
+ str (\\\); /* { dg-warning "valid string" "str(\\\\\\)" } */
+
+ /* This also serves as a useful test of the value of __INCLUDE_LEVEL. */
+ if (strcmp (xstr (__INCLUDE_LEVEL__), "0"))
+ err ("macro expansion");
+
+ if (strcmp(str (__INCLUDE_LEVEL__), "__INCLUDE_LEVEL__"))
+ err ("macro name");
+
+ if (strcmp(str(), "") || strcmp(str( ), ""))
+ err ("empty string");
+
+ if (strcmp(str ("s\n"), "\"s\\n\""))
+ err ("quoted string");
+
+ if (strcmp (str (a € b), "a \200 b"))
+ err ("unprintable char");
+
+ if (strcmp (str ( a b@ c ), "a b@ c"))
+ err ("internal whitespace");
+
+ if (strcmp (str(a \n), "a \n"))
+ err ("backslash token");
+
+ if (strcmp (strvar (foo, bar), "foo, bar"))
+ err ("variable arguments");
+
+ if (strcmp (glibc_str (ver), "GLIBC_2.2"))
+ err ("whitespace");
+
+ return 0;
+}