incomplete.carbon 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. // EXTRA-ARGS: --clang-arg=-fms-compatibility
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/interop/cpp/enum/incomplete.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/enum/incomplete.carbon
  13. // --- declaration.h
  14. // This is not valid in standard C++, but MSVC allows it as an extension, and so
  15. // Clang allows it in MSVC compatibility mode.
  16. enum UnsizedEnum;
  17. // --- import_declaration.carbon
  18. library "[[@TEST_NAME]]";
  19. // CHECK:STDERR: import_declaration.carbon:[[@LINE+5]]:10: in file included here [InCppInclude]
  20. // CHECK:STDERR: ./declaration.h:4:6: warning: forward references to 'enum' types are a Microsoft extension [CppInteropParseWarning]
  21. // CHECK:STDERR: 4 | enum UnsizedEnum;
  22. // CHECK:STDERR: | ^
  23. // CHECK:STDERR:
  24. import Cpp library "declaration.h";
  25. //@dump-sem-ir-begin
  26. fn F(e: Cpp.UnsizedEnum);
  27. //@dump-sem-ir-end
  28. // --- fail_use_declaration_as_definition.carbon
  29. library "[[@TEST_NAME]]";
  30. // CHECK:STDERR: fail_use_declaration_as_definition.carbon:[[@LINE+5]]:10: in file included here [InCppInclude]
  31. // CHECK:STDERR: ./declaration.h:4:6: warning: forward references to 'enum' types are a Microsoft extension [CppInteropParseWarning]
  32. // CHECK:STDERR: 4 | enum UnsizedEnum;
  33. // CHECK:STDERR: | ^
  34. // CHECK:STDERR:
  35. import Cpp library "declaration.h";
  36. fn MyF() {
  37. // TODO: It's a bit surprising to refer to this type as a class, even though
  38. // we model it as a class in Carbon. Consider customizing the diagnostic.
  39. // CHECK:STDERR: fail_use_declaration_as_definition.carbon:[[@LINE+8]]:10: error: binding pattern has incomplete type `UnsizedEnum` in name binding declaration [IncompleteTypeInBindingDecl]
  40. // CHECK:STDERR: var e: Cpp.UnsizedEnum;
  41. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  42. // CHECK:STDERR: fail_use_declaration_as_definition.carbon:[[@LINE-8]]:10: in file included here [InCppInclude]
  43. // CHECK:STDERR: ./declaration.h:4:6: note: class was forward declared here [ClassForwardDeclaredHere]
  44. // CHECK:STDERR: enum UnsizedEnum;
  45. // CHECK:STDERR: ^
  46. // CHECK:STDERR:
  47. var e: Cpp.UnsizedEnum;
  48. }
  49. // CHECK:STDOUT: --- import_declaration.carbon
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: constants {
  52. // CHECK:STDOUT: %UnsizedEnum: type = class_type @UnsizedEnum [concrete]
  53. // CHECK:STDOUT: %pattern_type: type = pattern_type %UnsizedEnum [concrete]
  54. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  55. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: imports {
  59. // CHECK:STDOUT: %Cpp: <namespace> = namespace file.%Cpp.import_cpp, [concrete] {
  60. // CHECK:STDOUT: .UnsizedEnum = %UnsizedEnum.decl
  61. // CHECK:STDOUT: import Cpp//...
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %UnsizedEnum.decl: type = class_decl @UnsizedEnum [concrete = constants.%UnsizedEnum] {} {}
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: file {
  67. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  68. // CHECK:STDOUT: %e.patt: %pattern_type = value_binding_pattern e [concrete]
  69. // CHECK:STDOUT: %e.param_patt: %pattern_type = value_param_pattern %e.patt, call_param0 [concrete]
  70. // CHECK:STDOUT: } {
  71. // CHECK:STDOUT: %e.param: %UnsizedEnum = value_param call_param0
  72. // CHECK:STDOUT: %.loc12: type = splice_block %UnsizedEnum.ref [concrete = constants.%UnsizedEnum] {
  73. // CHECK:STDOUT: %Cpp.ref: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
  74. // CHECK:STDOUT: %UnsizedEnum.ref: type = name_ref UnsizedEnum, imports.%UnsizedEnum.decl [concrete = constants.%UnsizedEnum]
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %e: %UnsizedEnum = value_binding e, %e.param
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: fn @F(%e.param: %UnsizedEnum);
  81. // CHECK:STDOUT: