summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/cpp/lexstrng.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/lexstrng.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/lexstrng.c')
-rw-r--r--gcc/testsuite/gcc.dg/cpp/lexstrng.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/cpp/lexstrng.c b/gcc/testsuite/gcc.dg/cpp/lexstrng.c
new file mode 100644
index 000000000..b03533003
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/lexstrng.c
@@ -0,0 +1,67 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc. */
+
+/* { dg-do run } */
+/* { dg-options "-trigraphs" } */
+
+/* Test lexing of strings and character constants. */
+
+#ifndef __WCHAR_TYPE__
+#define __WCHAR_TYPE__ int
+#endif
+typedef __WCHAR_TYPE__ wchar_t;
+
+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)
+
+/* Escaped newlines. */
+const char *str1 = "s\
+t\
+\
+r??/
+ 1";
+
+const char x = '\
+??/
+b';
+
+/* Test escaped terminators. */
+const char *term = "\"\\\"\\";
+const char termc = '\'';
+const char *terms = "'";
+
+/* Test wide strings and chars are lexed. */
+const wchar_t wchar = L'w';
+const wchar_t* wstring = L"wide string";
+
+/* Test all 9 trigraphs embedded in a string. Test trigraphs do not
+ survive an embedded backslash newline. Test trigraphs preceded by
+ a '?' are still noticed. */
+const char *t = "??/\??<??>??=??)??\
+(??(??!??'??-???=???/
+?-";
+
+int main (int argc, char *argv[])
+{
+ if (strcmp (str1, "str 1"))
+ err ("str1");
+
+ if (x != 'b')
+ err ("b");
+
+ /* We have to split the string up to avoid trigraph replacement
+ here. Split the 2 trigraphs after both 1 and 2 ?s; just doing
+ this exposed a bug in the initial release of the tokenized lexer. */
+ if (strcmp (t, "\\{}#]?" "?([|^~?#??" "-"))
+ err ("Embedded trigraphs");
+
+ if (term[0] != '"' || term[1] != '\\' || term[2] != '"'
+ || term[3] != '\\' || term[4] != '\0')
+ err ("Escaped string terminators");
+
+ if (termc != terms[0])
+ err ("Escaped character constant terminator");
+
+ return 0;
+}