From ae40d62f736098a12e3e31ab2d5cfb24f2467742 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Mon, 19 Nov 2007 20:40:43 +0000 Subject: [PATCH] started collecting some parser tests [r18490] --- parsetest/declarator_special.c | 14 +++++++++++ parsetest/initializers.c | 43 ++++++++++++++++++++++++++++++++++ parsetest/shouldfail/brace1.c | 2 ++ parsetest/shouldfail/brace2.c | 1 + 4 files changed, 60 insertions(+) create mode 100644 parsetest/declarator_special.c create mode 100644 parsetest/initializers.c create mode 100644 parsetest/shouldfail/brace1.c create mode 100644 parsetest/shouldfail/brace2.c diff --git a/parsetest/declarator_special.c b/parsetest/declarator_special.c new file mode 100644 index 0000000..75964ad --- /dev/null +++ b/parsetest/declarator_special.c @@ -0,0 +1,14 @@ +int f(void) +{ + return 42; +} + +int (* const (fip) (void))(void) +{ + return &f; +} + +int main(void) { + int(*func)(void) = fip(); + return func() == 42 ? 0 : 1; +} diff --git a/parsetest/initializers.c b/parsetest/initializers.c new file mode 100644 index 0000000..7c473b0 --- /dev/null +++ b/parsetest/initializers.c @@ -0,0 +1,43 @@ +int bla = 1; +int bla2 = 2; +int bla3 = { 3 }; +int bla4 = { 4, }; +/* should fail: +int bla5 = { { 2 } }; +int bla6 = { 1, 2 }; +int *bla7 = { 2, }; +int bla5 = 1, ; +*/ + +char str1[] = "Hello"; +char str2[5] = "Hello"; +char str3[10] = "Hello"; +signed char str4[] = "Hello"; +unsigned char str5[] = "Hello"; +/* char str4[4] = "Hello"; unclear wether this should be an error or warning + * gcc produces a warning, icc an error */ + +struct foo { + int a, b; +}; + +struct foo f1 = { 1, 2 }; +struct foo f2 = { { 1, }, 2 }; /* produces a warning on icc and gcc... */ +struct foo f3 = { { { 1, } }, 2 }; /* produces a warning on icc and gcc... */ + +struct foob { + int a; + struct foobb { + float c, d; + }; + int e; +}; + +struct foob ff2 = { 1, 2.5, 4, 2 }; + +union foou { + int a; + float b; +}; + +union foou g1 = { 5 }; diff --git a/parsetest/shouldfail/brace1.c b/parsetest/shouldfail/brace1.c new file mode 100644 index 0000000..cb0749c --- /dev/null +++ b/parsetest/shouldfail/brace1.c @@ -0,0 +1,2 @@ +int main(int argc, char **argv) +{ diff --git a/parsetest/shouldfail/brace2.c b/parsetest/shouldfail/brace2.c new file mode 100644 index 0000000..5c34318 --- /dev/null +++ b/parsetest/shouldfail/brace2.c @@ -0,0 +1 @@ +} -- 2.20.1