instantiate-c99.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. // Test template instantiation for C99-specific features.
  3. // ---------------------------------------------------------------------
  4. // Designated initializers
  5. // ---------------------------------------------------------------------
  6. template<typename T, typename XType, typename YType>
  7. struct DesigInit0 {
  8. void f(XType x, YType y) {
  9. T agg = {
  10. .y = y, // expected-error{{does not refer}}
  11. .x = x // expected-error{{does not refer}}
  12. };
  13. }
  14. };
  15. struct Point2D {
  16. float x, y;
  17. };
  18. template struct DesigInit0<Point2D, int, double>;
  19. struct Point3D {
  20. float x, y, z;
  21. };
  22. template struct DesigInit0<Point3D, int, double>;
  23. struct Color {
  24. unsigned char red, green, blue;
  25. };
  26. struct ColorPoint3D {
  27. Color color;
  28. float x, y, z;
  29. };
  30. template struct DesigInit0<ColorPoint3D, int, double>;
  31. template struct DesigInit0<Color, int, double>; // expected-note{{instantiation}}
  32. template<typename T, int Subscript1, int Subscript2,
  33. typename Val1, typename Val2>
  34. struct DesigArrayInit0 {
  35. void f(Val1 val1, Val2 val2) {
  36. T array = {
  37. [Subscript1] = val1,
  38. [Subscript2] = val2 // expected-error{{exceeds array bounds}}
  39. };
  40. int array2[10] = { [5] = 3 };
  41. }
  42. };
  43. template struct DesigArrayInit0<int[8], 5, 3, float, int>;
  44. template struct DesigArrayInit0<int[8], 5, 13, float, int>; // expected-note{{instantiation}}
  45. template<typename T, int Subscript1, int Subscript2,
  46. typename Val1>
  47. struct DesigArrayRangeInit0 {
  48. void f(Val1 val1) {
  49. T array = {
  50. [Subscript1...Subscript2] = val1 // expected-error{{exceeds}}
  51. };
  52. }
  53. };
  54. template struct DesigArrayRangeInit0<int[8], 3, 5, float>;
  55. template struct DesigArrayRangeInit0<int[8], 5, 13, float>; // expected-note{{instantiation}}
  56. // ---------------------------------------------------------------------
  57. // Compound literals
  58. // ---------------------------------------------------------------------
  59. template<typename T, typename Arg1, typename Arg2>
  60. struct CompoundLiteral0 {
  61. T f(Arg1 a1, Arg2 a2) {
  62. return (T){a1, a2};
  63. }
  64. };
  65. template struct CompoundLiteral0<Point2D, int, float>;