Clang doesn't have work with std :: experimental :: optional

It seems that clang is not working properly with std::experimental::optional.
Consider the following example:

#include <experimental/optional>
#include <iostream>

struct Foo { int bar; };

int main() {
    Foo foo;
    std::experimental::optional<Foo> opt = foo;
    opt.value().bar = 42;
    std::cout << opt.value().bar << std::endl;
}

It compiles fine with g ++ version 5.3.1, but it is not associated with either clang version 7.0.0 or clang version 7.0.2.
Error returned:

Undefined symbols for architecture x86_64:
"std::experimental::bad_optional_access::~bad_optional_access()", referenced from:
    _main in main-11b2dd.o
"typeinfo for std::experimental::bad_optional_access", referenced from:
    _main in main-11b2dd.o
"vtable for std::experimental::bad_optional_access", referenced from:
    std::experimental::bad_optional_access::bad_optional_access() in main-11b2dd.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I could not find the problem open in the error report for clang.
Who is behaving right? I think g ++ works fine, and clang seems to be listening. I'm wrong?

EDIT1

Actually, the error seems to be related to the definition bad_optional_access, although the problem occurs when using clang.

EDIT2

, -std=c++14.
, clang osx, ( optional ), value.
, :

opt->bar

:

opt.value().bar
+4
2

, opt.value() , , . , , , :

- undefined. . -, , ( logic_error),

, value() :

constexpr T const& optional<T>::value() const;
T& optional<T>::value();

:

*val, bool(*this).

:

bad_optional_access, !*this.

:

constexpr.

value:

constexpr T const& value()
{
    return *this ? storage_.value_ : (throw bad_optional_access(""), storage_.value_);
}

opt , , undefined.

, clang Wandbox ( ).

, , , , .

, github, .

+2

TL; :

@Petesh ( Clang 4.0.0, OSX), (= default) ... /experimental/optional: std::experimental::bad_optional_access::~bad_optional_access‌​() _NOEXCEPT = default;.

:

@Shafik , (void)0 , . 0 , , . ( , (dis) , , , , .)

(void)0, _LIBCPP_ASSERT - _LIBCPP_DEBUG_LEVEL 1, _LIBCPP_ASSERT ((x) ? (void)0 : (_VSTD::fprintf(stderr, "%s\n", m), _VSTD::abort())), .

, lib++ docs, _LIBCPP_DEBUG_LEVEL - , ". , , .: (

0

Source: https://habr.com/ru/post/1619226/


All Articles