-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow optional to tolerate being used with a nested class.
When Clang tries to complete a type containing `std::optional` it considers the `in_place_t` constructor with no arguments which checks if the value type is default constructible. If the value type is a nested class type, then this check occurs too early and poisons the is_default_constructible trait. This patch makes optional deduce `in_place_t` so we can prevent this early SFINAE evaluation. Technically this could break people doing weird things with the in_place_t tag, but that seems less important than making the nested class case work. llvm-svn: 355877
- Loading branch information
Showing
2 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
.../optional/optional.object/optional.object.ctor/empty_in_place_t_does_not_clobber.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++98, c++03, c++11, c++14 | ||
// <optional> | ||
|
||
// constexpr optional(in_place_t); | ||
|
||
// Test that the SFINAE "is_constructible<value_type>" isn't evaluated by the | ||
// in_place_t constructor with no arguments when the Clang is trying to check | ||
// copy constructor. | ||
|
||
#include <optional> | ||
#include <type_traits> | ||
#include <cassert> | ||
|
||
#include "test_macros.h" | ||
#include "archetypes.hpp" | ||
|
||
using std::optional; | ||
|
||
struct Wrapped { | ||
struct Inner { | ||
bool Dummy = true; | ||
}; | ||
std::optional<Inner> inner; | ||
}; | ||
|
||
int main(int, char**) { | ||
static_assert(std::is_default_constructible<Wrapped::Inner>::value, ""); | ||
Wrapped w; | ||
w.inner.emplace(); | ||
assert(w.inner.has_value()); | ||
|
||
return 0; | ||
} |