Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
WASM
Zig
Javascript
GIMPLE
Ygen
circle source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
Build 128
Build 129
Build 131
Latest
Options
Source code
#feature on safety #include <https://raw.githubusercontent.com/cppalliance/safe-cpp/master/libsafecxx/single-header/std2.h?token=$(date%20+%s)> using namespace std2; int main() safe { // Populate the vector with views with a nice mixture of lifetimes. vector<string_view> views { }; // string_view with /static lifetime. mut views.push_back("From a string literal"); // string_view with outer scope lifetime. string s1("From string object 1"); mut views.push_back(s1); { // string_view with inner scope lifetime. string s2("From string object 2"); mut views.push_back(s2); // s2 goes out of scope. views now holds dangling pointers into // out-of-scope data. } // Print the strings. s2 already fell out of scope, so this should // be a borrowck violation. `views` now contains objects that hold // dangling pointers. println("Printing from the outer scope:"); for(string_view sv : views) println(sv); }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
About the author
Statistics
Changelog
Version tree