Skip to content

Commit f635bcd

Browse files
NFC: Pre-commit test: -Wpointer-sign with plain char to [un]signed char
Add tests with bad message text for `-Wpointer-sign` and run them with both signed and unsigned versions of plain `char`.
1 parent 7470017 commit f635bcd

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

clang/test/Sema/incompatible-sign.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
// RUN: %clang_cc1 %s -verify -fsyntax-only
2+
// RUN: %clang_cc1 %s -verify -fsyntax-only -fno-signed-char
23

34
int a(int* x); // expected-note{{passing argument to parameter 'x' here}}
45
int b(unsigned* y) { return a(y); } // expected-warning {{passing 'unsigned int *' to parameter of type 'int *' converts between pointers to integer types with different sign}}
56

7+
signed char *plainCharToSignedChar(signed char *arg) { // expected-note{{passing argument to parameter}}
8+
extern char c;
9+
signed char *p = &c; // expected-warning {{converts between pointers to integer types with different sign}}
10+
struct { signed char *p; } s = { &c }; // expected-warning {{converts between pointers to integer types with different sign}}
11+
p = &c; // expected-warning {{converts between pointers to integer types with different sign}}
12+
plainCharToSignedChar(&c); // expected-warning {{converts between pointers to integer types with different sign}}
13+
return &c; // expected-warning {{converts between pointers to integer types with different sign}}
14+
}
15+
16+
char *unsignedCharToPlainChar(char *arg) { // expected-note{{passing argument to parameter}}
17+
extern unsigned char uc[];
18+
char *p = uc; // expected-warning {{converts between pointers to integer types with different sign}}
19+
(void) (char *[]){ [42] = uc }; // expected-warning {{converts between pointers to integer types with different sign}}
20+
p = uc; // expected-warning {{converts between pointers to integer types with different sign}}
21+
unsignedCharToPlainChar(uc); // expected-warning {{converts between pointers to integer types with different sign}}
22+
return uc; // expected-warning {{converts between pointers to integer types with different sign}}
23+
}

clang/test/Sema/incompatible-sign.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 %s -verify -fsyntax-only
2+
// RUN: %clang_cc1 %s -verify -fsyntax-only -fno-signed-char
3+
4+
void plainToSigned() {
5+
extern char c;
6+
signed char *p;
7+
p = &c; // expected-error {{converts between pointers to integer types with different sign}}
8+
}
9+
10+
void unsignedToPlain() {
11+
extern unsigned char uc;
12+
char *p;
13+
p = &uc; // expected-error {{converts between pointers to integer types with different sign}}
14+
}

0 commit comments

Comments
 (0)