Add __builtion_unreachable to vector::size(), vector::capacity()
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / write-to-string-literal-1.c
blob46e907a856091604a524273f8f89aa1cd04eef21
1 #include <string.h>
3 #ifdef __cplusplus
4 #define CONST_CAST(type) const_cast<type>
5 #else
6 #define CONST_CAST(type)
7 #endif
9 /* PR analyzer/95007. */
11 void test_1 (void)
13 char *s = CONST_CAST(char *)("foo");
14 s[0] = 'g'; /* { dg-warning "write to string literal" } */
17 /* PR c/83347. */
19 void test_2 (void)
21 // Technically irrelevant for C++ as fpermissive will warn about invalid conversion.
22 memcpy (CONST_CAST(char *)("abc"), "def", 3); /* { dg-warning "write to string literal" } */
25 /* PR c/83347. */
27 static char * __attribute__((noinline))
28 called_by_test_3 (void)
30 return (char *)"foo";
33 void test_3 (void)
35 char *s = called_by_test_3 ();
36 s[1] = 'a'; /* { dg-warning "write to string literal" } */
39 static char * __attribute__((noinline))
40 called_by_test_4 (int flag)
42 if (flag)
43 return (char *)"foo";
44 else
45 return (char *)"bar";
48 void test_4 (void)
50 char *s = called_by_test_4 (0);
51 s[1] = 'z'; /* { dg-warning "write to string literal" } */
54 static char * __attribute__((noinline))
55 called_by_test_5 (int flag)
57 if (flag)
58 return (char *)"foo";
59 else
60 return (char *)"bar";
63 void test_5 (int flag)
65 char *s = called_by_test_5 (flag);
66 s[1] = 'z'; /* We miss this one, unless we disable state merging. */