cpp-errors_noerr.hlsl 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. // RUN: %clang_cc1 -fsyntax-only -Wno-unused-value -ffreestanding -verify %s
  2. float f_arr_empty_init[] = { 1, 2, 3 };
  3. //float f_arr_empty_pack[] = { 1, 2 ... }; // expected-error {{expansion is unsupported in HLSL}}
  4. struct s_arr_i_f { int i; float f; };
  5. s_arr_i_f arr_struct_none[] = { }; // TODO: this should fail - see comments in HLSLExternalSource::InitializeInitSequenceForHLSL
  6. s_arr_i_f arr_struct_one[] = { 1, 2 };
  7. //s_arr_i_f arr_struct_incomplete[] = { 1, 2, 3 }; // expected-error {{too few elements in vector initialization (expected 4 elements, have 3)}}
  8. s_arr_i_f arr_struct_two[] = { 1, 2, 3, 4 };
  9. int g_int;
  10. //typeof(g_int) g_typeof_int; // expected-error {{unknown type name 'typeof'; did you mean 'typedef'?}} expected-error {{HLSL requires a type specifier for all declarations}} expected-error {{expected ';' after top level declarator}}
  11. //typedef int (*fn_int)(int); // expected-error {{pointers are unsupported in HLSL}}
  12. //auto g_auto = 3; // expected-error {{'auto' is a reserved keyword in HLSL}} expected-error {{HLSL requires a type specifier for all declarations}}
  13. //__is_signed g_is_signed; // expected-error {{'__is_signed' is a reserved keyword in HLSL}} expected-error {{HLSL requires a type specifier for all declarations}}
  14. //register int g_register; // expected-error {{'register' is a reserved keyword in HLSL}}
  15. //__thread int g_thread; // expected-error {{'__thread' is a reserved keyword in HLSL}}
  16. //thread_local int g_threadLocal; // expected-error {{expected unqualified-id}} expected-error {{unknown type name 'thread_local'}}
  17. //_Thread_local int g_Thread_local; // expected-error {{'_Thread_local' is a reserved keyword in HLSL}}
  18. //_Alignas(float) int g_Alignas; // expected-error {{'_Alignas' is a reserved keyword in HLSL}}
  19. //alignas(float) int g_alignas; // expected-error {{HLSL requires a type specifier for all declarations}} expected-error {{expected ';' after top level declarator}}
  20. //constexpr int g_constexpr = 3; // expected-error {{unknown type name 'constexpr'}} expected-error {{expected unqualified-id}}
  21. //friend int f_friend; // expected-error {{'friend' is a reserved keyword in HLSL}}
  22. // Alternate numerics and builtin types.
  23. //short g_short; // expected-error {{'short' is a reserved keyword in HLSL}} expected-error {{HLSL requires a type specifier for all declarations}}
  24. //long g_long; // expected-error {{'long' is a reserved keyword in HLSL}} expected-error {{HLSL requires a type specifier for all declarations}}
  25. //signed int g_signed_int; // expected-error {{'signed' is a reserved keyword in HLSL}}
  26. unsigned int g_unsigned_int;
  27. //char g_char; // expected-error {{'char' is a reserved keyword in HLSL}} expected-error {{HLSL requires a type specifier for all declarations}}
  28. //_Bool g_Bool; // expected-error {{unknown type name '_Bool'}}
  29. //_vector int altivec_vector; // expected-error {{unknown type name '_vector'}} expected-error {{expected unqualified-id}}
  30. //restrict int g_restrict; // expected-error {{unknown type name 'restrict'}} expected-error {{expected unqualified-id}}
  31. //__underlying_type(int) g_underlying_type; // expected-error {{__underlying_type is unsupported in HLSL}}
  32. //_Atomic(something) g_Atomic; // expected-error {{'_Atomic' is a reserved keyword in HLSL}} expected-error {{HLSL requires a type specifier for all declarations}}
  33. //typeof(g_int) g_anotherInt; // expected-error {{unknown type name 'typeof'; did you mean 'typedef'?}} expected-error {{HLSL requires a type specifier for all declarations}} expected-error {{expected ';' after top level declarator}}
  34. // More GNU-specific keywords.
  35. //_Decimal32 g__Decimal32; // expected-error {{GNU decimal type extension not supported}}
  36. //_Decimal64 g__Decimal64; // expected-error {{GNU decimal type extension not supported}}
  37. //_Decimal128 g__Decimal128; // expected-error {{GNU decimal type extension not supported}}
  38. //__null g___null; // expected-error {{expected unqualified-id}}
  39. //__alignof g___alignof; // expected-error {{expected unqualified-id}}
  40. //__imag g___imag; // expected-error {{expected unqualified-id}}
  41. //__int128 g___int128; // expected-error {{'__int128' is a reserved keyword in HLSL}} expected-error {{HLSL requires a type specifier for all declarations}}
  42. //__label__ g___label; // expected-error {{expected unqualified-id}}
  43. //__real g___real; // expected-error {{expected unqualified-id}}
  44. //__FUNCTION__ g___FUNCTION; // expected-error {{expected unqualified-id}}
  45. //__PRETTY__ g___PRETTY; // expected-error {{unknown type name '__PRETTY__'}}
  46. //struct s_with_bitfield {
  47. // int f_bitfield : 3; // expected-error {{bitfields are not supported in HLSL}}
  48. //};
  49. //struct s_with_friend {
  50. // friend void some_fn(); // expected-error {{'friend' is a reserved keyword in HLSL}}
  51. //};
  52. //typedef int (*fn_int_const)(int) const; // expected-error {{pointers are unsupported in HLSL}} expected-error {{expected ';' after top level declarator}} expected-warning {{declaration does not declare anything}}
  53. //typedef int (*fn_int_volatile)(int) volatile; // expected-error {{pointers are unsupported in HLSL}} expected-error {{expected ';' after top level declarator}} expected-warning {{declaration does not declare anything}}
  54. //
  55. //void fn_throw() throw() { } // expected-error {{exception specification is unsupported in HLSL}}
  56. //
  57. //// This would otherwise be 'exception specification is unsupported in HLSL', but noexcept is not a keyword for HLSL.
  58. //void fn_noexcept() noexcept { }; // expected-error {{expected function body after function declarator}}
  59. //
  60. //// This would be a failure because of unsupported trailer return types, but we mis-parse it differently.
  61. //auto fn_trailing() -> int { return 1; } ; // expected-error {{'auto' is a reserved keyword in HLSL}} expected-error {{expected function body after function declarator}}
  62. //
  63. //void fn_param_with_default(int val = 1) { } // expected-error {{default arguments are not supported}}
  64. //void fn_with_variadic(int a, ...) { } // expected-error {{variadic arguments is unsupported in HLSL}}
  65. //
  66. //float f_arr_empty_uninit[]; // expected-error {{definition of variable with array type needs an explicit size or an initializer}}
  67. //float f_arr_static[static 3]; // expected-error {{static keyword on array derivation is unsupported in HLSL}}
  68. //float f_arr_star[*]; // expected-error {{variable-length array is unsupported in HLSL}} expected-error {{definition of variable with array type needs an explicit size or an initializer}}
  69. //
  70. //#define <<(x) (x) // expected-error {{macro names must be identifiers}}
  71. //
  72. //typedef int bool; // expected-error {{redeclaration of HLSL built-in type 'bool'}} expected-warning {{typedef requires a name}}
  73. // This would generate an 'unknown pragma ignored' warning, but the default configuration ignores the warning.
  74. #pragma align(4)
  75. // Objective-C @ support for NSString literals.
  76. //const bool b = @"hello" != @"goodbye"; // expected-error {{expected expression}}
  77. //
  78. //int fn_eq_default() = default; // expected-error {{'= default' is a function definition and must occur in a standalone declaration}}
  79. //
  80. //typename typedef float4 TFloat4; // expected-error {{'typename' is a reserved keyword in HLSL}}
  81. //
  82. //class C {
  83. // int fn_eq_default() = default; // expected-error {{function deletion and defaulting is unsupported in HLSL}}
  84. //
  85. // // Errors are a bit misleading here, but ultimate we don't support these.
  86. // void* operator new(); // expected-error {{'operator' is a reserved keyword in HLSL}} expected-error {{pointers are unsupported in HLSL}}
  87. // void* operator new(int); // expected-error {{'operator' is a reserved keyword in HLSL}} expected-error {{pointers are unsupported in HLSL}}
  88. // void* operator new(size_t); // expected-error {{'operator' is a reserved keyword in HLSL}} expected-error {{pointers are unsupported in HLSL}}
  89. //
  90. // C() = delete; // expected-error {{member 'C' has the same name as its class}} expected-error {{HLSL requires a type specifier for all declarations}} expected-error {{constructor cannot have a return type}}
  91. //};
  92. //
  93. //asm ("int 3c"); // expected-error {{expected unqualified-id}}
  94. //@property int at_property_int; // expected-error {{expected unqualified-id}}
  95. //-int minus_int; // expected-error {{expected external declaration}}
  96. static int static_int() { return 1; }
  97. //#import "foo.h" // expected-error {{invalid preprocessing directive}}
  98. //int knr_fn(f) int f; { return 1; } // expected-error {{unknown type name 'f'}} expected-error {{expected ';' after top level declarator}} expected-error {{expected unqualified-id}}
  99. // TODO: this should be an error, but there is no C++ mention in any errors in any case;
  100. // the only error case we would have cared to fix is for Objective C++
  101. // [[attribute]] int g_value;
  102. int is_supported() {
  103. // GNU Extensions (in impl-reserved namespace)
  104. //KEYWORD(_Decimal32, KEYALL)
  105. //KEYWORD(_Decimal64, KEYALL)
  106. //KEYWORD(_Decimal128, KEYALL)
  107. //KEYWORD(__null, KEYCXX)
  108. //KEYWORD(__alignof, KEYALL)
  109. //KEYWORD(__attribute, KEYALL)
  110. //KEYWORD(__builtin_choose_expr, KEYALL)
  111. //KEYWORD(__builtin_offsetof, KEYALL)
  112. //if (__builtin_types_compatible_p(int, int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  113. //KEYWORD(__builtin_va_arg, KEYALL)
  114. //KEYWORD(__extension__, KEYALL)
  115. //KEYWORD(__imag, KEYALL)
  116. //KEYWORD(__int128, KEYALL)
  117. //KEYWORD(__label__, KEYALL)
  118. //KEYWORD(__real, KEYALL)
  119. //KEYWORD(__thread, KEYALL)
  120. //KEYWORD(__FUNCTION__, KEYALL)
  121. //KEYWORD(__PRETTY_FUNCTION__, KEYALL)
  122. // GNU and MS Type Traits
  123. // if (__has_nothrow_assign(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  124. // if (__has_nothrow_move_assign(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  125. // if (__has_nothrow_copy(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  126. // if (__has_nothrow_constructor(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  127. // if (__has_trivial_assign(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  128. // if (__has_trivial_move_assign(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  129. // if (__has_trivial_copy(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  130. // if (__has_trivial_constructor(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  131. // if (__has_trivial_move_constructor(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  132. // if (__has_trivial_destructor(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  133. // if (__has_virtual_destructor(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  134. // if (__is_abstract(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  135. // if (__is_base_of(int, int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  136. // if (__is_class(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  137. // if (__is_convertible_to(int, int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  138. // if (__is_empty(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  139. // if (__is_enum(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  140. // if (__is_final(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  141. // if (__is_literal(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  142. // if (__is_literal_type(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  143. // if (__is_pod(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  144. // if (__is_polymorphic(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  145. // if (__is_trivial(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  146. // if (__is_union(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  147. //
  148. // // Clang-only C++ Type Traits
  149. // if (__is_trivially_constructible(int)) return 1; // expected-error {{__is_trivially_constructible is unsupported in HLSL}}
  150. // if (__is_trivially_copyable(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  151. // if (__is_trivially_assignable(int, int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  152. //
  153. // // Embarcadero Expression Traits
  154. // if (__is_lvalue_expr(1)) return 1; // expected-error {{__is_lvalue_expr is unsupported in HLSL}}
  155. // if (__is_rvalue_expr(1)) return 1; // expected-error {{__is_rvalue_expr is unsupported in HLSL}}
  156. //
  157. // // Embarcadero Unary Type Traits
  158. // if (__is_arithmetic(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  159. // if (__is_floating_point(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  160. // if (__is_integral(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  161. // if (__is_complete_type(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  162. // if (__is_void(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  163. // if (__is_array(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  164. // if (__is_function(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  165. // if (__is_reference(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  166. // if (__is_lvalue_reference(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  167. // if (__is_rvalue_reference(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  168. // if (__is_fundamental(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  169. // if (__is_object(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  170. // if (__is_scalar(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  171. // if (__is_compound(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  172. // if (__is_pointer(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  173. // if (__is_member_object_pointer(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  174. // if (__is_member_function_pointer(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  175. // if (__is_member_pointer(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  176. // if (__is_const(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  177. // if (__is_volatile(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  178. // if (__is_standard_layout(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  179. // if (__is_signed(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  180. // if (__is_unsigned(int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  181. //
  182. // // Embarcadero Binary Type Traits
  183. // if (__is_same(int, int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  184. // if (__is_convertible(int, int)) return 1; // expected-error {{type trait functions are not supported in HLSL}}
  185. // if (__array_rank(int, 1)) return 1; // expected-error {{__array_rank is unsupported in HLSL}}
  186. // if (__array_extent(int, 1)) return 1; // expected-error {{__array_extent is unsupported in HLSL}}
  187. //
  188. // __attribute__((common)) int i; // expected-error {{attribute annotations are unsupported in HLSL}}
  189. //
  190. return 0;
  191. }
  192. //[availability(*, unavailable, renamed="somethingelse")] void fn_unavailable(); // expected-error {{'availability' is unsupported in HLSL}}
  193. //__declspec(align(16)) struct SAligned { int i; }; // expected-error {{'__declspec' is a reserved keyword in HLSL}}
  194. //void __fastcall fn_fastcall(); // expected-error {{'__fastcall' is a reserved keyword in HLSL}}
  195. //
  196. //// These aren't even recognized as keywords.
  197. //int _pascal fn_pascal(); // expected-error {{expected ';' after top level declarator}}
  198. //int _kernel fn_kernel(); // expected-error {{expected ';' after top level declarator}}
  199. //int __private int__private; // expected-error {{expected ';' after top level declarator}}
  200. //int __global int__global; // expected-error {{expected ';' after top level declarator}}
  201. //int __local int__local; // expected-error {{expected ';' after top level declarator}}
  202. //int __constant int__constant; // expected-error {{expected ';' after top level declarator}}
  203. //int global intglobal; // expected-error {{expected ';' after top level declarator}}
  204. //int local intlocal; // expected-error {{expected ';' after top level declarator}}
  205. //int constant intconstant; // expected-error {{expected ';' after top level declarator}}
  206. typedef void VOID_TYPE;
  207. //template <typename T> // expected-error {{'template' is a reserved keyword in HLSL}}
  208. //int fn_template(T t)
  209. //{
  210. // return (int)t;
  211. //}
  212. //int template; // expected-error {{'template' is a reserved keyword in HLSL}} expected-error {{expected unqualified-id}}
  213. //
  214. //int get_value(VOID_TYPE) { // expected-error {{empty parameter list defined with a typedef of 'void' not allowed in HLSL}}
  215. // return 1;
  216. //}
  217. //
  218. //extern "C" int get_value(int) { // expected-error {{expected unqualified-id}}
  219. // return 2;
  220. //}
  221. //
  222. //void vla(int size) {
  223. // int n[size]; // expected-error {{variable length arrays are not supported in HLSL}}
  224. // return n[0];
  225. //}
  226. //
  227. //enum MyEnum { MyEnum_MyVal1, MyEnum_MyVal2 }; // expected-error {{enum is unsupported in HLSL}} expected-warning {{declaration does not declare anything}}
  228. //enum class MyEnumWithClass { MyEnumWithClass_MyVal1, MyEnumWithClass_MyVal2 }; // expected-error {{enum is unsupported in HLSL}} expected-warning {{declaration does not declare anything}}
  229. float4 fn_with_semantic() : SV_Target0{
  230. return 0;
  231. }
  232. float4 fn_with_semantic_arg(float4 arg : SV_SOMETHING) : SV_Target0{
  233. return arg;
  234. }
  235. //int fn_with_try_body()
  236. //try // expected-error {{expected function body after function declarator}}
  237. //{
  238. // return 1;
  239. //}
  240. //
  241. //// unnamed namespace definition.
  242. //namespace { // expected-error {{expected identifier}}
  243. // int f_anon_ns_int;
  244. //}
  245. // original namespace definition.
  246. namespace MyNS {
  247. }
  248. //namespace MyNs::Nested { // expected-error {{nested namespace definition must define each namespace separately}}
  249. //}
  250. //
  251. //// original namespace definition with inline.
  252. //inline namespace MyInlineNs { // expected-error {{expected unqualified-id}}
  253. //}
  254. // extension namespace definition.
  255. namespace MyNs {
  256. int my_ns_extension;
  257. }
  258. // namespace alias definition.
  259. //namespace NamespaceAlias = MyNs; // expected-error {{expected identifier}}
  260. //
  261. //using MyNS; // expected-error {{'using' is a reserved keyword in HLSL}}
  262. //int using; // expected-error {{'using' is a reserved keyword in HLSL}}
  263. // function defined outside namespace
  264. namespace MyNs2
  265. {
  266. float outsideFunc(int x);
  267. }
  268. float MyNs2::outsideFunc(int x)
  269. {
  270. return x;
  271. }
  272. float4 main()
  273. {
  274. return MyNs2::outsideFunc(1);
  275. }
  276. struct my_struct { };
  277. class my_class { };
  278. interface my_interface { };
  279. class my_class_2 : my_class { };
  280. class my_class_3 : my_interface { };
  281. class my_class_4 : my_struct { };
  282. struct my_struct_2 : my_struct { };
  283. struct my_struct_3 : my_class { };
  284. struct my_struct_4 : my_interface { };
  285. struct my_struct_5 : my_class, my_interface { };
  286. //struct my_struct_6 : my_class, my_interface, my_struct { }; // expected-error {{multiple concrete base types specified}}
  287. //
  288. //interface my_interface_2 : my_interface { }; // expected-error {{interfaces cannot inherit from other types}}
  289. //
  290. //class my_class_public : public my_class { }; // expected-error {{base type access specifier is unsupported in HLSL}}
  291. //struct forward_struct; // this fails in fxc, but we allow it now for HLSL version >= 2016
  292. struct my_struct_type_decl { int a; } my_struct_var_decl;
  293. //struct my_struct_type_decl_parens { int a; } (my_struct_var_decl_parens); // expected-error {{expected ';' after struct}} expected-error {{HLSL requires a type specifier for all declarations}}
  294. //struct my_struct_type_const { int a; } const my_struct_type_var; // // expected-error {{expected ';' after struct}} expected-error {{HLSL requires a type specifier for all declarations}}
  295. struct my_struct_type_init { int a; } my_struct_type_init_one = { 1 }, my_struct_type_init_two = { 2 };
  296. //struct my_struct_type_static { int a; } static my_struct_type_static; // expected-error {{expected ';' after struct}} expected-warning {{declaration does not declare anything}}
  297. struct { int my_anon_struct_field; } my_anon_struct_type;
  298. void fn_my_struct_type_decl() {
  299. my_struct_type_decl local_var;
  300. }
  301. //struct s_with_template_member {
  302. // template<typename T> T fn(); // expected-error {{'template' is a reserved keyword in HLSL}}
  303. //};
  304. //
  305. //struct s_with_using {
  306. // using MyNS; // expected-error {{'using' is a reserved keyword in HLSL}}
  307. //};
  308. //
  309. //struct s_with_init {
  310. // int i = 1; // expected-error {{struct/class members cannot have default values}}
  311. //};
  312. struct s_with_multiple {
  313. int i, j;
  314. };
  315. //class c_outer {
  316. // class c_inner { int disallowed; }; // expected-error {{nested class is unsupported in HLSL}}
  317. //};
  318. //
  319. //class c_outer_typedef {
  320. // typedef int local_int; // expected-error {{nested typedefs are not supported in HLSL}}
  321. //};
  322. class c_outer_fn {
  323. int fn() {
  324. class local_class { int j; };
  325. typedef int local_int;
  326. return 0;
  327. }
  328. };
  329. //class c_public {
  330. //public: int i; // expected-error {{'public' is a reserved keyword in HLSL}}
  331. //};
  332. namespace ns_with_struct {
  333. struct s { int i; };
  334. }
  335. //matrix<int...> g_matrix_pack; // expected-error {{ellipsis is unsupported in HLSL}}
  336. //matrix<ns_with_struct::s> g_matrix_ns; // expected-error {{'ns_with_struct::s' cannot be used as a type parameter where a scalar is required}}
  337. matrix<int, 1, 2> g_matrix_simple;
  338. //matrix<s_with_multiple, 1, 2> g_matrix_user; // expected-error {{'s_with_multiple' cannot be used as a type parameter where a scalar is required}}
  339. //matrix<float2, 1, 1> g_matrix_vector_shorthand; // expected-error {{'float2' cannot be used as a type parameter where a scalar is required}}
  340. //matrix<template matrix<typename, 1, 2> > g_matrix_template_template; // expected-error {{expected expression}} expected-error {{expected unqualified-id}}
  341. //matrix<matrix<typename, 1, 2> > g_matrix_template_template_nokw; // expected-error {{expected a qualified name after 'typename'}} expected-error {{expected a type}} expected-error {{expected a type}}
  342. //matrix<matrix<float, 1, 2> ... > g_matrix_template_template_ellipsis; // expected-error {{ellipsis is unsupported in HLSL}}
  343. #pragma unknown
  344. int global_fn() { return 1; }
  345. //void fn_int_arg(int); // expected-note {{candidate function not viable: no known conversion from 'int2' to 'int' for 1st argument}}
  346. void statements()
  347. {
  348. int local_i = 1; // expected-note {{declared here}}
  349. // // attempt to parse a label.
  350. //my_label: local_i = 1; // expected-error {{label is unsupported in HLSL}}
  351. //
  352. // // attempt to parse an obj-c statement
  353. // @throw local_i; // expected-error {{expected expression}}
  354. //
  355. // verify that compound statement blocks have their own scope
  356. {
  357. // inner block with scope
  358. float local_f;
  359. }
  360. {
  361. // inner block with scope
  362. double local_f;
  363. }
  364. // verify that GNU local label (__label__) is disallowed
  365. //{
  366. // __label__ X, Y; // expected-error {{local label is unsupported in HLSL}}
  367. //}
  368. // expression statements
  369. (void)local_i; // disallowed in fxc as the cast is impossible, but allowed for compat now
  370. //local_i;
  371. if (local_i == 0) {
  372. local_i++;
  373. }
  374. if (int my_if_local = global_fn()) { // this is an addition to fxc HLSL
  375. local_i++;
  376. my_if_local++;
  377. } else {
  378. my_if_local--;
  379. }
  380. // declaration in 'if' conditional clause does not leak out
  381. //my_if_local++; // expected-error {{use of undeclared identifier 'my_if_local'}}
  382. switch (int my_switch_local = global_fn()) {
  383. case 0: my_switch_local--; return;
  384. }
  385. while (int my_while_local = global_fn()) {
  386. my_while_local--;
  387. }
  388. switch(local_i) {
  389. case 0:
  390. local_i = 2;
  391. break;
  392. case 1 + 2:
  393. local_i = 3;
  394. break;
  395. //case local_i: // expected-error {{expression is not an integral constant expression}} expected-note {{read of non-const variable 'local_i' is not allowed in a constant expression}}
  396. // break;
  397. //case 10 ... 12: // expected-error {{case range is unsupported in HLSL}}
  398. // break;
  399. default:
  400. local_i = 100;
  401. // fall through
  402. }
  403. while (local_i > 0) {
  404. local_i -= 1;
  405. if (local_i == 1) continue;
  406. if (local_i == 2) break;
  407. }
  408. //asm(); // expected-error {{'asm' is a reserved keyword in HLSL}}
  409. //try { // expected-error {{'try' is a reserved keyword in HLSL}}
  410. // local_i = 1;
  411. //} catch(...) {
  412. // local_i = 2;
  413. //}
  414. // do/while (without braces)
  415. do local_i += 1; while (local_i < 3);
  416. // for, leaking declaration from control part
  417. for (int i = 0; i < 10; ++i) {
  418. local_i = i;
  419. break;
  420. }
  421. local_i = i - 1;
  422. // for, not leaking declaration from body
  423. for (int val = 0; i < 10; ++i) {
  424. int val_inner = val;
  425. break;
  426. }
  427. //local_i = val_inner; // expected-error {{use of undeclared identifier 'val_inner'}}
  428. //// for, redeclaring local
  429. //int red_same; // expected-note {{previous definition is here}}
  430. //for (int red_same = 0;;) break; // expected-warning {{redefinition of 'red_same' shadows declaration in the outer scope; most recent declaration will be used}}
  431. //// for, redeclaring local with different type
  432. //int red_different; // expected-note {{previous definition is here}}
  433. //for (float red_different = 0;;) break; // expected-warning {{redefinition of 'red_different' with a different type: 'float' vs 'int' shadows declaration in the outer scope; most recent declaration will be used}}
  434. //// this proves that the more recent variable is in scope; int2 to int is disallowed
  435. //int2 red_i_then_int = 0; // expected-note {{previous definition is here}}
  436. //for (int red_i_then_int = 0;;) break; //expected-warning {{redefinition of 'red_i_then_int' with a different type: 'int' vs 'int2' shadows declaration in the outer scope; most recent declaration will be used}}
  437. //fn_int_arg(red_i_then_int);
  438. //fn_int_arg(int2(0,0)); // expected-error {{no matching function for call to 'fn_int_arg'}}
  439. // for without declaration
  440. for (local_i = 0; ;) {
  441. break;
  442. }
  443. // for without initialization
  444. for (int j;;) { break; }
  445. // ranged for is disallowed
  446. //for (int n : local_i) { // expected-error {{expected ';' in 'for' statement specifier}} expected-error {{expected ';' in 'for' statement specifier}}
  447. // break;
  448. //}
  449. //for (int n_again in local_i) { // expected-error {{expected ';' in 'for' statement specifier}} expected-error {{unknown type name 'local_i'}} expected-error {{expected unqualified-id}} expected-error {{variable declaration in condition must have an initializer}}
  450. //}
  451. // if/else
  452. if (local_i == 0)
  453. local_i = 1;
  454. else {
  455. local_i = 2;
  456. }
  457. // empty/null statements
  458. ;;;
  459. //switch (local_i) {
  460. //default: // expected-error {{label at end of compound statement: expected statement}}
  461. //}
  462. //// goto statement
  463. //goto my_label; // expected-error {{goto is unsupported in HLSL}}
  464. // return statement
  465. return;
  466. // discard statement
  467. discard;
  468. }
  469. void expressions()
  470. {
  471. int local_i;
  472. local_i = 1 > 2 ? 0 : 1;
  473. // GNU extension to ternary operator, missing second argument to mean first
  474. //local_i = 1 > 2 ? : 1; // expected-error {{use of GNU ?: conditional expression extension, omitting middle operand is unsupported in HLSL}}
  475. // initializer lists as right-hand in binary operator (err_init_list_bin_op), but HLSL does not support init lists here
  476. //local_i = 1 + 2 * { 1 }; // expected-error {{expected expression}}
  477. local_i = true;
  478. //local_i = __objc_no; // expected-error {{'__objc_no' is a reserved keyword in HLSL}}
  479. //local_i = __objc_yes; // expected-error {{'__objc_yes' is a reserved keyword in HLSL}}
  480. //local_i = nullptr; // expected-error {{use of undeclared identifier 'nullptr'}}
  481. //local_i = decltype(1)(1); // expected-error {{use of undeclared identifier 'decltype'}}
  482. //local_i = __is_integral(bool); // expected-error {{type trait functions are not supported in HLSL}}
  483. //local_i = &local_i; // expected-error {{operator is not supported}}
  484. local_i = 'c'; // this is fine
  485. local_i = '\xFF'; // this is fine
  486. local_i = '\x94'; // this is fine
  487. //local_i = 'ab'; // expected-error {{unsupported style of char literal - use a single-character char-based literal}} expected-warning {{multi-character character constant}}
  488. //local_i = L'a'; // expected-error {{non-ASCII/multiple-char character constant is unsupported in HLSL}}
  489. //local_i = L"AB"; // expected-error {{non-ASCII string constant is unsupported in HLSL}}
  490. //local_i = __FUNCTION__; // expected-error {{'__FUNCTION__' is a reserved keyword in HLSL}}
  491. //local_i = _Generic('a',default:0); // expected-error {{'_Generic' is a reserved keyword in HLSL}}
  492. //// for string literals, see string.hlsl
  493. //local_i = *local_i; // expected-error {{operator is not supported}}
  494. local_i = +local_i;
  495. local_i = -local_i;
  496. local_i = ~local_i;
  497. local_i = !local_i;
  498. //local_i = __real local_i; // expected-error {{'__real' is a reserved keyword in HLSL}}
  499. //local_i = __imag local_i; // expected-error {{'__imag' is a reserved keyword in HLSL}}
  500. //local_i = typeid 123; // expected-error {{'typeid' is a reserved keyword in HLSL}}
  501. //local_i = __uuidof(local_i); // expected-error {{use of undeclared identifier '__uuidof'}}
  502. struct CInternal {
  503. int i;
  504. int fn() { return this.i; }
  505. CInternal getSelf() { return this; }
  506. //int operator+(int); // expected-error {{'operator' is a reserved keyword in HLSL}}
  507. };
  508. //if (__is_pod(int)) { } // expected-error {{type trait functions are not supported in HLSL}}
  509. //^(int x){ return x + 1; }; // expected-error {{compound literal is unsupported in HLSL}} expected-error {{block is unsupported in HLSL}} expected-error {{expected ')'}} expected-note {{to match this '('}}
  510. CInternal internal;
  511. //internal->fn(); // expected-error {{operator is not supported}}
  512. //local_i = (int3) { 1, 2, 3 }; // expected-error {{compound literal is unsupported in HLSL}}
  513. //Texture2D<::c_outer_fn> local_texture; // expected-error {{'::c_outer_fn' cannot be used as a type parameter}}
  514. //::new local_new; // expected-error {{new' is a reserved keyword in HLSL}}
  515. //::template foo local_template; // expected-error {{'template' is a reserved keyword in HLSL}} expected-error {{unknown type name 'foo'}}
  516. //class CInlineWithTry {
  517. // void fn()
  518. // try // expected-error {{expected function body after function declarator}}
  519. // {
  520. // int n;
  521. // }
  522. // catch(...)
  523. // {
  524. // }
  525. // void fn_other()
  526. // try // expected-error {{expected function body after function declarator}}
  527. // {
  528. // return;
  529. // }
  530. // int local_field_1 = 1; // expected-error {{struct/class members cannot have default values}}
  531. // int local_field_2[] = { 1 }; // expected-error {{struct/class members cannot have default values}} expected-error {{array bound cannot be deduced from an in-class initializer}}
  532. //};
  533. }
  534. // Pragmas.
  535. // TODO: unhandled pragmas should result in a warning
  536. int unused_i;
  537. #pragma unused(unused_i)
  538. #pragma unknown
  539. #pragma GCC visibility push(public)
  540. #pragma pack(push, 1)
  541. #pragma ms_struct(on)
  542. #pragma comment(lib, "kernel32.lib")
  543. #pragma align 64
  544. #pragma weak expressions
  545. #pragma weak expressions = expressions
  546. #pragma redefine_extname g_int new_name_g_int
  547. #pragma STDC FP_CONTRACT on
  548. #pragma OPENCL EXTENSION
  549. #pragma clang __debug captured
  550. #pragma
  551. // Preprocessor directives.
  552. #define A_DEFINE 1
  553. #if (A_DEFINE==1)
  554. #elif (A_DEFINE==2)
  555. #else
  556. #warning it does not work
  557. #endif
  558. // Verified this works but it trips the error processor.
  559. // #error err
  560. #ifdef A_DEFINE
  561. #endif
  562. #undef A_DEFINE
  563. #ifndef A_DEFINE
  564. #else
  565. #error it does not work
  566. #endif
  567. #line 321
  568. //int;
  569. // expected-warning@321 {{declaration does not declare anything}}
  570. float4 plain(float4 param4 /* : FOO */) /*: FOO */{
  571. //int i[0]; // expected-error {{array dimension must be between 1 and 65536}}
  572. //const j; // expected-error {{HLSL requires a type specifier for all declarations}}
  573. //long long ll; // expected-error {{'long' is a reserved keyword in HLSL}} expected-error {{'long' is a reserved keyword in HLSL}} expected-error {{HLSL requires a type specifier for all declarations}}
  574. return is_supported();
  575. }