cpp-errors.hlsl 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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 {{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;
  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) { // expected-error {{empty parameter list defined with a typedef of 'void' not allowed in HLSL}}
  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 }; //
  208. enum class MyEnumWithClass { MyEnumWithClass_MyVal1, MyEnumWithClass_MyVal2 }; //
  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
  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. class c_inner { int disallowed; }; // expected-error {{nested class is unsupported in HLSL}}
  277. };
  278. class c_outer_typedef {
  279. typedef int local_int; // expected-error {{nested typedefs are not supported in HLSL}}
  280. };
  281. class c_outer_fn {
  282. int fn() {
  283. class local_class { int j; };
  284. typedef int local_int;
  285. }
  286. };
  287. class c_public {
  288. public: int i; // expected-error {{'public' is a reserved keyword in HLSL}}
  289. };
  290. namespace ns_with_struct {
  291. struct s { int i; };
  292. }
  293. matrix<int...> g_matrix_pack; // expected-error {{ellipsis is unsupported in HLSL}}
  294. 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}}
  295. matrix<int, 1, 2> g_matrix_simple;
  296. 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}}
  297. matrix<float2, 1, 1> g_matrix_vector_shorthand; // expected-error {{'float2' cannot be used as a type parameter where a scalar is required}}
  298. matrix<template matrix<typename, 1, 2> > g_matrix_template_template; // expected-error {{expected expression}} expected-error {{expected unqualified-id}}
  299. 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}}
  300. matrix<matrix<float, 1, 2> ... > g_matrix_template_template_ellipsis; // expected-error {{ellipsis is unsupported in HLSL}}
  301. #pragma unknown
  302. int global_fn() { return 1; }
  303. void fn_int_arg(int);
  304. void statements()
  305. {
  306. int local_i = 1; // expected-note {{declared here}}
  307. // attempt to parse a label.
  308. my_label: local_i = 1; // expected-error {{label is unsupported in HLSL}}
  309. // attempt to parse an obj-c statement
  310. @throw local_i; // expected-error {{expected expression}}
  311. // verify that compound statement blocks have their own scope
  312. {
  313. // inner block with scope
  314. float local_f;
  315. }
  316. {
  317. // inner block with scope
  318. double local_f;
  319. }
  320. // verify that GNU local label (__label__) is disallowed
  321. {
  322. __label__ X, Y; // expected-error {{local label is unsupported in HLSL}}
  323. }
  324. // expression statements
  325. (void)local_i; // disallowed in fxc as the cast is impossible, but allowed for compat now
  326. local_i;
  327. if (local_i == 0) {
  328. local_i++;
  329. }
  330. if (int my_if_local = global_fn()) { // this is an addition to fxc HLSL
  331. local_i++;
  332. my_if_local++;
  333. } else {
  334. my_if_local--;
  335. }
  336. // declaration in 'if' conditional clause does not leak out
  337. my_if_local++; // expected-error {{use of undeclared identifier 'my_if_local'}}
  338. switch (int my_switch_local = global_fn()) {
  339. case 0: my_switch_local--; return;
  340. }
  341. while (int my_while_local = global_fn()) {
  342. my_while_local--;
  343. }
  344. switch(local_i) {
  345. case 0:
  346. local_i = 2;
  347. break;
  348. case 1 + 2:
  349. local_i = 3;
  350. break;
  351. case local_i: // expected-error {{case value is not a constant expression}} expected-note {{read of non-const variable 'local_i' is not allowed in a constant expression}}
  352. break;
  353. case 10 ... 12: // expected-error {{case range is unsupported in HLSL}}
  354. break;
  355. default:
  356. local_i = 100;
  357. // fall through
  358. }
  359. while (local_i > 0) {
  360. local_i -= 1;
  361. if (local_i == 1) continue;
  362. if (local_i == 2) break;
  363. }
  364. asm(); // expected-error {{'asm' is a reserved keyword in HLSL}}
  365. try { // expected-error {{'try' is a reserved keyword in HLSL}}
  366. local_i = 1;
  367. } catch(...) {
  368. local_i = 2;
  369. }
  370. // do/while (without braces)
  371. do local_i += 1; while (local_i < 3);
  372. // for, leaking declaration from control part
  373. for (int i = 0; i < 10; ++i) {
  374. local_i = i;
  375. break;
  376. }
  377. local_i = i - 1;
  378. // for, not leaking declaration from body
  379. for (int val = 0; i < 10; ++i) {
  380. int val_inner = val;
  381. break;
  382. }
  383. local_i = val_inner; // expected-error {{use of undeclared identifier 'val_inner'}}
  384. // for, redeclaring local
  385. int red_same; // expected-note {{previous definition is here}}
  386. for (int red_same = 0;;) break; // expected-warning {{redefinition of 'red_same' shadows declaration in the outer scope; most recent declaration will be used}}
  387. // for, redeclaring local with different type
  388. int red_different; // expected-note {{previous definition is here}}
  389. 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}}
  390. // this proves that the more recent variable is in scope
  391. int2 red_i_then_int = 0; // expected-note {{previous definition is here}}
  392. 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}}
  393. fn_int_arg(red_i_then_int);
  394. fn_int_arg(int2(0,0)); // int2 to int conversion is allowed // expected-warning {{implicit truncation of vector type}}
  395. // for without declaration
  396. for (local_i = 0; ;) {
  397. break;
  398. }
  399. // for without initialization
  400. for (int j;;) { break; }
  401. // ranged for is disallowed
  402. 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}}
  403. break;
  404. }
  405. 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}}
  406. }
  407. // if/else
  408. if (local_i == 0)
  409. local_i = 1;
  410. else {
  411. local_i = 2;
  412. }
  413. // empty/null statements
  414. ;;;
  415. switch (local_i) {
  416. default: // expected-error {{label at end of compound statement: expected statement}}
  417. }
  418. // goto statement
  419. goto my_label; // expected-error {{goto is unsupported in HLSL}}
  420. // return statement
  421. return;
  422. // discard statement
  423. discard;
  424. }
  425. void expressions()
  426. {
  427. int local_i;
  428. local_i = 1 > 2 ? 0 : 1;
  429. // GNU extension to ternary operator, missing second argument to mean first
  430. local_i = 1 > 2 ? : 1; // expected-error {{use of GNU ?: conditional expression extension, omitting middle operand is unsupported in HLSL}}
  431. // initializer lists as right-hand in binary operator (err_init_list_bin_op), but HLSL does not support init lists here
  432. local_i = 1 + 2 * { 1 }; // expected-error {{expected expression}}
  433. local_i = true;
  434. local_i = __objc_no; // expected-error {{'__objc_no' is a reserved keyword in HLSL}}
  435. local_i = __objc_yes; // expected-error {{'__objc_yes' is a reserved keyword in HLSL}}
  436. local_i = nullptr; // expected-error {{use of undeclared identifier 'nullptr'}}
  437. local_i = decltype(1)(1); // expected-error {{use of undeclared identifier 'decltype'}}
  438. local_i = __is_integral(bool); // expected-error {{__is_integral is unsupported in HLSL}}
  439. local_i = &local_i; // expected-error {{operator is not supported}}
  440. local_i = 'c'; // this is fine
  441. local_i = '\xFF'; // this is fine
  442. local_i = 'ab'; // expected-error {{unsupported style of char literal - use a single-character char-based literal}} expected-warning {{multi-character character constant}}
  443. local_i = L'a'; // expected-error {{non-ASCII/multiple-char character constant is unsupported in HLSL}}
  444. local_i = L"AB"; // expected-error {{non-ASCII string constant is unsupported in HLSL}}
  445. local_i = __FUNCTION__; // expected-error {{'__FUNCTION__' is a reserved keyword in HLSL}}
  446. local_i = _Generic('a',default:0); // expected-error {{'_Generic' is a reserved keyword in HLSL}}
  447. // for string literals, see string.hlsl
  448. local_i = *local_i; // expected-error {{operator is not supported}}
  449. local_i = +local_i;
  450. local_i = -local_i;
  451. local_i = ~local_i;
  452. local_i = !local_i;
  453. local_i = __real local_i; // expected-error {{'__real' is a reserved keyword in HLSL}}
  454. local_i = __imag local_i; // expected-error {{'__imag' is a reserved keyword in HLSL}}
  455. local_i = typeid 123; // expected-error {{'typeid' is a reserved keyword in HLSL}}
  456. local_i = __uuidof(local_i); // expected-error {{use of undeclared identifier '__uuidof'}}
  457. struct CInternal {
  458. int i;
  459. int fn() { return this.i; }
  460. CInternal getSelf() { return this; }
  461. int operator+(int); // expected-error {{'operator' is a reserved keyword in HLSL}}
  462. };
  463. if (__is_pod(int)) { } // expected-error {{__is_pod is unsupported in HLSL}}
  464. ^(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 '('}}
  465. CInternal internal;
  466. internal->fn(); // expected-error {{operator is not supported}}
  467. local_i = (int3) { 1, 2, 3 }; // expected-error {{compound literal is unsupported in HLSL}}
  468. Texture2D<::c_outer_fn> local_texture; // expected-error {{'::c_outer_fn' cannot be used as a type parameter}}
  469. ::new local_new; // expected-error {{new' is a reserved keyword in HLSL}}
  470. ::template foo local_template; // expected-error {{'template' is a reserved keyword in HLSL}} expected-error {{unknown type name 'foo'}}
  471. class CInlineWithTry {
  472. void fn()
  473. try // expected-error {{expected function body after function declarator}}
  474. {
  475. int n;
  476. }
  477. catch(...)
  478. {
  479. }
  480. void fn_other()
  481. try // expected-error {{expected function body after function declarator}}
  482. {
  483. return;
  484. }
  485. int local_field_1 = 1; // expected-error {{struct/class members cannot have default values}}
  486. int local_field_2[] = { 1 }; // expected-error {{array bound cannot be deduced from an in-class initializer}} expected-error {{struct/class members cannot have default values}}
  487. };
  488. }
  489. // Pragmas.
  490. // TODO: unhandled pragmas should result in a warning
  491. int unused_i;
  492. #pragma unused(unused_i)
  493. #pragma unknown
  494. #pragma GCC visibility push(public)
  495. #pragma pack(push, 1)
  496. #pragma ms_struct(on)
  497. #pragma comment(lib, "kernel32.lib")
  498. #pragma align 64
  499. #pragma weak expressions
  500. #pragma weak expressions = expressions
  501. #pragma redefine_extname g_int new_name_g_int
  502. #pragma STDC FP_CONTRACT on
  503. #pragma OPENCL EXTENSION
  504. #pragma clang __debug captured
  505. #pragma
  506. // Preprocessor directives.
  507. #define A_DEFINE 1
  508. #if (A_DEFINE==1)
  509. #elif (A_DEFINE==2)
  510. #else
  511. #warning it does not work
  512. #endif
  513. // Verified this works but it trips the error processor.
  514. // #error err
  515. #ifdef A_DEFINE
  516. #endif
  517. #undef A_DEFINE
  518. #ifndef A_DEFINE
  519. #else
  520. #error it does not work
  521. #endif
  522. #line 321
  523. int;
  524. // expected-warning@321 {{declaration does not declare anything}}
  525. float4 plain(float4 param4 /* : FOO */) /*: FOO */{
  526. int i[0]; // expected-error {{array dimension must be between 1 and 65536}}
  527. const j; // expected-error {{HLSL requires a type specifier for all declarations}}
  528. 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}}
  529. return is_supported();
  530. }