11
22Last Updated 5 December 2025
33
4- This is a work in progress. Cake source is currently being used to validate the concepts.
4+ ## Cake Static Analysis
55
6-
7- ## Abstract
86
9- The objective is to statically check code and prevent bugs, including memory bugs like double free,
10- null dereference and memory leaks.
11-
12- Type-annotations have been created to extend the type system and insert information that defines contracts.
7+ Cake provides a set of annotations and extended qualifiers that are recognized by
8+ the static analyzer.
9+ With ownership qualifiers, it is possible to achieve the same or even stronger guarantees
10+ than those provided by C++ RAII. It also introduces the concept of nullable pointers,
11+ which helps express when a pointer may be null and prevents mistakes such as
12+ accidentally dereferencing a null pointer.
1313
14- These new type-annotations can be ignored, the language ** and existing code patterns** remains unmodified.
1514
1615## Concepts
1716
@@ -838,6 +837,8 @@ int main() {
838837
839838<button onclick =" Try (this )" >try</button >
840839
840+ Obs: [[ ctor]] in cake is similar of \_ Out in Microsoft SAL
841+
841842
842843** Sample - Using ` x_destroy ` to implement ` x_delete ` **
843844
@@ -856,7 +857,7 @@ void x_destroy( [[dtor]] struct X * x) {
856857
857858void x_delete(_ Opt struct X * _ Owner _ Opt p) {
858859 if (p) {
859- x_destroy(p)
860+ x_destroy(p);
860861
861862 /*
862863 contents of * p where moved
@@ -1395,7 +1396,7 @@ void list_append(struct list* list, struct node* _Owner node)
13951396<button onclick="Try(this)">try</button>
13961397
13971398
1398- ## Cake's static analysis limitations
1399+ ## Limitations
13991400
14001401While Cake tracks possible states, such as maybe-null, it does not track
14011402the origin or relationships between these states.
@@ -1450,7 +1451,12 @@ A header `safe.h` can define all cake extensions as empty macros.
14501451
14511452## References
14521453
1453- [1] https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references, https://learn.microsoft.com/en-us/dotnet/csharp/nullable-migration-strategies?source=recommendations
1454+ [1] https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references,
14541455
1456+ https://learn.microsoft.com/en-us/dotnet/csharp/nullable-migration-strategies?source=recommendations
14551457
14561458https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates
1459+
1460+ Microsoft SAL
1461+ https://learn.microsoft.com/en-us/cpp/code-quality/understanding-sal?view=msvc-170
1462+
0 commit comments