brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · b0183ff Raw
101 lines · cpp
1// RUN: %clang_cc1 -Wno-c99-extensions -Wno-reorder -fsyntax-only -verify %s2// RUN: %clang_cc1 -Wno-c99-extensions -Wno-reorder -fsyntax-only -verify -std=c++98 %s3// RUN: %clang_cc1 -Wno-c99-extensions -Wno-reorder -fsyntax-only -verify -std=c++11 %s4 5// Test template instantiation for C99-specific features.6 7// ---------------------------------------------------------------------8// Designated initializers9// ---------------------------------------------------------------------10template<typename T, typename XType, typename YType>11struct DesigInit0 {12  void f(XType x, YType y) {13    T agg = { 14#if __cplusplus <= 199711L15      .y = y, // expected-error{{does not refer}}16      .x = x  // expected-error{{does not refer}}17#else18      .y = static_cast<float>(y), // expected-error{{does not refer}}19      .x = static_cast<float>(x)  // expected-error{{does not refer}}20#endif21    };22  }23};24 25struct Point2D {26  float x, y;27};28 29template struct DesigInit0<Point2D, int, double>;30 31struct Point3D {32  float x, y, z;33};34 35template struct DesigInit0<Point3D, int, double>;36 37struct Color { 38  unsigned char red, green, blue;39};40 41struct ColorPoint3D {42  Color color;43  float x, y, z;44};45 46template struct DesigInit0<ColorPoint3D, int, double>;47template struct DesigInit0<Color, int, double>; // expected-note{{instantiation}}48 49template<typename T, int Subscript1, int Subscript2,50         typename Val1, typename Val2>51struct DesigArrayInit0 {52  void f(Val1 val1, Val2 val2) {53    T array = {54#if __cplusplus <= 199711L55      [Subscript1] = val1,56#else57      [Subscript1] = static_cast<int>(val1),58#endif59      [Subscript2] = val2 // expected-error{{exceeds array bounds}}60    };61 62    int array2[10] = { [5] = 3 };63  }64};65 66template struct DesigArrayInit0<int[8], 5, 3, float, int>;67template struct DesigArrayInit0<int[8], 5, 13, float, int>; // expected-note{{instantiation}}68 69template<typename T, int Subscript1, int Subscript2,70         typename Val1>71struct DesigArrayRangeInit0 {72  void f(Val1 val1) {73    T array = {74#if __cplusplus <= 199711L75      [Subscript1...Subscript2] = val1 // expected-error{{exceeds}}76#else77      [Subscript1...Subscript2] = static_cast<int>(val1) // expected-error{{exceeds}}78#endif79    };80  }81};82 83template struct DesigArrayRangeInit0<int[8], 3, 5, float>;84template struct DesigArrayRangeInit0<int[8], 5, 13, float>; // expected-note{{instantiation}}85 86// ---------------------------------------------------------------------87// Compound literals88// ---------------------------------------------------------------------89template<typename T, typename Arg1, typename Arg2>90struct CompoundLiteral0 {91  T f(Arg1 a1, Arg2 a2) {92#if __cplusplus <= 199711L93    return (T){a1, a2};94#else95    return (T){static_cast<float>(a1), a2};96#endif97  }98};99 100template struct CompoundLiteral0<Point2D, int, float>;101