Closed nickolaym closed 1 year ago
The problem is that just including <string>
in test framework makes the compile time 20x worse, its that bad a header. I don't want to add any specific support for std::string
because of that.
The problem is not with std::string only.
Your code works with dangling values.
My example PureString may be rewritten with pure C strings:
struct PureString {
char* s_;
PureString(const char* s) : s_(strdup(s)) {}
PureString(const PureString& ps) : s_(strdup(ps.s_)) {}
~PureString() { memset(s_, '#', strlen(s_)); free(s_); }
const char* c_str() const { return s_; }
};
In C++, it is easy to fix it: just use lambda. In pure C, it is easy, too: just write an inline function.
Illustration: https://gcc.godbolt.org/z/zE5oeqWvh
Consider such code
It causes warning (which should be treated as error!)
But passes.
Moreover,
causes no warnings at all. And it fails.