Discussion about this post

User's avatar
Dan's avatar

"This post presents a lot of code as screenshots."

Does substack not provide a way to include fixed with code blocks at all? If the only limitation is not supporting syntax highlighting I'd probably give it up to be more accessible.

Expand full comment
Paul Fultz II's avatar

Cppcheck already warns for this code:

test.cpp:16:45: error: Using object that is a temporary. [danglingTemporaryLifetime]

assert((std::vector<int>{1, 2, 3, 4} == append34({1, 2}))); // FAIL: UB

^

test.cpp:3:12: note: Return lambda.

return [&](std::vector<int>&& items) {

^

test.cpp:2:50: note: Passed to reference.

auto make_appender(std::vector<int> const& suffix) {

^

test.cpp:4:36: note: Lambda captures variable by reference here.

return append(move(items), suffix);

^

test.cpp:15:35: note: Passed to 'make_appender'.

auto append34 = make_appender({3, 4});

^

test.cpp:15:35: note: Temporary created here.

auto append34 = make_appender({3, 4});

^

test.cpp:16:45: note: Using object that is a temporary.

assert((std::vector<int>{1, 2, 3, 4} == append34({1, 2}))); // FAIL: UB

Expand full comment
6 more comments...

No posts