Home | History | Annotate | Line # | Download | only in lint1
msg_346.c revision 1.2
      1 /*	$NetBSD: msg_346.c,v 1.2 2021/08/15 14:00:27 rillig Exp $	*/
      2 # 3 "msg_346.c"
      3 
      4 // Test for message: call to '%s' effectively discards 'const' from argument [346]
      5 
      6 typedef unsigned long size_t;
      7 
      8 void* memchr(const void *, int, size_t);		/* C99 7.21.5.1 */
      9 char *strchr(const char *, int);			/* C99 7.21.5.2 */
     10 char* strpbrk(const char *, const char *);		/* C99 7.21.5.4 */
     11 char* strrchr(const char *, int);			/* C99 7.21.5.5 */
     12 char* strstr(const char *, const char *);		/* C99 7.21.5.7 */
     13 
     14 void take_const_char_ptr(const char *);
     15 void take_char_ptr(char *);
     16 
     17 void
     18 example(void)
     19 {
     20 	const char *ccp = "const char *";
     21 	char *cp = "char *";
     22 
     23 	ccp = strchr(ccp, 'c');
     24 	ccp = strchr(cp, 'c');
     25 	/* expect+1: warning: call to 'strchr' effectively discards 'const' from argument [346] */
     26 	cp = strchr(ccp, 'c');
     27 	cp = strchr(cp, 'c');
     28 
     29 	take_const_char_ptr(strchr(ccp, 'c'));
     30 	take_const_char_ptr(strchr(cp, 'c'));
     31 	/* expect+1: warning: call to 'strchr' effectively discards 'const' from argument [346] */
     32 	take_char_ptr(strchr(ccp, 'c'));
     33 	take_char_ptr(strchr(cp, 'c'));
     34 
     35 	take_const_char_ptr(strchr("literal", 'c'));
     36 	/* expect+1: warning: call to 'strchr' effectively discards 'const' from argument [346] */
     37 	take_char_ptr(strchr("literal", 'c'));
     38 }
     39 
     40 void
     41 all_functions(void)
     42 {
     43 	/* TODO: expect+1: warning: call to 'memchr' effectively discards 'const' from argument [346] */
     44 	take_char_ptr(memchr("string", 'c', 7));
     45 	/* expect+1: warning: call to 'strchr' effectively discards 'const' from argument [346] */
     46 	take_char_ptr(strchr("string", 'c'));
     47 	/* TODO: expect+1: warning: call to 'strpbrk' effectively discards 'const' from argument [346] */
     48 	take_char_ptr(strpbrk("string", "c"));
     49 	/* TODO: expect+1: warning: call to 'strrchr' effectively discards 'const' from argument [346] */
     50 	take_char_ptr(strrchr("string", 'c'));
     51 	/* TODO: expect+1: warning: call to 'strstr' effectively discards 'const' from argument [346] */
     52 	take_char_ptr(strstr("string", "c"));
     53 }
     54