unused_internal.carbon 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/int.carbon
  6. // EXTRA-ARGS: --clang-arg=-Wunused
  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/basics/unused_internal.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/unused_internal.carbon
  13. // --- unused.carbon
  14. library "[[@TEST_NAME]]";
  15. import Cpp inline '''c++
  16. // CHECK:STDERR: unused.carbon:[[@LINE+4]]:12: warning: unused variable 'n' [CppInteropParseWarning]
  17. // CHECK:STDERR: 9 | static int n = 0;
  18. // CHECK:STDERR: | ^
  19. // CHECK:STDERR:
  20. static int n = 0;
  21. // CHECK:STDERR: unused.carbon:[[@LINE+4]]:13: warning: unused function 'f' [CppInteropParseWarning]
  22. // CHECK:STDERR: 14 | static void f() {}
  23. // CHECK:STDERR: | ^
  24. // CHECK:STDERR:
  25. static void f() {}
  26. ''';
  27. // --- not_unused.carbon
  28. library "[[@TEST_NAME]]";
  29. import Cpp inline '''c++
  30. static int n = 0;
  31. static void f() {}
  32. ''';
  33. fn F() -> i32 {
  34. Cpp.f();
  35. return Cpp.n;
  36. }