condition.cpp revision cfdc81a83467973b14e4ea5e9e9af1690f135415
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3void test() {
4  int x;
5  if (x) ++x;
6  if (int x=0) ++x;
7
8  typedef int arr[10];
9  while (arr x=0) ; // expected-error {{an array type is not allowed here}} expected-error {{array initializer must be an initializer list}}
10  while (int f()=0) ; // expected-error {{a function type is not allowed here}}
11
12  struct S {} s;
13  if (s) ++x; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}}
14  while (struct S x=s) ; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}}
15  do ; while (s); // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}}
16  for (;s;) ; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}}
17  switch (s) {} // expected-error {{statement requires expression of integer type ('struct S' invalid)}}
18
19  while (struct S {} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{no viable conversion}} expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} expected-note{{candidate function}}
20  while (struct {} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{no viable conversion}} expected-error {{value of type 'struct <anonymous>' is not contextually convertible to 'bool'}} expected-note{{candidate function}}
21  switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{cannot initialize}}
22
23  if (int x=0) { // expected-note 2 {{previous definition is here}}
24    int x;  // expected-error {{redefinition of 'x'}}
25  }
26  else
27    int x;  // expected-error {{redefinition of 'x'}}
28  while (int x=0) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
29  while (int x=0) { int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
30  for (int x; int x=0; ) ; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
31  for (int x; ; ) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
32  for (; int x=0; ) int x; // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
33  for (; int x=0; ) { int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
34  switch (int x=0) { default: int x; } // expected-error {{redefinition of 'x'}} expected-note {{previous definition is here}}
35}
36
37int* get_int_ptr();
38
39void test2() {
40  float *ip;
41  if (int *ip = ip) {
42  }
43}
44