C++로 전환하고 사용자 정의 std::optional
솔루션을 표준 I/F로 바꾸면 clang 5의 예기치 않은 동작이 감지되었습니다. 어떤 이유로 인해 std::is_constructible
특성 클래스의 특성이 잘못 평가되어 emplace()
이 사용 중지되었습니다.clang 5 : std :: optional instantiation screws std :: is_constructible 특성 매개 변수 유형의 특성
#include <optional>
/// Precondition #1: T must be a nested struct
struct Foo
{
struct Victim
{
/// Precondition #2: T must have an aggregate-initializer
/// for one of its members
std::size_t value{0};
};
/// Precondition #3: std::optional<T> must be instantiated in this scope
std::optional<Victim> victim;
bool foo()
{
std::optional<Victim> foo;
// An error
foo.emplace();
/// Assertion is failed
static_assert(std::is_constructible<Victim>::value);
}
};
라이브 예를 전제 조건의 변경
godbolt.org과 예상대로 컴파일 : 그것은 재현하기 전에
일부 특정 전제 조건
을 만족해야합니다. 표준에서 불명확 한 불일치가 발생하여 준수하는 동안 clang이이 코드를 거부하게됩니까? 보조 노트로 : GCC 7.1 및 GCC 7.2은 위의 코드와 아무 문제가 있습니다.버그 보고서에 : bugs.llvm.org
컴파일러 버그 일 수 있습니다. –
@CrisLuengo, 표준보다 수정하기가 쉽기 때문에 가능합니다. – GreenScape
핵심은 귀하가 언어 변호사의 질문입니다. 그것은 그렇게 대답해야합니다. – StoryTeller