p8-0x.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
  2. struct global {
  3. };
  4. namespace PR10127 {
  5. struct outer {
  6. struct middle {
  7. struct inner {
  8. int func();
  9. int i;
  10. };
  11. struct inner2 {
  12. };
  13. struct inner3 {
  14. };
  15. int mfunc();
  16. };
  17. typedef int td_int;
  18. };
  19. struct str {
  20. operator decltype(outer::middle::inner()) ();
  21. operator decltype(outer::middle())::inner2 ();
  22. operator decltype(outer())::middle::inner3 ();
  23. str(int (decltype(outer::middle::inner())::*n)(),
  24. int (decltype(outer::middle())::inner::*o)(),
  25. int (decltype(outer())::middle::inner::*p)());
  26. };
  27. decltype(outer::middle::inner()) a;
  28. void scope() {
  29. a.decltype(outer::middle())::mfunc(); // expected-error{{'PR10127::outer::middle::mfunc' is not a member of class 'decltype(outer::middle::inner())'}}
  30. a.decltype(outer::middle::inner())::func();
  31. a.decltype(outer::middle())::inner::func();
  32. a.decltype(outer())::middle::inner::func();
  33. a.decltype(outer())::middle::inner::~inner();
  34. decltype(outer())::middle::inner().func();
  35. }
  36. decltype(outer::middle())::inner b;
  37. decltype(outer())::middle::inner c;
  38. decltype(outer())::fail d; // expected-error{{no type named 'fail' in 'PR10127::outer'}}
  39. decltype(outer())::fail::inner e; // expected-error{{no member named 'fail' in 'PR10127::outer'}}
  40. decltype()::fail f; // expected-error{{expected expression}}
  41. decltype()::middle::fail g; // expected-error{{expected expression}}
  42. decltype(int()) h;
  43. decltype(int())::PR10127::outer i; // expected-error{{'decltype(int())' (aka 'int') is not a class, namespace, or enumeration}}
  44. decltype(int())::global j; // expected-error{{'decltype(int())' (aka 'int') is not a class, namespace, or enumeration}}
  45. outer::middle k = decltype(outer())::middle();
  46. outer::middle::inner l = decltype(outer())::middle::inner();
  47. template<typename T>
  48. struct templ {
  49. typename decltype(T())::middle::inner x; // expected-error{{type 'decltype(int())' (aka 'int') cannot be used prior to '::' because it has no members}}
  50. };
  51. template class templ<int>; // expected-note{{in instantiation of template class 'PR10127::templ<int>' requested here}}
  52. template class templ<outer>;
  53. enum class foo {
  54. bar,
  55. baz
  56. };
  57. foo m = decltype(foo::bar)::baz;
  58. enum E {
  59. };
  60. struct bar {
  61. enum E : decltype(outer())::td_int(4);
  62. enum F : decltype(outer())::td_int;
  63. enum G : decltype; // expected-error{{expected '(' after 'decltype'}}
  64. };
  65. }