template_template_param.carbon 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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/convert.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/template/template_template_param.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/template/template_template_param.carbon
  12. // --- templates.h
  13. template<typename> struct A {};
  14. template<typename> struct B {};
  15. template<typename, typename> struct C {};
  16. template<template<typename> typename, template<typename> typename>
  17. struct TwoTemplates {};
  18. // --- valid.carbon
  19. library "[[@TEST_NAME]]";
  20. import Cpp library "templates.h";
  21. //@dump-sem-ir-begin
  22. var x: Cpp.TwoTemplates(Cpp.A, Cpp.B);
  23. //@dump-sem-ir-end
  24. // --- fail_template_mismatch.carbon
  25. library "[[@TEST_NAME]]";
  26. import Cpp library "templates.h";
  27. //@dump-sem-ir-begin
  28. // CHECK:STDERR: fail_template_mismatch.carbon:[[@LINE+15]]:35: error: too few template arguments for class template 'C' [CppInteropParseError]
  29. // CHECK:STDERR: 22 | var x: Cpp.TwoTemplates(Cpp.A, Cpp.C);
  30. // CHECK:STDERR: | ^
  31. // CHECK:STDERR: fail_template_mismatch.carbon:[[@LINE+12]]:35: note: template template argument has different template parameters than its corresponding template template parameter [CppInteropParseNote]
  32. // CHECK:STDERR: 22 | var x: Cpp.TwoTemplates(Cpp.A, Cpp.C);
  33. // CHECK:STDERR: | ^
  34. // CHECK:STDERR: fail_template_mismatch.carbon:[[@LINE-9]]:10: in file included here [InCppInclude]
  35. // CHECK:STDERR: ./templates.h:6:66: note: previous template template parameter is here [CppInteropParseNote]
  36. // CHECK:STDERR: 6 | template<template<typename> typename, template<typename> typename>
  37. // CHECK:STDERR: | ~~~~~~~~~~~~~~~~~~ ^
  38. // CHECK:STDERR: fail_template_mismatch.carbon:[[@LINE-13]]:10: in file included here [InCppInclude]
  39. // CHECK:STDERR: ./templates.h:4:37: note: template is declared here [CppInteropParseNote]
  40. // CHECK:STDERR: 4 | template<typename, typename> struct C {};
  41. // CHECK:STDERR: | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
  42. // CHECK:STDERR:
  43. var x: Cpp.TwoTemplates(Cpp.A, Cpp.C);
  44. //@dump-sem-ir-end
  45. // --- fail_type_argument.carbon
  46. library "[[@TEST_NAME]]";
  47. import Cpp library "templates.h";
  48. class X {}
  49. // CHECK:STDERR: fail_type_argument.carbon:[[@LINE+4]]:32: error: template argument for template template parameter must be a class template or type alias template [CppInteropParseError]
  50. // CHECK:STDERR: 12 | var x: Cpp.TwoTemplates(Cpp.A, X);
  51. // CHECK:STDERR: | ^
  52. // CHECK:STDERR:
  53. var x: Cpp.TwoTemplates(Cpp.A, X);
  54. // --- fail_non_type_argument.carbon
  55. library "[[@TEST_NAME]]";
  56. import Cpp library "templates.h";
  57. // CHECK:STDERR: fail_non_type_argument.carbon:[[@LINE+4]]:32: error: template argument for template template parameter must be a class template or type alias template [CppInteropParseError]
  58. // CHECK:STDERR: 10 | var x: Cpp.TwoTemplates(Cpp.A, true);
  59. // CHECK:STDERR: | ^
  60. // CHECK:STDERR:
  61. var x: Cpp.TwoTemplates(Cpp.A, true);
  62. // CHECK:STDOUT: --- valid.carbon
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: constants {
  65. // CHECK:STDOUT: %TwoTemplates: type = class_type @TwoTemplates [concrete]
  66. // CHECK:STDOUT: %pattern_type: type = pattern_type %TwoTemplates [concrete]
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT:
  69. // CHECK:STDOUT: imports {
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: file {
  73. // CHECK:STDOUT: name_binding_decl {
  74. // CHECK:STDOUT: %x.patt: %pattern_type = ref_binding_pattern x [concrete]
  75. // CHECK:STDOUT: %x.var_patt: %pattern_type = var_pattern %x.patt [concrete]
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %x.var: ref %TwoTemplates = var %x.var_patt [concrete]
  78. // CHECK:STDOUT: %x: ref %TwoTemplates = ref_binding x, %x.var [concrete = %x.var]
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: --- fail_template_mismatch.carbon
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: constants {
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: imports {
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: file {
  90. // CHECK:STDOUT: name_binding_decl {
  91. // CHECK:STDOUT: %x.patt: <error> = ref_binding_pattern x [concrete]
  92. // CHECK:STDOUT: %x.var_patt: <error> = var_pattern %x.patt [concrete]
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: %x.var: ref <error> = var %x.var_patt [concrete = <error>]
  95. // CHECK:STDOUT: %x: ref <error> = ref_binding x, <error> [concrete = <error>]
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: