summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/array-init.c
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2007-12-10 22:44:33 +0000
committerSteve Naroff <snaroff@apple.com>2007-12-10 22:44:33 +0000
commit91f78080e3727d4472f9aac4b401938ce2195c80 (patch)
treef755e86e1ec747808d31d7c7c9558bfbe894259d /clang/test/Sema/array-init.c
parent9a698a1da7b8c3f86e2828544a3f23cc90a1559a (diff)
downloadbcm5719-llvm-91f78080e3727d4472f9aac4b401938ce2195c80.tar.gz
bcm5719-llvm-91f78080e3727d4472f9aac4b401938ce2195c80.zip
Add support for initializing char arrays from string literals.
Adapted from a patch by Anders Carlsson. llvm-svn: 44816
Diffstat (limited to 'clang/test/Sema/array-init.c')
-rw-r--r--clang/test/Sema/array-init.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/test/Sema/array-init.c b/clang/test/Sema/array-init.c
index 5b22681d1b9..bf5ea06bab4 100644
--- a/clang/test/Sema/array-init.c
+++ b/clang/test/Sema/array-init.c
@@ -137,3 +137,28 @@ void testTypedef()
AryT a = { 1, 2 }, b = { 3, 4, 5 };
}
+static char const xx[] = "test";
+static char const yy[5] = "test";
+static char const zz[3] = "test"; // expected-warning{{initializer-string for char array is too long}}
+
+void charArrays()
+{
+ static char const test[] = "test";
+ static char const test2[] = { "weird stuff" };
+ static char const test3[] = { "test", "excess stuff" }; // expected-error{{excess elements in char array initializer}}
+
+ char* cp[] = { "Hello" };
+
+ char c[] = { "Hello" };
+ int l[sizeof(c) == 6 ? 1 : -1];
+
+ int i[] = { "Hello "}; // expected-error{{array of wrong type 'int' initialized from string constant}}
+ char c2[] = { "Hello", "Good bye" }; //expected-error{{excess elements in char array initializer}}
+
+ int i2[1] = { "Hello" }; //expected-error{{array of wrong type 'int' initialized from string constant}}
+ char c3[5] = { "Hello" };
+ char c4[4] = { "Hello" }; //expected-warning{{initializer-string for char array is too long}}
+
+ int i3[] = {}; //expected-error{{at least one initializer value required to size array}} expected-warning{{use of GNU empty initializer extension}}
+}
+
OpenPOWER on IntegriCloud