cxx0x-condition.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
  2. struct S { S(int); operator bool(); };
  3. void f() {
  4. int a;
  5. typedef int n;
  6. while (a) ;
  7. while (int x) ; // expected-error {{variable declaration in condition must have an initializer}}
  8. while (float x = 0) ;
  9. if (const int x = a) ; // expected-warning{{empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
  10. switch (int x = a+10) {}
  11. for (; int x = ++a; ) ;
  12. if (S(a)) {} // ok
  13. if (S(a) = 0) {} // ok
  14. if (S(a) == 0) {} // ok
  15. if (S(n)) {} // expected-error {{unexpected type name 'n': expected expression}}
  16. if (S(n) = 0) {} // ok
  17. if (S(n) == 0) {} // expected-error {{unexpected type name 'n': expected expression}}
  18. if (S b(a)) {} // expected-error {{variable declaration in condition cannot have a parenthesized initializer}}
  19. if (S b(n)) {} // expected-error {{a function type is not allowed here}} expected-error {{must have an initializer}}
  20. if (S b(n) = 0) {} // expected-error {{a function type is not allowed here}}
  21. if (S b(n) == 0) {} // expected-error {{a function type is not allowed here}} expected-error {{did you mean '='?}}
  22. S s(a);
  23. if (S{s}) {} // ok
  24. if (S a{s}) {} // ok
  25. if (S a = {s}) {} // ok
  26. if (S a == {s}) {} // expected-error {{did you mean '='?}}
  27. if (S(b){a}) {} // ok
  28. if (S(b) = {a}) {} // ok
  29. }