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 const int% f1(const int% x, const int% y, bool pred) safe { // The return reference is constrained by all reference parameters: x and y. return pred ? x : y; } struct Obj { const int% f2(const int% arg) const % safe { // Non-static member functions are constrained by the implicit // object lifetime. // It's OK to return `x`, because self outlives the return. return %x; } const int% f3(const int% arg) const % safe { // Error: arg does not outlive the return reference. return arg; } const int% f4(const self%, const int% arg) safe { // OK - f4 is a free function with an explicit self parameter. return arg; } int x; }; int main() { int x = 1, y = 2; f1(x, y, true); // OK Obj obj { }; obj.f2(x); // OK obj.f3(x); // Error obj.f4(x); // OK. }
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