base.carbon 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/primitives.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/class/base.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/class/base.carbon
  12. // --- derived_to_base_conversion.h
  13. class Base {};
  14. class Derived : public Base {};
  15. // --- use_derived_to_base_conversion.carbon
  16. library "[[@TEST_NAME]]";
  17. import Cpp library "derived_to_base_conversion.h";
  18. //@dump-sem-ir-begin
  19. fn ConvertPtr(d: Cpp.Derived*) -> Cpp.Base* {
  20. return d;
  21. }
  22. //@dump-sem-ir-end
  23. fn AcceptVal(b: Cpp.Base);
  24. //@dump-sem-ir-begin
  25. fn ConvertVal(d: Cpp.Derived) {
  26. AcceptVal(d);
  27. }
  28. //@dump-sem-ir-end
  29. // --- static_member.h
  30. class Base {
  31. public:
  32. static auto base_fn() -> void;
  33. };
  34. class Derived : public Base {
  35. public:
  36. static auto derived_fn() -> void;
  37. };
  38. // --- use_static_member.carbon
  39. library "[[@TEST_NAME]]";
  40. import Cpp library "static_member.h";
  41. fn MyF() {
  42. //@dump-sem-ir-begin
  43. Cpp.Base.base_fn();
  44. Cpp.Derived.base_fn();
  45. Cpp.Derived.derived_fn();
  46. //@dump-sem-ir-end
  47. }
  48. // --- base_field.h
  49. struct Base {
  50. int a;
  51. int b;
  52. };
  53. struct Derived : Base {
  54. int b;
  55. };
  56. // --- use_base_field.carbon
  57. library "[[@TEST_NAME]]";
  58. import Cpp library "base_field.h";
  59. fn AccessDirect(d: Cpp.Derived) -> i32 {
  60. //@dump-sem-ir-begin
  61. return d.a;
  62. //@dump-sem-ir-end
  63. }
  64. fn AccessQualified(d: Cpp.Derived) -> i32 {
  65. //@dump-sem-ir-begin
  66. return d.(Cpp.Base.b);
  67. //@dump-sem-ir-end
  68. }
  69. // --- base_method.h
  70. struct Base {
  71. void f() const;
  72. void g() const;
  73. };
  74. struct Derived : Base {
  75. void g() const;
  76. };
  77. // --- use_base_method.carbon
  78. library "[[@TEST_NAME]]";
  79. import Cpp library "base_method.h";
  80. fn CallDirect(d: Cpp.Derived) {
  81. //@dump-sem-ir-begin
  82. d.f();
  83. //@dump-sem-ir-end
  84. }
  85. fn CallQualified(d: Cpp.Derived) {
  86. //@dump-sem-ir-begin
  87. d.(Cpp.Base.g)();
  88. //@dump-sem-ir-end
  89. }
  90. fn CallBaseQualifiedByDerived(d: Cpp.Derived, b: Cpp.Base) {
  91. //@dump-sem-ir-begin
  92. // `Cpp.Derived.f` names a member of `Cpp.Base`, so we allow that to be used
  93. // when `self` is a `Cpp.Base` or anything that implicitly converts to
  94. // `Cpp.Base`, such as `Cpp.Derived`.
  95. d.(Cpp.Derived.f)();
  96. b.(Cpp.Derived.f)();
  97. //@dump-sem-ir-end
  98. }
  99. // --- multiple_inheritance.h
  100. struct A { int a; };
  101. struct B { int b; };
  102. struct C : A, B {};
  103. struct Empty1 {};
  104. struct Empty2 {};
  105. struct OneNonEmptyBase : Empty1, A, Empty2 {};
  106. struct TwoNonEmptyBases : Empty1, A, B, Empty2 {};
  107. struct Polymorphic1 {
  108. virtual void f();
  109. };
  110. struct Polymorphic2 {
  111. virtual void g();
  112. };
  113. struct OnePolymorphicBase : A, B, Polymorphic1, Empty1 {};
  114. struct TwoPolymorphicBases : Polymorphic1, Polymorphic2 {};
  115. // --- fail_todo_use_multiple_inheritance.carbon
  116. library "[[@TEST_NAME]]";
  117. import Cpp library "multiple_inheritance.h";
  118. fn ConvertA(p: Cpp.C*) -> Cpp.A* {
  119. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.C*` to `Cpp.A*` [ConversionFailure]
  120. // CHECK:STDERR: return p;
  121. // CHECK:STDERR: ^~~~~~~~~
  122. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+4]]:3: note: type `Cpp.C*` does not implement interface `Core.ImplicitAs(Cpp.A*)` [MissingImplInMemberAccessNote]
  123. // CHECK:STDERR: return p;
  124. // CHECK:STDERR: ^~~~~~~~~
  125. // CHECK:STDERR:
  126. return p;
  127. }
  128. fn ConvertB(p: Cpp.C*) -> Cpp.B* {
  129. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.C*` to `Cpp.B*` [ConversionFailure]
  130. // CHECK:STDERR: return p;
  131. // CHECK:STDERR: ^~~~~~~~~
  132. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+4]]:3: note: type `Cpp.C*` does not implement interface `Core.ImplicitAs(Cpp.B*)` [MissingImplInMemberAccessNote]
  133. // CHECK:STDERR: return p;
  134. // CHECK:STDERR: ^~~~~~~~~
  135. // CHECK:STDERR:
  136. return p;
  137. }
  138. fn ConvertOneNonEmptyBaseToEmpty1(p: Cpp.OneNonEmptyBase*) -> Cpp.Empty1* {
  139. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.OneNonEmptyBase*` to `Cpp.Empty1*` [ConversionFailure]
  140. // CHECK:STDERR: return p;
  141. // CHECK:STDERR: ^~~~~~~~~
  142. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+4]]:3: note: type `Cpp.OneNonEmptyBase*` does not implement interface `Core.ImplicitAs(Cpp.Empty1*)` [MissingImplInMemberAccessNote]
  143. // CHECK:STDERR: return p;
  144. // CHECK:STDERR: ^~~~~~~~~
  145. // CHECK:STDERR:
  146. return p;
  147. }
  148. fn ConvertOneNonEmptyBaseToEmpty2(p: Cpp.OneNonEmptyBase*) -> Cpp.Empty2* {
  149. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.OneNonEmptyBase*` to `Cpp.Empty2*` [ConversionFailure]
  150. // CHECK:STDERR: return p;
  151. // CHECK:STDERR: ^~~~~~~~~
  152. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+4]]:3: note: type `Cpp.OneNonEmptyBase*` does not implement interface `Core.ImplicitAs(Cpp.Empty2*)` [MissingImplInMemberAccessNote]
  153. // CHECK:STDERR: return p;
  154. // CHECK:STDERR: ^~~~~~~~~
  155. // CHECK:STDERR:
  156. return p;
  157. }
  158. fn ConvertTwoNonEmptyBasesToA(p: Cpp.TwoNonEmptyBases*) -> Cpp.A* {
  159. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.TwoNonEmptyBases*` to `Cpp.A*` [ConversionFailure]
  160. // CHECK:STDERR: return p;
  161. // CHECK:STDERR: ^~~~~~~~~
  162. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+4]]:3: note: type `Cpp.TwoNonEmptyBases*` does not implement interface `Core.ImplicitAs(Cpp.A*)` [MissingImplInMemberAccessNote]
  163. // CHECK:STDERR: return p;
  164. // CHECK:STDERR: ^~~~~~~~~
  165. // CHECK:STDERR:
  166. return p;
  167. }
  168. fn ConvertTwoNonEmptyBasesToB(p: Cpp.TwoNonEmptyBases*) -> Cpp.B* {
  169. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.TwoNonEmptyBases*` to `Cpp.B*` [ConversionFailure]
  170. // CHECK:STDERR: return p;
  171. // CHECK:STDERR: ^~~~~~~~~
  172. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+4]]:3: note: type `Cpp.TwoNonEmptyBases*` does not implement interface `Core.ImplicitAs(Cpp.B*)` [MissingImplInMemberAccessNote]
  173. // CHECK:STDERR: return p;
  174. // CHECK:STDERR: ^~~~~~~~~
  175. // CHECK:STDERR:
  176. return p;
  177. }
  178. fn ConvertOnePolymorphicBaseToA(p: Cpp.OnePolymorphicBase*) -> Cpp.A* {
  179. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.OnePolymorphicBase*` to `Cpp.A*` [ConversionFailure]
  180. // CHECK:STDERR: return p;
  181. // CHECK:STDERR: ^~~~~~~~~
  182. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+4]]:3: note: type `Cpp.OnePolymorphicBase*` does not implement interface `Core.ImplicitAs(Cpp.A*)` [MissingImplInMemberAccessNote]
  183. // CHECK:STDERR: return p;
  184. // CHECK:STDERR: ^~~~~~~~~
  185. // CHECK:STDERR:
  186. return p;
  187. }
  188. fn ConvertOnePolymorphicBaseToB(p: Cpp.OnePolymorphicBase*) -> Cpp.B* {
  189. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.OnePolymorphicBase*` to `Cpp.B*` [ConversionFailure]
  190. // CHECK:STDERR: return p;
  191. // CHECK:STDERR: ^~~~~~~~~
  192. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+4]]:3: note: type `Cpp.OnePolymorphicBase*` does not implement interface `Core.ImplicitAs(Cpp.B*)` [MissingImplInMemberAccessNote]
  193. // CHECK:STDERR: return p;
  194. // CHECK:STDERR: ^~~~~~~~~
  195. // CHECK:STDERR:
  196. return p;
  197. }
  198. fn ConvertTwoPolymorphicBasesToPolymorphic1(p: Cpp.TwoPolymorphicBases*) -> Cpp.Polymorphic1* {
  199. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.TwoPolymorphicBases*` to `Cpp.Polymorphic1*` [ConversionFailure]
  200. // CHECK:STDERR: return p;
  201. // CHECK:STDERR: ^~~~~~~~~
  202. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+4]]:3: note: type `Cpp.TwoPolymorphicBases*` does not implement interface `Core.ImplicitAs(Cpp.Polymorphic1*)` [MissingImplInMemberAccessNote]
  203. // CHECK:STDERR: return p;
  204. // CHECK:STDERR: ^~~~~~~~~
  205. // CHECK:STDERR:
  206. return p;
  207. }
  208. fn ConvertTwoPolymorphicBasesToPolymorphic2(p: Cpp.TwoPolymorphicBases*) -> Cpp.Polymorphic2* {
  209. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.TwoPolymorphicBases*` to `Cpp.Polymorphic2*` [ConversionFailure]
  210. // CHECK:STDERR: return p;
  211. // CHECK:STDERR: ^~~~~~~~~
  212. // CHECK:STDERR: fail_todo_use_multiple_inheritance.carbon:[[@LINE+4]]:3: note: type `Cpp.TwoPolymorphicBases*` does not implement interface `Core.ImplicitAs(Cpp.Polymorphic2*)` [MissingImplInMemberAccessNote]
  213. // CHECK:STDERR: return p;
  214. // CHECK:STDERR: ^~~~~~~~~
  215. // CHECK:STDERR:
  216. return p;
  217. }
  218. // --- multiple_inheritance_with_preferred_base.carbon
  219. library "[[@TEST_NAME]]";
  220. import Cpp library "multiple_inheritance.h";
  221. // If there's only one non-empty base, that's our preferred base class. We can
  222. // convert to that.
  223. fn ConvertOneNonEmptyBaseToA(p: Cpp.OneNonEmptyBase*) -> Cpp.A* {
  224. return p;
  225. }
  226. // If there's only one polymorphic base, that's our preferred base class. We can
  227. // convert to that.
  228. fn ConvertOnePolymorphicBaseToPolymorphic1(p: Cpp.OnePolymorphicBase*) -> Cpp.Polymorphic1* {
  229. return p;
  230. }
  231. // --- virtual_inheritance.h
  232. struct A { int a; };
  233. struct B : virtual A {};
  234. void UseB(B * _Nonnull p);
  235. // --- use_virtual_inheritance_incomplete.carbon
  236. library "[[@TEST_NAME]]";
  237. import Cpp library "virtual_inheritance.h";
  238. fn Convert(p: Cpp.B*) {
  239. // OK, doesn't require `Cpp.B` to be a complete type.
  240. Cpp.UseB(p);
  241. }
  242. // --- fail_todo_use_virtual_inheritance.carbon
  243. library "[[@TEST_NAME]]";
  244. import Cpp library "virtual_inheritance.h";
  245. fn Convert(p: Cpp.B*) -> Cpp.A* {
  246. // CHECK:STDERR: fail_todo_use_virtual_inheritance.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.B*` to `Cpp.A*` [ConversionFailure]
  247. // CHECK:STDERR: return p;
  248. // CHECK:STDERR: ^~~~~~~~~
  249. // CHECK:STDERR: fail_todo_use_virtual_inheritance.carbon:[[@LINE+4]]:3: note: type `Cpp.B*` does not implement interface `Core.ImplicitAs(Cpp.A*)` [MissingImplInMemberAccessNote]
  250. // CHECK:STDERR: return p;
  251. // CHECK:STDERR: ^~~~~~~~~
  252. // CHECK:STDERR:
  253. return p;
  254. }
  255. // --- diamond.h
  256. struct A {
  257. int a;
  258. };
  259. struct B : virtual A {
  260. int b;
  261. };
  262. struct C : virtual A {
  263. int c;
  264. };
  265. struct D : B, C {
  266. int d;
  267. };
  268. // --- fail_todo_use_diamond.carbon
  269. library "[[@TEST_NAME]]";
  270. import Cpp library "diamond.h";
  271. fn ConvertBA(p: Cpp.B*) -> Cpp.A* {
  272. // CHECK:STDERR: fail_todo_use_diamond.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.B*` to `Cpp.A*` [ConversionFailure]
  273. // CHECK:STDERR: return p;
  274. // CHECK:STDERR: ^~~~~~~~~
  275. // CHECK:STDERR: fail_todo_use_diamond.carbon:[[@LINE+4]]:3: note: type `Cpp.B*` does not implement interface `Core.ImplicitAs(Cpp.A*)` [MissingImplInMemberAccessNote]
  276. // CHECK:STDERR: return p;
  277. // CHECK:STDERR: ^~~~~~~~~
  278. // CHECK:STDERR:
  279. return p;
  280. }
  281. fn ConvertCA(p: Cpp.C*) -> Cpp.A* {
  282. // CHECK:STDERR: fail_todo_use_diamond.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.C*` to `Cpp.A*` [ConversionFailure]
  283. // CHECK:STDERR: return p;
  284. // CHECK:STDERR: ^~~~~~~~~
  285. // CHECK:STDERR: fail_todo_use_diamond.carbon:[[@LINE+4]]:3: note: type `Cpp.C*` does not implement interface `Core.ImplicitAs(Cpp.A*)` [MissingImplInMemberAccessNote]
  286. // CHECK:STDERR: return p;
  287. // CHECK:STDERR: ^~~~~~~~~
  288. // CHECK:STDERR:
  289. return p;
  290. }
  291. fn ConvertDB(p: Cpp.D*) -> Cpp.B* {
  292. // CHECK:STDERR: fail_todo_use_diamond.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.D*` to `Cpp.B*` [ConversionFailure]
  293. // CHECK:STDERR: return p;
  294. // CHECK:STDERR: ^~~~~~~~~
  295. // CHECK:STDERR: fail_todo_use_diamond.carbon:[[@LINE+4]]:3: note: type `Cpp.D*` does not implement interface `Core.ImplicitAs(Cpp.B*)` [MissingImplInMemberAccessNote]
  296. // CHECK:STDERR: return p;
  297. // CHECK:STDERR: ^~~~~~~~~
  298. // CHECK:STDERR:
  299. return p;
  300. }
  301. fn ConvertDC(p: Cpp.D*) -> Cpp.C* {
  302. // CHECK:STDERR: fail_todo_use_diamond.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `Cpp.D*` to `Cpp.C*` [ConversionFailure]
  303. // CHECK:STDERR: return p;
  304. // CHECK:STDERR: ^~~~~~~~~
  305. // CHECK:STDERR: fail_todo_use_diamond.carbon:[[@LINE+4]]:3: note: type `Cpp.D*` does not implement interface `Core.ImplicitAs(Cpp.C*)` [MissingImplInMemberAccessNote]
  306. // CHECK:STDERR: return p;
  307. // CHECK:STDERR: ^~~~~~~~~
  308. // CHECK:STDERR:
  309. return p;
  310. }
  311. fn AccessBA(d: Cpp.D) -> i32 {
  312. // CHECK:STDERR: fail_todo_use_diamond.carbon:[[@LINE+7]]:11: error: cannot convert expression of type `Cpp.D` to `Cpp.B` with `as` [ConversionFailure]
  313. // CHECK:STDERR: return (d as Cpp.B).b;
  314. // CHECK:STDERR: ^~~~~~~~~~
  315. // CHECK:STDERR: fail_todo_use_diamond.carbon:[[@LINE+4]]:11: note: type `Cpp.D` does not implement interface `Core.As(Cpp.B)` [MissingImplInMemberAccessNote]
  316. // CHECK:STDERR: return (d as Cpp.B).b;
  317. // CHECK:STDERR: ^~~~~~~~~~
  318. // CHECK:STDERR:
  319. return (d as Cpp.B).b;
  320. }
  321. fn AccessCA(d: Cpp.D) -> i32 {
  322. // CHECK:STDERR: fail_todo_use_diamond.carbon:[[@LINE+7]]:11: error: cannot convert expression of type `Cpp.D` to `Cpp.C` with `as` [ConversionFailure]
  323. // CHECK:STDERR: return (d as Cpp.C).b;
  324. // CHECK:STDERR: ^~~~~~~~~~
  325. // CHECK:STDERR: fail_todo_use_diamond.carbon:[[@LINE+4]]:11: note: type `Cpp.D` does not implement interface `Core.As(Cpp.C)` [MissingImplInMemberAccessNote]
  326. // CHECK:STDERR: return (d as Cpp.C).b;
  327. // CHECK:STDERR: ^~~~~~~~~~
  328. // CHECK:STDERR:
  329. return (d as Cpp.C).b;
  330. }
  331. fn AccessDB(d: Cpp.D) -> i32 {
  332. // CHECK:STDERR: fail_todo_use_diamond.carbon:[[@LINE+7]]:10: error: cannot implicitly convert expression of type `Cpp.D` to `Cpp.B` [ConversionFailure]
  333. // CHECK:STDERR: return d.b;
  334. // CHECK:STDERR: ^~~
  335. // CHECK:STDERR: fail_todo_use_diamond.carbon:[[@LINE+4]]:10: note: type `Cpp.D` does not implement interface `Core.ImplicitAs(Cpp.B)` [MissingImplInMemberAccessNote]
  336. // CHECK:STDERR: return d.b;
  337. // CHECK:STDERR: ^~~
  338. // CHECK:STDERR:
  339. return d.b;
  340. }
  341. fn AccessDC(d: Cpp.D) -> i32 {
  342. // CHECK:STDERR: fail_todo_use_diamond.carbon:[[@LINE+7]]:10: error: cannot implicitly convert expression of type `Cpp.D` to `Cpp.C` [ConversionFailure]
  343. // CHECK:STDERR: return d.c;
  344. // CHECK:STDERR: ^~~
  345. // CHECK:STDERR: fail_todo_use_diamond.carbon:[[@LINE+4]]:10: note: type `Cpp.D` does not implement interface `Core.ImplicitAs(Cpp.C)` [MissingImplInMemberAccessNote]
  346. // CHECK:STDERR: return d.c;
  347. // CHECK:STDERR: ^~~
  348. // CHECK:STDERR:
  349. return d.c;
  350. }
  351. // --- final.h
  352. struct A final {};
  353. // --- fail_derive_from_final.carbon
  354. library "[[@TEST_NAME]]";
  355. import Cpp library "final.h";
  356. class B {
  357. // CHECK:STDERR: fail_derive_from_final.carbon:[[@LINE+4]]:16: error: deriving from final type `A`; base type must be an `abstract` or `base` class [BaseIsFinal]
  358. // CHECK:STDERR: extend base: Cpp.A;
  359. // CHECK:STDERR: ^~~~~
  360. // CHECK:STDERR:
  361. extend base: Cpp.A;
  362. }
  363. // --- union.h
  364. union U {};
  365. // --- fail_derive_from_union.carbon
  366. library "[[@TEST_NAME]]";
  367. import Cpp library "union.h";
  368. class V {
  369. // CHECK:STDERR: fail_derive_from_union.carbon:[[@LINE+4]]:16: error: deriving from final type `U`; base type must be an `abstract` or `base` class [BaseIsFinal]
  370. // CHECK:STDERR: extend base: Cpp.U;
  371. // CHECK:STDERR: ^~~~~
  372. // CHECK:STDERR:
  373. extend base: Cpp.U;
  374. }
  375. // CHECK:STDOUT: --- use_derived_to_base_conversion.carbon
  376. // CHECK:STDOUT:
  377. // CHECK:STDOUT: constants {
  378. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  379. // CHECK:STDOUT: %Derived: type = class_type @Derived [concrete]
  380. // CHECK:STDOUT: %ptr.ddb: type = ptr_type %Derived [concrete]
  381. // CHECK:STDOUT: %pattern_type.5c86: type = pattern_type %ptr.ddb [concrete]
  382. // CHECK:STDOUT: %Base: type = class_type @Base [concrete]
  383. // CHECK:STDOUT: %ptr.fb2: type = ptr_type %Base [concrete]
  384. // CHECK:STDOUT: %.fa5: Core.Form = init_form %ptr.fb2, call_param1 [concrete]
  385. // CHECK:STDOUT: %pattern_type.72a: type = pattern_type %ptr.fb2 [concrete]
  386. // CHECK:STDOUT: %ConvertPtr.type: type = fn_type @ConvertPtr [concrete]
  387. // CHECK:STDOUT: %ConvertPtr: %ConvertPtr.type = struct_value () [concrete]
  388. // CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
  389. // CHECK:STDOUT: %T.67d: type = symbolic_binding T, 0 [symbolic]
  390. // CHECK:STDOUT: %ptr.as.Copy.impl.Op.type.2d4: type = fn_type @ptr.as.Copy.impl.Op, @ptr.as.Copy.impl(%T.67d) [symbolic]
  391. // CHECK:STDOUT: %ptr.as.Copy.impl.Op.74e: %ptr.as.Copy.impl.Op.type.2d4 = struct_value () [symbolic]
  392. // CHECK:STDOUT: %Copy.impl_witness.33f: <witness> = impl_witness imports.%Copy.impl_witness_table.c3a, @ptr.as.Copy.impl(%Base) [concrete]
  393. // CHECK:STDOUT: %ptr.as.Copy.impl.Op.type.d24: type = fn_type @ptr.as.Copy.impl.Op, @ptr.as.Copy.impl(%Base) [concrete]
  394. // CHECK:STDOUT: %ptr.as.Copy.impl.Op.dae: %ptr.as.Copy.impl.Op.type.d24 = struct_value () [concrete]
  395. // CHECK:STDOUT: %Copy.facet: %Copy.type = facet_value %ptr.fb2, (%Copy.impl_witness.33f) [concrete]
  396. // CHECK:STDOUT: %Copy.WithSelf.Op.type.326: type = fn_type @Copy.WithSelf.Op, @Copy(%Copy.facet) [concrete]
  397. // CHECK:STDOUT: %.107: type = fn_type_with_self_type %Copy.WithSelf.Op.type.326, %Copy.facet [concrete]
  398. // CHECK:STDOUT: %ptr.as.Copy.impl.Op.specific_fn: <specific function> = specific_function %ptr.as.Copy.impl.Op.dae, @ptr.as.Copy.impl.Op(%Base) [concrete]
  399. // CHECK:STDOUT: %AcceptVal.type: type = fn_type @AcceptVal [concrete]
  400. // CHECK:STDOUT: %AcceptVal: %AcceptVal.type = struct_value () [concrete]
  401. // CHECK:STDOUT: %pattern_type.5de: type = pattern_type %Derived [concrete]
  402. // CHECK:STDOUT: %ConvertVal.type: type = fn_type @ConvertVal [concrete]
  403. // CHECK:STDOUT: %ConvertVal: %ConvertVal.type = struct_value () [concrete]
  404. // CHECK:STDOUT: }
  405. // CHECK:STDOUT:
  406. // CHECK:STDOUT: imports {
  407. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  408. // CHECK:STDOUT: .Derived = %Derived.decl
  409. // CHECK:STDOUT: .Base = %Base.decl
  410. // CHECK:STDOUT: import Cpp//...
  411. // CHECK:STDOUT: }
  412. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [concrete = constants.%Derived] {} {}
  413. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [concrete = constants.%Base] {} {}
  414. // CHECK:STDOUT: %Core.import_ref.203: @ptr.as.Copy.impl.%ptr.as.Copy.impl.Op.type (%ptr.as.Copy.impl.Op.type.2d4) = import_ref Core//prelude/parts/copy, loc{{\d+_\d+}}, loaded [symbolic = @ptr.as.Copy.impl.%ptr.as.Copy.impl.Op (constants.%ptr.as.Copy.impl.Op.74e)]
  415. // CHECK:STDOUT: %Copy.impl_witness_table.c3a = impl_witness_table (%Core.import_ref.203), @ptr.as.Copy.impl [concrete]
  416. // CHECK:STDOUT: }
  417. // CHECK:STDOUT:
  418. // CHECK:STDOUT: file {
  419. // CHECK:STDOUT: %ConvertPtr.decl: %ConvertPtr.type = fn_decl @ConvertPtr [concrete = constants.%ConvertPtr] {
  420. // CHECK:STDOUT: %d.patt: %pattern_type.5c86 = value_binding_pattern d [concrete]
  421. // CHECK:STDOUT: %d.param_patt: %pattern_type.5c86 = value_param_pattern %d.patt, call_param0 [concrete]
  422. // CHECK:STDOUT: %return.patt: %pattern_type.72a = return_slot_pattern [concrete]
  423. // CHECK:STDOUT: %return.param_patt: %pattern_type.72a = out_param_pattern %return.patt, call_param1 [concrete]
  424. // CHECK:STDOUT: } {
  425. // CHECK:STDOUT: %Cpp.ref.loc7_35: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  426. // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%Base.decl [concrete = constants.%Base]
  427. // CHECK:STDOUT: %ptr.loc7_43: type = ptr_type %Base.ref [concrete = constants.%ptr.fb2]
  428. // CHECK:STDOUT: %.loc7_43: Core.Form = init_form %ptr.loc7_43, call_param1 [concrete = constants.%.fa5]
  429. // CHECK:STDOUT: %d.param: %ptr.ddb = value_param call_param0
  430. // CHECK:STDOUT: %.loc7_29: type = splice_block %ptr.loc7_29 [concrete = constants.%ptr.ddb] {
  431. // CHECK:STDOUT: %Cpp.ref.loc7_18: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  432. // CHECK:STDOUT: %Derived.ref: type = name_ref Derived, imports.%Derived.decl [concrete = constants.%Derived]
  433. // CHECK:STDOUT: %ptr.loc7_29: type = ptr_type %Derived.ref [concrete = constants.%ptr.ddb]
  434. // CHECK:STDOUT: }
  435. // CHECK:STDOUT: %d: %ptr.ddb = value_binding d, %d.param
  436. // CHECK:STDOUT: %return.param: ref %ptr.fb2 = out_param call_param1
  437. // CHECK:STDOUT: %return: ref %ptr.fb2 = return_slot %return.param
  438. // CHECK:STDOUT: }
  439. // CHECK:STDOUT: %ConvertVal.decl: %ConvertVal.type = fn_decl @ConvertVal [concrete = constants.%ConvertVal] {
  440. // CHECK:STDOUT: %d.patt: %pattern_type.5de = value_binding_pattern d [concrete]
  441. // CHECK:STDOUT: %d.param_patt: %pattern_type.5de = value_param_pattern %d.patt, call_param0 [concrete]
  442. // CHECK:STDOUT: } {
  443. // CHECK:STDOUT: %d.param: %Derived = value_param call_param0
  444. // CHECK:STDOUT: %.loc15: type = splice_block %Derived.ref [concrete = constants.%Derived] {
  445. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  446. // CHECK:STDOUT: %Derived.ref: type = name_ref Derived, imports.%Derived.decl [concrete = constants.%Derived]
  447. // CHECK:STDOUT: }
  448. // CHECK:STDOUT: %d: %Derived = value_binding d, %d.param
  449. // CHECK:STDOUT: }
  450. // CHECK:STDOUT: }
  451. // CHECK:STDOUT:
  452. // CHECK:STDOUT: fn @ConvertPtr(%d.param: %ptr.ddb) -> out %return.param: %ptr.fb2 {
  453. // CHECK:STDOUT: !entry:
  454. // CHECK:STDOUT: %d.ref: %ptr.ddb = name_ref d, %d
  455. // CHECK:STDOUT: %.loc8_11.1: ref %Derived = deref %d.ref
  456. // CHECK:STDOUT: %.loc8_11.2: ref %Base = class_element_access %.loc8_11.1, element0
  457. // CHECK:STDOUT: %addr: %ptr.fb2 = addr_of %.loc8_11.2
  458. // CHECK:STDOUT: %.loc8_11.3: %ptr.fb2 = converted %d.ref, %addr
  459. // CHECK:STDOUT: %impl.elem0: %.107 = impl_witness_access constants.%Copy.impl_witness.33f, element0 [concrete = constants.%ptr.as.Copy.impl.Op.dae]
  460. // CHECK:STDOUT: %bound_method.loc8_11.1: <bound method> = bound_method %.loc8_11.3, %impl.elem0
  461. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @ptr.as.Copy.impl.Op(constants.%Base) [concrete = constants.%ptr.as.Copy.impl.Op.specific_fn]
  462. // CHECK:STDOUT: %bound_method.loc8_11.2: <bound method> = bound_method %.loc8_11.3, %specific_fn
  463. // CHECK:STDOUT: %ptr.as.Copy.impl.Op.call: init %ptr.fb2 = call %bound_method.loc8_11.2(%.loc8_11.3)
  464. // CHECK:STDOUT: return %ptr.as.Copy.impl.Op.call
  465. // CHECK:STDOUT: }
  466. // CHECK:STDOUT:
  467. // CHECK:STDOUT: fn @ConvertVal(%d.param: %Derived) {
  468. // CHECK:STDOUT: !entry:
  469. // CHECK:STDOUT: %AcceptVal.ref: %AcceptVal.type = name_ref AcceptVal, file.%AcceptVal.decl [concrete = constants.%AcceptVal]
  470. // CHECK:STDOUT: %d.ref: %Derived = name_ref d, %d
  471. // CHECK:STDOUT: %.loc16_13.1: ref %Base = class_element_access %d.ref, element0
  472. // CHECK:STDOUT: %.loc16_13.2: ref %Base = converted %d.ref, %.loc16_13.1
  473. // CHECK:STDOUT: %.loc16_13.3: %Base = acquire_value %.loc16_13.2
  474. // CHECK:STDOUT: %AcceptVal.call: init %empty_tuple.type = call %AcceptVal.ref(%.loc16_13.3)
  475. // CHECK:STDOUT: return
  476. // CHECK:STDOUT: }
  477. // CHECK:STDOUT:
  478. // CHECK:STDOUT: --- use_static_member.carbon
  479. // CHECK:STDOUT:
  480. // CHECK:STDOUT: constants {
  481. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  482. // CHECK:STDOUT: %Base: type = class_type @Base [concrete]
  483. // CHECK:STDOUT: %Base.base_fn.cpp_overload_set.type: type = cpp_overload_set_type @Base.base_fn.cpp_overload_set [concrete]
  484. // CHECK:STDOUT: %Base.base_fn.cpp_overload_set.value: %Base.base_fn.cpp_overload_set.type = cpp_overload_set_value @Base.base_fn.cpp_overload_set [concrete]
  485. // CHECK:STDOUT: %Base.base_fn.type: type = fn_type @Base.base_fn [concrete]
  486. // CHECK:STDOUT: %Base.base_fn: %Base.base_fn.type = struct_value () [concrete]
  487. // CHECK:STDOUT: %Derived: type = class_type @Derived [concrete]
  488. // CHECK:STDOUT: %Derived.base_fn.cpp_overload_set.type: type = cpp_overload_set_type @Derived.base_fn.cpp_overload_set [concrete]
  489. // CHECK:STDOUT: %Derived.base_fn.cpp_overload_set.value: %Derived.base_fn.cpp_overload_set.type = cpp_overload_set_value @Derived.base_fn.cpp_overload_set [concrete]
  490. // CHECK:STDOUT: %Derived.derived_fn.cpp_overload_set.type: type = cpp_overload_set_type @Derived.derived_fn.cpp_overload_set [concrete]
  491. // CHECK:STDOUT: %Derived.derived_fn.cpp_overload_set.value: %Derived.derived_fn.cpp_overload_set.type = cpp_overload_set_value @Derived.derived_fn.cpp_overload_set [concrete]
  492. // CHECK:STDOUT: %Derived.derived_fn.type: type = fn_type @Derived.derived_fn [concrete]
  493. // CHECK:STDOUT: %Derived.derived_fn: %Derived.derived_fn.type = struct_value () [concrete]
  494. // CHECK:STDOUT: }
  495. // CHECK:STDOUT:
  496. // CHECK:STDOUT: imports {
  497. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  498. // CHECK:STDOUT: .Base = %Base.decl
  499. // CHECK:STDOUT: .Derived = %Derived.decl
  500. // CHECK:STDOUT: import Cpp//...
  501. // CHECK:STDOUT: }
  502. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [concrete = constants.%Base] {} {}
  503. // CHECK:STDOUT: %Base.base_fn.cpp_overload_set.value: %Base.base_fn.cpp_overload_set.type = cpp_overload_set_value @Base.base_fn.cpp_overload_set [concrete = constants.%Base.base_fn.cpp_overload_set.value]
  504. // CHECK:STDOUT: %Base.base_fn.decl: %Base.base_fn.type = fn_decl @Base.base_fn [concrete = constants.%Base.base_fn] {} {}
  505. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [concrete = constants.%Derived] {} {}
  506. // CHECK:STDOUT: %Derived.base_fn.cpp_overload_set.value: %Derived.base_fn.cpp_overload_set.type = cpp_overload_set_value @Derived.base_fn.cpp_overload_set [concrete = constants.%Derived.base_fn.cpp_overload_set.value]
  507. // CHECK:STDOUT: %Derived.derived_fn.cpp_overload_set.value: %Derived.derived_fn.cpp_overload_set.type = cpp_overload_set_value @Derived.derived_fn.cpp_overload_set [concrete = constants.%Derived.derived_fn.cpp_overload_set.value]
  508. // CHECK:STDOUT: %Derived.derived_fn.decl: %Derived.derived_fn.type = fn_decl @Derived.derived_fn [concrete = constants.%Derived.derived_fn] {} {}
  509. // CHECK:STDOUT: }
  510. // CHECK:STDOUT:
  511. // CHECK:STDOUT: fn @MyF() {
  512. // CHECK:STDOUT: !entry:
  513. // CHECK:STDOUT: %Cpp.ref.loc8: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  514. // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%Base.decl [concrete = constants.%Base]
  515. // CHECK:STDOUT: %base_fn.ref.loc8: %Base.base_fn.cpp_overload_set.type = name_ref base_fn, imports.%Base.base_fn.cpp_overload_set.value [concrete = constants.%Base.base_fn.cpp_overload_set.value]
  516. // CHECK:STDOUT: %Base.base_fn.call.loc8: init %empty_tuple.type = call imports.%Base.base_fn.decl()
  517. // CHECK:STDOUT: %Cpp.ref.loc9: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  518. // CHECK:STDOUT: %Derived.ref.loc9: type = name_ref Derived, imports.%Derived.decl [concrete = constants.%Derived]
  519. // CHECK:STDOUT: %base_fn.ref.loc9: %Derived.base_fn.cpp_overload_set.type = name_ref base_fn, imports.%Derived.base_fn.cpp_overload_set.value [concrete = constants.%Derived.base_fn.cpp_overload_set.value]
  520. // CHECK:STDOUT: %Base.base_fn.call.loc9: init %empty_tuple.type = call imports.%Base.base_fn.decl()
  521. // CHECK:STDOUT: %Cpp.ref.loc10: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  522. // CHECK:STDOUT: %Derived.ref.loc10: type = name_ref Derived, imports.%Derived.decl [concrete = constants.%Derived]
  523. // CHECK:STDOUT: %derived_fn.ref: %Derived.derived_fn.cpp_overload_set.type = name_ref derived_fn, imports.%Derived.derived_fn.cpp_overload_set.value [concrete = constants.%Derived.derived_fn.cpp_overload_set.value]
  524. // CHECK:STDOUT: %Derived.derived_fn.call: init %empty_tuple.type = call imports.%Derived.derived_fn.decl()
  525. // CHECK:STDOUT: <elided>
  526. // CHECK:STDOUT: }
  527. // CHECK:STDOUT:
  528. // CHECK:STDOUT: --- use_base_field.carbon
  529. // CHECK:STDOUT:
  530. // CHECK:STDOUT: constants {
  531. // CHECK:STDOUT: %Derived: type = class_type @Derived [concrete]
  532. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  533. // CHECK:STDOUT: %N: Core.IntLiteral = symbolic_binding N, 0 [symbolic]
  534. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  535. // CHECK:STDOUT: %Base: type = class_type @Base [concrete]
  536. // CHECK:STDOUT: %Base.elem: type = unbound_element_type %Base, %i32 [concrete]
  537. // CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
  538. // CHECK:STDOUT: %Int.as.Copy.impl.Op.type.824: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%N) [symbolic]
  539. // CHECK:STDOUT: %Int.as.Copy.impl.Op.9b9: %Int.as.Copy.impl.Op.type.824 = struct_value () [symbolic]
  540. // CHECK:STDOUT: %Copy.impl_witness.f17: <witness> = impl_witness imports.%Copy.impl_witness_table.e76, @Int.as.Copy.impl(%int_32) [concrete]
  541. // CHECK:STDOUT: %Int.as.Copy.impl.Op.type.546: type = fn_type @Int.as.Copy.impl.Op, @Int.as.Copy.impl(%int_32) [concrete]
  542. // CHECK:STDOUT: %Int.as.Copy.impl.Op.664: %Int.as.Copy.impl.Op.type.546 = struct_value () [concrete]
  543. // CHECK:STDOUT: %Copy.facet: %Copy.type = facet_value %i32, (%Copy.impl_witness.f17) [concrete]
  544. // CHECK:STDOUT: %Copy.WithSelf.Op.type.081: type = fn_type @Copy.WithSelf.Op, @Copy(%Copy.facet) [concrete]
  545. // CHECK:STDOUT: %.8e2: type = fn_type_with_self_type %Copy.WithSelf.Op.type.081, %Copy.facet [concrete]
  546. // CHECK:STDOUT: %Int.as.Copy.impl.Op.specific_fn: <specific function> = specific_function %Int.as.Copy.impl.Op.664, @Int.as.Copy.impl.Op(%int_32) [concrete]
  547. // CHECK:STDOUT: }
  548. // CHECK:STDOUT:
  549. // CHECK:STDOUT: imports {
  550. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  551. // CHECK:STDOUT: .Derived = %Derived.decl
  552. // CHECK:STDOUT: .Base = %Base.decl
  553. // CHECK:STDOUT: import Cpp//...
  554. // CHECK:STDOUT: }
  555. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [concrete = constants.%Derived] {} {}
  556. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [concrete = constants.%Base] {} {}
  557. // CHECK:STDOUT: %Core.import_ref.18d: @Int.as.Copy.impl.%Int.as.Copy.impl.Op.type (%Int.as.Copy.impl.Op.type.824) = import_ref Core//prelude/parts/int, loc{{\d+_\d+}}, loaded [symbolic = @Int.as.Copy.impl.%Int.as.Copy.impl.Op (constants.%Int.as.Copy.impl.Op.9b9)]
  558. // CHECK:STDOUT: %Copy.impl_witness_table.e76 = impl_witness_table (%Core.import_ref.18d), @Int.as.Copy.impl [concrete]
  559. // CHECK:STDOUT: }
  560. // CHECK:STDOUT:
  561. // CHECK:STDOUT: fn @AccessDirect(%d.param: %Derived) -> out %return.param: %i32 {
  562. // CHECK:STDOUT: !entry:
  563. // CHECK:STDOUT: %d.ref: %Derived = name_ref d, %d
  564. // CHECK:STDOUT: %a.ref: %Base.elem = name_ref a, @Base.%.1 [concrete = @Base.%.1]
  565. // CHECK:STDOUT: %.loc8_11.1: ref %Base = class_element_access %d.ref, element0
  566. // CHECK:STDOUT: %.loc8_11.2: ref %Base = converted %d.ref, %.loc8_11.1
  567. // CHECK:STDOUT: %.loc8_11.3: ref %i32 = class_element_access %.loc8_11.2, element0
  568. // CHECK:STDOUT: %.loc8_11.4: %i32 = acquire_value %.loc8_11.3
  569. // CHECK:STDOUT: %impl.elem0: %.8e2 = impl_witness_access constants.%Copy.impl_witness.f17, element0 [concrete = constants.%Int.as.Copy.impl.Op.664]
  570. // CHECK:STDOUT: %bound_method.loc8_11.1: <bound method> = bound_method %.loc8_11.4, %impl.elem0
  571. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Int.as.Copy.impl.Op(constants.%int_32) [concrete = constants.%Int.as.Copy.impl.Op.specific_fn]
  572. // CHECK:STDOUT: %bound_method.loc8_11.2: <bound method> = bound_method %.loc8_11.4, %specific_fn
  573. // CHECK:STDOUT: %Int.as.Copy.impl.Op.call: init %i32 = call %bound_method.loc8_11.2(%.loc8_11.4)
  574. // CHECK:STDOUT: return %Int.as.Copy.impl.Op.call
  575. // CHECK:STDOUT: }
  576. // CHECK:STDOUT:
  577. // CHECK:STDOUT: fn @AccessQualified(%d.param: %Derived) -> out %return.param: %i32 {
  578. // CHECK:STDOUT: !entry:
  579. // CHECK:STDOUT: %d.ref: %Derived = name_ref d, %d
  580. // CHECK:STDOUT: %Cpp.ref.loc14: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  581. // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%Base.decl [concrete = constants.%Base]
  582. // CHECK:STDOUT: %b.ref: %Base.elem = name_ref b, @Base.%.2 [concrete = @Base.%.2]
  583. // CHECK:STDOUT: %.loc14_11.1: ref %Base = class_element_access %d.ref, element0
  584. // CHECK:STDOUT: %.loc14_11.2: ref %Base = converted %d.ref, %.loc14_11.1
  585. // CHECK:STDOUT: %.loc14_11.3: ref %i32 = class_element_access %.loc14_11.2, element1
  586. // CHECK:STDOUT: %.loc14_11.4: %i32 = acquire_value %.loc14_11.3
  587. // CHECK:STDOUT: %impl.elem0: %.8e2 = impl_witness_access constants.%Copy.impl_witness.f17, element0 [concrete = constants.%Int.as.Copy.impl.Op.664]
  588. // CHECK:STDOUT: %bound_method.loc14_11.1: <bound method> = bound_method %.loc14_11.4, %impl.elem0
  589. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Int.as.Copy.impl.Op(constants.%int_32) [concrete = constants.%Int.as.Copy.impl.Op.specific_fn]
  590. // CHECK:STDOUT: %bound_method.loc14_11.2: <bound method> = bound_method %.loc14_11.4, %specific_fn
  591. // CHECK:STDOUT: %Int.as.Copy.impl.Op.call: init %i32 = call %bound_method.loc14_11.2(%.loc14_11.4)
  592. // CHECK:STDOUT: return %Int.as.Copy.impl.Op.call
  593. // CHECK:STDOUT: }
  594. // CHECK:STDOUT:
  595. // CHECK:STDOUT: --- use_base_method.carbon
  596. // CHECK:STDOUT:
  597. // CHECK:STDOUT: constants {
  598. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  599. // CHECK:STDOUT: %Derived: type = class_type @Derived [concrete]
  600. // CHECK:STDOUT: %Base: type = class_type @Base [concrete]
  601. // CHECK:STDOUT: %Derived.f.cpp_overload_set.type: type = cpp_overload_set_type @Derived.f.cpp_overload_set [concrete]
  602. // CHECK:STDOUT: %Derived.f.cpp_overload_set.value: %Derived.f.cpp_overload_set.type = cpp_overload_set_value @Derived.f.cpp_overload_set [concrete]
  603. // CHECK:STDOUT: %f__carbon_thunk.type: type = fn_type @f__carbon_thunk [concrete]
  604. // CHECK:STDOUT: %f__carbon_thunk: %f__carbon_thunk.type = struct_value () [concrete]
  605. // CHECK:STDOUT: %Base.g.cpp_overload_set.type: type = cpp_overload_set_type @Base.g.cpp_overload_set [concrete]
  606. // CHECK:STDOUT: %Base.g.cpp_overload_set.value: %Base.g.cpp_overload_set.type = cpp_overload_set_value @Base.g.cpp_overload_set [concrete]
  607. // CHECK:STDOUT: %g__carbon_thunk.type: type = fn_type @g__carbon_thunk [concrete]
  608. // CHECK:STDOUT: %g__carbon_thunk: %g__carbon_thunk.type = struct_value () [concrete]
  609. // CHECK:STDOUT: }
  610. // CHECK:STDOUT:
  611. // CHECK:STDOUT: imports {
  612. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  613. // CHECK:STDOUT: .Derived = %Derived.decl
  614. // CHECK:STDOUT: .Base = %Base.decl
  615. // CHECK:STDOUT: import Cpp//...
  616. // CHECK:STDOUT: }
  617. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [concrete = constants.%Derived] {} {}
  618. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [concrete = constants.%Base] {} {}
  619. // CHECK:STDOUT: %Derived.f.cpp_overload_set.value: %Derived.f.cpp_overload_set.type = cpp_overload_set_value @Derived.f.cpp_overload_set [concrete = constants.%Derived.f.cpp_overload_set.value]
  620. // CHECK:STDOUT: %f__carbon_thunk.decl: %f__carbon_thunk.type = fn_decl @f__carbon_thunk [concrete = constants.%f__carbon_thunk] {
  621. // CHECK:STDOUT: <elided>
  622. // CHECK:STDOUT: } {
  623. // CHECK:STDOUT: <elided>
  624. // CHECK:STDOUT: }
  625. // CHECK:STDOUT: %Base.g.cpp_overload_set.value: %Base.g.cpp_overload_set.type = cpp_overload_set_value @Base.g.cpp_overload_set [concrete = constants.%Base.g.cpp_overload_set.value]
  626. // CHECK:STDOUT: %g__carbon_thunk.decl: %g__carbon_thunk.type = fn_decl @g__carbon_thunk [concrete = constants.%g__carbon_thunk] {
  627. // CHECK:STDOUT: <elided>
  628. // CHECK:STDOUT: } {
  629. // CHECK:STDOUT: <elided>
  630. // CHECK:STDOUT: }
  631. // CHECK:STDOUT: }
  632. // CHECK:STDOUT:
  633. // CHECK:STDOUT: fn @CallDirect(%d.param: %Derived) {
  634. // CHECK:STDOUT: !entry:
  635. // CHECK:STDOUT: %d.ref: %Derived = name_ref d, %d
  636. // CHECK:STDOUT: %f.ref: %Derived.f.cpp_overload_set.type = name_ref f, imports.%Derived.f.cpp_overload_set.value [concrete = constants.%Derived.f.cpp_overload_set.value]
  637. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %d.ref, %f.ref
  638. // CHECK:STDOUT: %.loc8_3.1: ref %Base = class_element_access %d.ref, element0
  639. // CHECK:STDOUT: %.loc8_3.2: ref %Base = converted %d.ref, %.loc8_3.1
  640. // CHECK:STDOUT: %.loc8_3.3: %Base = acquire_value %.loc8_3.2
  641. // CHECK:STDOUT: %f__carbon_thunk.call: init %empty_tuple.type = call imports.%f__carbon_thunk.decl(%.loc8_3.3)
  642. // CHECK:STDOUT: <elided>
  643. // CHECK:STDOUT: }
  644. // CHECK:STDOUT:
  645. // CHECK:STDOUT: fn @CallQualified(%d.param: %Derived) {
  646. // CHECK:STDOUT: !entry:
  647. // CHECK:STDOUT: %d.ref: %Derived = name_ref d, %d
  648. // CHECK:STDOUT: %Cpp.ref.loc14: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  649. // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%Base.decl [concrete = constants.%Base]
  650. // CHECK:STDOUT: %g.ref: %Base.g.cpp_overload_set.type = name_ref g, imports.%Base.g.cpp_overload_set.value [concrete = constants.%Base.g.cpp_overload_set.value]
  651. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %d.ref, %g.ref
  652. // CHECK:STDOUT: %.loc14_3.1: ref %Base = class_element_access %d.ref, element0
  653. // CHECK:STDOUT: %.loc14_3.2: ref %Base = converted %d.ref, %.loc14_3.1
  654. // CHECK:STDOUT: %.loc14_3.3: %Base = acquire_value %.loc14_3.2
  655. // CHECK:STDOUT: %g__carbon_thunk.call: init %empty_tuple.type = call imports.%g__carbon_thunk.decl(%.loc14_3.3)
  656. // CHECK:STDOUT: <elided>
  657. // CHECK:STDOUT: }
  658. // CHECK:STDOUT:
  659. // CHECK:STDOUT: fn @CallBaseQualifiedByDerived(%d.param: %Derived, %b.param: %Base) {
  660. // CHECK:STDOUT: !entry:
  661. // CHECK:STDOUT: %d.ref: %Derived = name_ref d, %d
  662. // CHECK:STDOUT: %Cpp.ref.loc23: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  663. // CHECK:STDOUT: %Derived.ref.loc23: type = name_ref Derived, imports.%Derived.decl [concrete = constants.%Derived]
  664. // CHECK:STDOUT: %f.ref.loc23: %Derived.f.cpp_overload_set.type = name_ref f, imports.%Derived.f.cpp_overload_set.value [concrete = constants.%Derived.f.cpp_overload_set.value]
  665. // CHECK:STDOUT: %bound_method.loc23: <bound method> = bound_method %d.ref, %f.ref.loc23
  666. // CHECK:STDOUT: %.loc23_3.1: ref %Base = class_element_access %d.ref, element0
  667. // CHECK:STDOUT: %.loc23_3.2: ref %Base = converted %d.ref, %.loc23_3.1
  668. // CHECK:STDOUT: %.loc23_3.3: %Base = acquire_value %.loc23_3.2
  669. // CHECK:STDOUT: %f__carbon_thunk.call.loc23: init %empty_tuple.type = call imports.%f__carbon_thunk.decl(%.loc23_3.3)
  670. // CHECK:STDOUT: %b.ref: %Base = name_ref b, %b
  671. // CHECK:STDOUT: %Cpp.ref.loc24: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  672. // CHECK:STDOUT: %Derived.ref.loc24: type = name_ref Derived, imports.%Derived.decl [concrete = constants.%Derived]
  673. // CHECK:STDOUT: %f.ref.loc24: %Derived.f.cpp_overload_set.type = name_ref f, imports.%Derived.f.cpp_overload_set.value [concrete = constants.%Derived.f.cpp_overload_set.value]
  674. // CHECK:STDOUT: %bound_method.loc24: <bound method> = bound_method %b.ref, %f.ref.loc24
  675. // CHECK:STDOUT: %f__carbon_thunk.call.loc24: init %empty_tuple.type = call imports.%f__carbon_thunk.decl(%b.ref)
  676. // CHECK:STDOUT: <elided>
  677. // CHECK:STDOUT: }
  678. // CHECK:STDOUT: