Lightning Talk: Const Mayhem in C++ - Ofek Shilon - CppCon 2022

preview_player
Показать описание
---

Lightning Talk: Const Mayhem in Cpp - Ofek Shilon - CppCon 2022

"Did you know that:
(1) const methods can legally modify members?
(2) A const object cannot be default-initialized? (this makes sense after a minute)
(2)(b) Unless... a default constructor is declared non-inline?
(3) The standard does not properly account for volatile members of const objects?
All this and (probably not much) more, at this lightning talk."
---

Ofek Shilon
__

#cppcon #programming #cpp
Рекомендации по теме
Комментарии
Автор

5:43
The thing is that int* m_p in context of constMethod() is a "const pointer" not a "pointer to const". So we can't change its value (the address) while we can dereference (and change the value pointed to).

genx
Автор

Very good talk. People interested in this topic might be interested in the existence of which is a smart pointer that can’t modify its pointed-to memory when it’s in const context. Part of the “library fundamentals TS v2”

Roibarkan
Автор

Were the "slides" out of sync? Also is the talk available somewhere else, I would love to hear the complete version.

User-cvee
Автор

5:40 but shouldn't that constness of the variable turn the int into a const int and then it would trigger at least a warning about making a mutable pointer from a const variable?

Raspredval
Автор

Why does the standard allow this? It seems like a purely harmful UB case. I guess it should be detected by the compiler and result in an error.

ohwow
join shbcf.ru