-
Notifications
You must be signed in to change notification settings - Fork 47
Closed
Description
Snippet to reproduce:
// g++ -std=c++14 -o x x.cpp
#include "optional.hpp"
class A
{
};
// B is implicitly constructible from A.
class B
{
public:
B(A a)
{
}
};
// f accepts optional<B>.
void f(nonstd::optional<B> b)
{
}
// check conditions on https://en.cppreference.com/w/cpp/utility/optional/optional item 8
static_assert(std::is_constructible<B, A&&>::value, "");
static_assert(!std::is_same<std::decay_t<A&&>, nonstd::in_place_t>::value, "");
static_assert(!std::is_same<std::decay_t<A&&>, nonstd::optional<B>>::value, "");
int main()
{
A a;
f(a); // Call f with A, compile error.
}
This snippet fails to compile on gcc 5.4 in C++14 mode:
$ g++ -std=c++14 -o x x.cpp
x.cpp: In function ‘int main()’:
x.cpp:31:6: error: could not convert ‘a’ from ‘A’ to ‘nonstd::optional_lite::optional<B>’
f(a);
^
It works on gcc 8.2 in C++17 mode: https://godbolt.org/z/2XyZum
Metadata
Metadata
Assignees
Labels
No labels