Skip to content

Using value_or() changes stored value #60

@deadem

Description

@deadem

Code:

#include <https://raw.githubusercontent.com/martinmoene/optional-lite/master/include/nonstd/optional.hpp>
#include <iostream>
#include <string>

int main()
{
    nonstd::optional<std::string> s;
    s = "test";
    std::cout << (*s == "test") << std::endl;
    std::cout << (s.value_or("") == "test") << std::endl; // comment this line
    std::cout << (s->empty()) <<  std::endl;
}

Output:
1
1
1

Expected output:
1
1
0

If I comment line with value_or it works just fine. GCC version also works as expected, but clang and msvc does not.

Live code: https://godbolt.org/z/frqjfr

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