Closed
Description
It will complain in code like
#include <optional>
#include <string>
class FontInfo
{
public:
FontInfo() = default;
const std::optional<std::string> &getName() const { return name; };
private:
std::optional<std::string> name;
};
int main(int argc, char **)
{
FontInfo fi;
printf("HAS NAME %s\n", fi.getName() ? fi.getName()->c_str() : "[none]");
}
because it has the rule that consecutive calls to the same function might return different values, but that's simply not possible given how the two getName calls are one after the other and they are just returning a const & to a member in a const method, no?