Skip to content

Commit b02b1e9

Browse files
committed
Update the test
Use a bookmark, per review request Add C++ RUN line to show we diagnose invalid constructs in C++
1 parent de78049 commit b02b1e9

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed
Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
1-
// RUN: %clang_cc1 -fsyntax-only -verify -Wimplicit-void-ptr-cast %s
2-
// RUN: %clang_cc1 -fsyntax-only -verify -Wc++-compat %s
1+
// RUN: %clang_cc1 -fsyntax-only -verify=c -Wimplicit-void-ptr-cast %s
2+
// RUN: %clang_cc1 -fsyntax-only -verify=c -Wc++-compat %s
3+
// RUN: %clang_cc1 -fsyntax-only -verify=cxx -x c++ %s
34
// RUN: %clang_cc1 -fsyntax-only -verify=good %s
45
// RUN: %clang_cc1 -fsyntax-only -verify=good -Wc++-compat -Wno-implicit-void-ptr-cast %s
56
// good-no-diagnostics
67

78
typedef __typeof__(sizeof(int)) size_t;
89
extern void *malloc(size_t);
910

10-
void func(int *); // expected-note {{passing argument to parameter here}}
11+
void func(int *); // #func-param
1112

1213
void test(void) {
13-
int *x = malloc(sizeof(char)); // expected-warning {{implicit conversion when initializing 'int *' with an expression of type 'void *' is not permitted in C++}}
14-
x = malloc(sizeof(char)); // expected-warning {{implicit conversion when assigning to 'int *' from type 'void *' is not permitted in C++}}
15-
func(malloc(sizeof(char))); // expected-warning {{implicit conversion when passing 'void *' to parameter of type 'int *' is not permitted in C++}}
14+
int *x = malloc(sizeof(char)); // c-warning {{implicit conversion when initializing 'int *' with an expression of type 'void *' is not permitted in C++}} \
15+
cxx-error {{cannot initialize a variable of type 'int *' with an rvalue of type 'void *'}}
16+
x = malloc(sizeof(char)); // c-warning {{implicit conversion when assigning to 'int *' from type 'void *' is not permitted in C++}} \
17+
cxx-error {{assigning to 'int *' from incompatible type 'void *'}}
18+
func(malloc(sizeof(char))); // c-warning {{implicit conversion when passing 'void *' to parameter of type 'int *' is not permitted in C++}} \
19+
c-note@#func-param {{passing argument to parameter here}} \
20+
cxx-error {{no matching function for call to 'func'}} \
21+
cxx-note@#func-param {{candidate function not viable: cannot convert argument of incomplete type 'void *' to 'int *' for 1st argument}}
1622
x = (int *)malloc(sizeof(char));
1723

1824
void *vp = 0;
19-
x = vp; // expected-warning {{implicit conversion when assigning to 'int *' from type 'void *' is not permitted in C++}}
25+
x = vp; // c-warning {{implicit conversion when assigning to 'int *' from type 'void *' is not permitted in C++}} \
26+
cxx-error {{assigning to 'int *' from incompatible type 'void *'}}
2027
vp = vp;
2128

22-
x = (void *)malloc(sizeof(char)); // expected-warning {{implicit conversion when assigning to 'int *' from type 'void *' is not permitted in C++}}
23-
const int *y = vp; // expected-warning {{implicit conversion when initializing 'const int *' with an expression of type 'void *' is not permitted in C++}}
29+
x = (void *)malloc(sizeof(char)); // c-warning {{implicit conversion when assigning to 'int *' from type 'void *' is not permitted in C++}} \
30+
cxx-error {{assigning to 'int *' from incompatible type 'void *'}}
31+
const int *y = vp; // c-warning {{implicit conversion when initializing 'const int *' with an expression of type 'void *' is not permitted in C++}} \
32+
cxx-error {{cannot initialize a variable of type 'const int *' with an lvalue of type 'void *'}}
2433
}
2534

2635
int *other_func(void *ptr) {
27-
return ptr; // expected-warning {{implicit conversion when returning 'void *' from a function with result type 'int *' is not permitted in C++}}
36+
return ptr; // c-warning {{implicit conversion when returning 'void *' from a function with result type 'int *' is not permitted in C++}} \
37+
cxx-error {{cannot initialize return object of type 'int *' with an lvalue of type 'void *'}}
2838
}

0 commit comments

Comments
 (0)