1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <complex>
10
11// Regression test for https://github.com/llvm/llvm-project/issues/101960 where we used to
12// trigger an ambiguous constructor.
13
14#include <complex>
15#include <cassert>
16
17struct NastyConvertible {
18 template <class T>
19 operator T() const {
20 return T(0);
21 }
22};
23
24template <class T>
25void test() {
26 NastyConvertible nasty;
27 std::complex<T> x(nasty, nasty);
28 assert(x.real() == T(0));
29 assert(x.imag() == T(0));
30}
31
32int main(int, char**) {
33 test<float>();
34 test<double>();
35 test<long double>();
36
37 return 0;
38}
39

source code of libcxx/test/std/numerics/complex.number/complex.special/gh_101960_ambiguous_ctor.pass.cpp