This code gets rejected:
const std::optional<int> opt{5};
std::optional<volatile int> opt2 = opt;
But this is accepted:
const std::optional<int> opt{5};
std::optional<const int> opt2 = opt;
What is going on here?
In file included from /tmp/a.cpp:1: /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/optional:627:4: error: no matching function for call to 'operator new' ::new ^~ /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/optional:1140:10: note: in instantiation of function template specialization 'std::_Optional_base_impl >::_M_construct' requested here this->_M_construct(std::forward(__args)...); ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/optional:1002:4: note: in instantiation of function template specialization 'std::optional::emplace' requested here emplace(*__t); ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/new:134:7: note: candidate function not viable: no known conversion from 'volatile int *' to 'const std::nothrow_t' for 2nd argument void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/new:143:7: note: candidate function not viable: no known conversion from 'volatile int *' to 'std::align_val_t' for 2nd argument void* operator new(std::size_t, std::align_val_t) ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/new:168:14: note: candidate function not viable: no known conversion from 'volatile int *' to 'void *' for 2nd argument inline void* operator new(std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/new:120:7: note: candidate function not viable: requires 1 argument, but 2 were provided void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc) ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/new:145:7: note: candidate function not viable: requires 3 arguments, but 2 were provided void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&) ^ 1 error generated.