-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++] Fix ambiguous constructors for std::complex and std::optional (
- Loading branch information
Showing
4 changed files
with
78 additions
and
6 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
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
38 changes: 38 additions & 0 deletions
38
libcxx/test/std/numerics/complex.number/complex.special/gh_101960_ambiguous_ctor.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,38 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <complex> | ||
|
||
// Regression test for https://github.com/llvm/llvm-project/issues/101960 where we used to | ||
// trigger an ambiguous constructor. | ||
|
||
#include <complex> | ||
#include <cassert> | ||
|
||
struct NastyConvertible { | ||
template <class T> | ||
operator T() const { | ||
return T(0); | ||
} | ||
}; | ||
|
||
template <class T> | ||
void test() { | ||
NastyConvertible nasty; | ||
std::complex<T> x(nasty, nasty); | ||
assert(x.real() == T(0)); | ||
assert(x.imag() == T(0)); | ||
} | ||
|
||
int main(int, char**) { | ||
test<float>(); | ||
test<double>(); | ||
test<long double>(); | ||
|
||
return 0; | ||
} |
28 changes: 28 additions & 0 deletions
28
...es/optional/optional.object/optional.object.ctor/gh_101960_internal_ctor.compile.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,28 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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++03, c++11, c++14 | ||
|
||
// <optional> | ||
|
||
// Regression test for https://github.com/llvm/llvm-project/issues/101960 where a constructor | ||
// of std::optional that should have been private was instead publicly available. | ||
|
||
#include <optional> | ||
#include <type_traits> | ||
|
||
struct NastyConvertible { | ||
template <class T> | ||
operator T() { | ||
return 0; | ||
} | ||
}; | ||
|
||
using F = int(int); | ||
|
||
static_assert(!std::is_constructible<std::optional<int>, NastyConvertible, int(int), int>::value); |