-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
experimental mode to ban unsafe use of C++ references (without unsafe…
… annotation) Currently implemented: ban all C++ references from subexpressions: An expression returning a reference must either be discarded or must be on the lhs of an Assignment (requiring a 'ref' type annotion if the reference is to be preserved instead of a copy). TODO: additional unsafe annotation for const:ref / mut:ref locals/members and mut:ref params.
- Loading branch information
Showing
6 changed files
with
219 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Test Output 1 | ||
# Test Output 2 | ||
# Test Output 3 | ||
# Test Output 123 | ||
|
||
# requires --_norefs | ||
|
||
class (Foo: | ||
a = [1, 2, 3] | ||
|
||
def (foo: | ||
#for (x in self.a: # static_assert this->a is_reference_v (same with self.a but self rewritten to this) | ||
#for (x in this->a: # same | ||
a = self.a | ||
for (x in a: | ||
std.cout << x # << std.endl # static_assert std.cout << x is_reference_v | ||
std.cout << "\n" | ||
) | ||
# unsafe:mut:auto:ref:ref in the future! | ||
b: mut:auto:ref:ref = self.a | ||
for (x in b: | ||
std.cout << x | ||
) | ||
) | ||
) | ||
|
||
def (main: | ||
f = Foo() | ||
f.foo() | ||
) |
46 changes: 46 additions & 0 deletions
46
tests/regression/ban_refs_for_loop.donotedit.autogenerated.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
#include <string> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <sstream> | ||
#include <functional> | ||
#include <cassert> | ||
#include <compare> // for <=> | ||
#include <thread> | ||
#include <optional> | ||
|
||
|
||
#include "ceto.h" | ||
//#include "ceto_private_boundscheck.donotedit.autogenerated.h" | ||
|
||
#include "ceto_private_listcomp.donotedit.autogenerated.h" | ||
; | ||
#include "ceto_private_boundscheck.donotedit.autogenerated.h" | ||
; | ||
#include "ceto_private_convenience.donotedit.autogenerated.h" | ||
; | ||
struct Foo : public ceto::shared_object, public std::enable_shared_from_this<Foo> { | ||
|
||
decltype(std::vector {{1, 2, 3}}) a = std::vector {{1, 2, 3}}; | ||
|
||
inline auto foo() const -> void { | ||
const auto a = (this -> a); | ||
for(const auto& x : a) { | ||
std::cout << x; | ||
std::cout << "\n"; | ||
} | ||
auto && b { (this -> a) } ; | ||
for(const auto& x : b) { | ||
std::cout << x; | ||
} | ||
} | ||
|
||
}; | ||
|
||
auto main() -> int { | ||
const auto f = std::make_shared<const Foo>(); | ||
(*ceto::mad(f)).foo(); | ||
} | ||
|