Skip to content

Incorrect __attribute__((pure)) in effectful functions #72

@joom

Description

@joom

See

__attribute__((pure)) std::string iotest::test4() {
std::cout << "what is your name?"s << '\n';
std::string s2 = []() -> std::string {
std::string s;
std::getline(std::cin, s);
return s;
}();
std::cout << "hello "s + s2 << '\n';
return "I read the name "s + s2 + " from the command line!"s;
}
__attribute__((pure)) void iotest::test5() {
std::string s = []() -> std::string {
std::ifstream file("file.txt"s);
if (!file) {
std::cerr << "Failed to open file " << "file.txt"s << '\n';
return std::string{};
}
return std::string(std::istreambuf_iterator<char>(file),
std::istreambuf_iterator<char>());
}();
std::cout << s << '\n';
return;
}

These functions should not have __attribute__((pure)), as they have side effects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions