cxx-ambig-paren-expr.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
  2. void f() {
  3. typedef int T;
  4. int x, *px;
  5. // Type id.
  6. (T())x; // expected-error {{cast from 'int' to 'T ()'}}
  7. (T())+x; // expected-error {{cast from 'int' to 'T ()'}}
  8. (T())*px; // expected-error {{cast from 'int' to 'T ()'}}
  9. // Expression.
  10. x = (T());
  11. x = (T())/x;
  12. typedef int *PT;
  13. // Make sure stuff inside the parens are parsed only once (only one warning).
  14. x = (PT()[(int){1}]); // expected-warning {{compound literals}}
  15. // Special case: empty parens is a call, not an expression
  16. struct S{int operator()();};
  17. (S())();
  18. // FIXME: Special case: "++" is postfix here, not prefix
  19. // (S())++;
  20. }
  21. // Make sure we do tentative parsing correctly in conditions.
  22. typedef int type;
  23. struct rec { rec(int); };
  24. namespace ns {
  25. typedef int type;
  26. struct rec { rec(int); };
  27. }
  28. struct cls {
  29. typedef int type;
  30. struct rec { rec(int); };
  31. };
  32. struct result {
  33. template <class T> result(T);
  34. bool check();
  35. };
  36. void test(int i) {
  37. if (result((cls::type) i).check())
  38. return;
  39. if (result((ns::type) i).check())
  40. return;
  41. if (result((::type) i).check())
  42. return;
  43. if (result((cls::rec) i).check())
  44. return;
  45. if (result((ns::rec) i).check())
  46. return;
  47. if (result((::rec) i).check())
  48. return;
  49. }