blob: 25da12b5861f95a32dcc65a1c532c23ed7006c4f [file] [log] [blame]
Chris Lattner35080842008-02-02 20:20:10 +00001// RUN: clang %s -verify -pedantic -fsyntax-only
2
3// PR1966
4_Complex double test1() {
5 return __extension__ 1.0if;
6}
7
8_Complex double test2() {
9 return 1.0if; // expected-warning {{imaginary constants are an extension}}
10}
11
Chris Lattnerbaf0d662008-07-25 18:07:19 +000012// rdar://6097308
13void test3() {
14 int x;
15 (__extension__ x) = 10;
16}
17
Chris Lattner2c156472008-08-21 18:04:13 +000018// rdar://6162726
19void test4() {
20 static int var;
21 var =+ 5; // expected-warning {{use of unary operator that may be intended as compound assignment (+=)}}
22 var =- 5; // expected-warning {{use of unary operator that may be intended as compound assignment (-=)}}
Chris Lattner399bd1b2009-03-08 06:51:10 +000023 var = +5; // no warning when space between the = and +.
Chris Lattner2c156472008-08-21 18:04:13 +000024 var = -5;
Chris Lattner399bd1b2009-03-08 06:51:10 +000025
26 var =+5; // no warning when the subexpr of the unary op has no space before it.
27 var =-5;
Chris Lattner2c156472008-08-21 18:04:13 +000028}
29
Chris Lattnerca354fa2008-11-17 19:51:54 +000030// rdar://6319320
31void test5(int *X, float *P) {
32 (float*)X = P; // expected-error {{assignment to cast is illegal, lvalue casts are not supported}}
33}
34
Chris Lattnerb1b4d332008-11-21 18:27:34 +000035void test6() {
36 int X;
37 X(); // expected-error {{called object type 'int' is not a function or function pointer}}
38}
Chris Lattner7ca14252008-11-22 19:57:03 +000039
40void test7(int *P, _Complex float Gamma) {
41 P = (P-42) + Gamma*4; // expected-error {{invalid operands to binary expression ('int *' and '_Complex float')}}
42}
43
Chris Lattner670a62c2008-12-12 05:35:08 +000044
45// rdar://6095061
46int test8(void) {
47 int i;
Chris Lattner4209a392008-12-12 05:59:56 +000048 __builtin_choose_expr (0, 42, i) = 10; // expected-warning {{extension used}}
Chris Lattner670a62c2008-12-12 05:35:08 +000049 return i;
50}
Chris Lattner31e21e02009-01-24 20:17:12 +000051
52
53// PR3386
54struct f { int x : 4; float y[]; };
55int test9(struct f *P) {
Chris Lattnerda027472009-01-24 21:29:22 +000056 int R;
57 R = __alignof(P->x); // expected-error {{invalid application of '__alignof' to bitfield}} expected-warning {{extension used}}
58 R = __alignof(P->y); // ok. expected-warning {{extension used}}
59 R = sizeof(P->x); // expected-error {{invalid application of 'sizeof' to bitfield}}
60 return R;
Chris Lattner31e21e02009-01-24 20:17:12 +000061}
62
Chris Lattner56cd21b2009-02-13 22:08:30 +000063// PR3562
64void test10(int n,...) {
65 struct S {
66 double a[n]; // expected-error {{fields must have a constant size}}
67 } s;
68 double x = s.a[0]; // should not get another error here.
69}
Chris Lattnerd0344a42009-02-19 23:45:49 +000070
71
72#define MYMAX(A,B) __extension__ ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
73
74struct mystruct {int A; };
Chris Lattner55660a72009-03-08 19:39:53 +000075void test11(struct mystruct P, float F) {
Chris Lattnerd0344a42009-02-19 23:45:49 +000076 MYMAX(P, F); // expected-error {{invalid operands to binary expression ('typeof(P)' (aka 'struct mystruct') and 'typeof(F)' (aka 'float'))}}
77}
78
Chris Lattner55660a72009-03-08 19:39:53 +000079// PR3753
80int test12(const char *X) {
Chris Lattner466a7f82009-03-08 19:52:14 +000081 return X == "foo"; // expected-warning {{comparison against a string literal is unspecified}}
Chris Lattner55660a72009-03-08 19:39:53 +000082}
83