p13.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s
  2. // If T is the name of a class, then each of the following shall have
  3. // a name different from T:
  4. // - every static data member of class T;
  5. struct X0 {
  6. static int X0; // expected-error{{member 'X0' has the same name as its class}}
  7. };
  8. // - every member function of class T
  9. struct Xa {
  10. int Xa() {} // expected-error{{constructor cannot have a return type}}
  11. };
  12. // - every member of class T that is itself a type;
  13. struct X1 {
  14. enum X1 { }; // expected-error{{member 'X1' has the same name as its class}}
  15. };
  16. struct X1a {
  17. struct X1a; // expected-error{{member 'X1a' has the same name as its class}}
  18. };
  19. struct X2 {
  20. typedef int X2; // expected-error{{member 'X2' has the same name as its class}}
  21. };
  22. struct X2a {
  23. using X2a = int; // expected-error{{member 'X2a' has the same name as its class}}
  24. };
  25. // - every member template of class T
  26. struct X2b {
  27. template<typename T> struct X2b; // expected-error{{member 'X2b' has the same name as its class}}
  28. };
  29. struct X2c {
  30. template<typename T> void X2c(); // expected-error{{constructor cannot have a return type}}
  31. };
  32. struct X2d {
  33. template<typename T> static int X2d; // expected-error{{member 'X2d' has the same name as its class}}
  34. };
  35. struct X2e {
  36. template<typename T> using X2e = int; // expected-error{{member 'X2e' has the same name as its class}}
  37. };
  38. // - every enumerator of every member of class T that is an unscoped enumerated type; and
  39. struct X3 {
  40. enum E {
  41. X3 // expected-error{{member 'X3' has the same name as its class}}
  42. };
  43. };
  44. struct X3a {
  45. enum class E {
  46. X3a // ok
  47. };
  48. };
  49. // - every member of every anonymous union that is a member of class T.
  50. struct X4 {
  51. union {
  52. int X;
  53. union {
  54. float Y;
  55. unsigned X4; // expected-error{{member 'X4' has the same name as its class}}
  56. };
  57. };
  58. };