cpp-errors-hv2015.hlsl 32 KB

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