summaryrefslogtreecommitdiff
path: root/tests/functions/test_must_use.zc
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-14 23:59:54 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-14 23:59:54 +0000
commitdcfdc053cb5f9fb4d5eac0a2233c75126b7a8188 (patch)
treef34f30b382fa22d6fd0af46875a5b4b26d00feff /tests/functions/test_must_use.zc
parenta918df69269a39ef7350a645b5db025d66ecb18a (diff)
Added some of the tests.
Diffstat (limited to 'tests/functions/test_must_use.zc')
-rw-r--r--tests/functions/test_must_use.zc47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/functions/test_must_use.zc b/tests/functions/test_must_use.zc
new file mode 100644
index 0000000..a42b341
--- /dev/null
+++ b/tests/functions/test_must_use.zc
@@ -0,0 +1,47 @@
+include <stdio.h>
+
+@must_use
+fn compute() -> int {
+ return 42;
+}
+
+@deprecated("Use new_version instead")
+fn old_function() {
+ "deprecated!";
+}
+
+@inline
+fn fast_add(a: int, b: int) -> int {
+ return a + b;
+}
+
+@must_use @inline
+fn combined() -> int {
+ return 100;
+}
+
+fn optional_result() -> int {
+ return 1;
+}
+
+test "attributes" {
+ // This should NOT warn (result used)
+ var x = compute();
+ assert(x == 42, "compute() should return 42");
+
+ // This should NOT warn (no must_use attribute)
+ optional_result();
+
+ // This SHOULD warn (result discarded on must_use function)
+ compute();
+
+ // Test inline works
+ var sum = fast_add(1, 2);
+ assert(sum == 3, "inline add failed");
+
+ // Combined attributes
+ var c = combined();
+ assert(c == 100, "combined failed");
+
+ "Attributes test completed";
+}