From 91f78080e3727d4472f9aac4b401938ce2195c80 Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Mon, 10 Dec 2007 22:44:33 +0000 Subject: Add support for initializing char arrays from string literals. Adapted from a patch by Anders Carlsson. llvm-svn: 44816 --- clang/test/Sema/array-init.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'clang/test/Sema/array-init.c') 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}} +} + -- cgit v1.2.3