test a reference as a lvalue

master
neingeist 11 years ago
parent 9b2aef1701
commit b987b2badd

1
.gitignore vendored

@ -15,3 +15,4 @@ object-lifetime
shared_ptr
casts
classes
lvalues

@ -15,3 +15,4 @@ add_executable(object-lifetime object-lifetime.cpp)
add_executable(shared_ptr shared_ptr.cpp)
add_executable(casts casts.cpp)
add_executable(classes classes.cpp)
add_executable(lvalues lvalues.cpp)

@ -0,0 +1,31 @@
#include <cassert>
int test = 12;
int fnord_(const int i) {
test += i;
return test;
}
int& fnord(const int i) {
test += i;
return test;
}
int main() {
test = 13;
fnord_(5);
assert(test == 18);
// LOLNOPE:
// fnord_(5)++;
test = 13;
fnord(5);
assert(test == 18);
fnord(5)++;
assert(test == 24);
}
Loading…
Cancel
Save