type-convert-construct.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. // RUN: %clang_cc1 -fsyntax-only -verify -std=gnu++98 %s
  3. // RUN: %clang_cc1 -fsyntax-only -verify -std=gnu++11 %s
  4. void f() {
  5. float v1 = float(1);
  6. int v2 = typeof(int)(1,2); // expected-error {{excess elements in scalar initializer}}
  7. typedef int arr[];
  8. int v3 = arr(); // expected-error {{array types cannot be value-initialized}}
  9. typedef void fn_ty();
  10. fn_ty(); // expected-error {{cannot create object of function type 'fn_ty'}}
  11. fn_ty(0); // expected-error {{functional-style cast from 'int' to 'fn_ty'}}
  12. fn_ty(0, 0); // expected-error {{cannot create object of function type 'fn_ty'}}
  13. #if __cplusplus >= 201103L
  14. fn_ty{}; // expected-error {{cannot create object of function type 'fn_ty'}}
  15. fn_ty{0}; // expected-error {{cannot create object of function type 'fn_ty'}}
  16. fn_ty{0, 0}; // expected-error {{cannot create object of function type 'fn_ty'}}
  17. fn_ty({}); // expected-error {{cannot create object of function type 'fn_ty'}}
  18. #endif
  19. int v4 = int();
  20. int v5 = int; // expected-error {{expected '(' for function-style cast or type construction}}
  21. typedef int T;
  22. int *p;
  23. bool v6 = T(0) == p;
  24. #if __cplusplus >= 201103L
  25. // expected-error@-2 {{comparison between pointer and integer ('T' (aka 'int') and 'int *')}}
  26. #endif
  27. char *str;
  28. str = "a string";
  29. #if __cplusplus <= 199711L
  30. // expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}}
  31. #else
  32. // expected-warning@-4 {{ISO C++11 does not allow conversion from string literal to 'char *'}}
  33. #endif
  34. wchar_t *wstr;
  35. wstr = L"a wide string";
  36. #if __cplusplus <= 199711L
  37. // expected-warning@-2 {{conversion from string literal to 'wchar_t *' is deprecated}}
  38. #else
  39. // expected-warning@-4 {{ISO C++11 does not allow conversion from string literal to 'wchar_t *'}}
  40. #endif
  41. }