1 // RUN: %clang_cc1 -std=c++2a -emit-pch %s -o %t-cxx2a 2 // RUN: %clang_cc1 -std=c++2a -DUSE_PCH -include-pch %t-cxx2a %s -ast-print -verify | FileCheck %s 3 4 #ifndef USE_PCH 5 namespace inheriting_constructor { 6 struct S {}; 7 8 template<typename X, typename Y> struct T { 9 template<typename A> 10 explicit((Y{}, true)) T(A &&a) {} 11 }; 12 13 template<typename X, typename Y> struct U : T<X, Y> { 14 using T<X, Y>::T; 15 }; 16 17 U<S, char> foo(char ch) { 18 return U<S, char>(ch); 19 } 20 } 21 #else 22 namespace inheriting_constructor { 23 U<S, char> a = foo('0'); 24 } 25 26 //CHECK: explicit((char{} , true)) 27 28 #endif 29 30 namespace basic { 31 #ifndef USE_PCH 32 33 struct B {}; 34 35 struct A { 36 explicit A(int); 37 explicit(false) operator bool(); 38 explicit(true) operator B(); 39 }; 40 #else 41 //expected-note@-6+ {{candidate constructor}} 42 //expected-note@-9+ {{candidate constructor}} 43 //expected-note@-6+ {{candidate function}} 44 45 //CHECK: explicit{{ +}}A( 46 //CHECK-NEXT: explicit(false){{ +}}operator 47 //CHECK-NEXT: explicit(true){{ +}}operator 48 A a = 0; //expected-error {{no viable conversion}} 49 A a1(0); 50 51 bool b = a1; 52 B b1 = a1; //expected-error {{no viable conversion}} 53 54 #endif 55 } 56 57 58 namespace templ { 59 #ifndef USE_PCH 60 61 template<bool b> 62 struct B { 63 static constexpr bool value = b; 64 }; 65 66 template<bool b> 67 struct A { 68 explicit(b) A(B<b>) {} 69 template<typename T> 70 explicit(b ^ T::value) operator T(); 71 }; 72 B<true> b_true; 73 B<false> b_false; 74 #else 75 //expected-note@-8 {{candidate template ignored}} 76 //expected-note@-8+ {{explicit constructor}} 77 //expected-note@-15+ {{candidate constructor}} 78 //expected-note@-8+ {{candidate conversion operator ignored}} 79 //expected-note@-9+ {{explicit(bool) specifier resolved to true}} 80 //expected-note@-12 {{explicit(bool) specifier resolved to true}} 81 //expected-note@-13+ {{candidate deductiong guide ignored}} 82 83 //CHECK: explicit(b){{ +}}A 84 //CHECK: explicit(b{{ +}}^{{ +}}T::value){{ +}}operator 85 86 A a = { b_true }; //expected-error {{class template argument deduction}} 87 A a0 = b_true; //expected-error {{no viable constructor or deduction guide}} 88 A a_true(b_true); 89 A a_false = b_false; 90 91 B<true> b = a_true; 92 B<true> b1 = a_false; //expected-error {{no viable conversion}} 93 B<false> b2(a_true); 94 95 #endif 96 97 } 98 99 namespace guide { 100 101 #ifndef USE_PCH 102 103 template<typename T> 104 struct A { 105 A(T); 106 }; 107 108 template<typename T> 109 explicit(true) A(T) -> A<T>; 110 111 explicit(false) A(int) -> A<int>; 112 113 #else 114 //expected-note@-5 {{explicit deduction guide}} 115 116 //CHECK: explicit(true){{ +}}A( 117 //CHECK: explicit(false){{ +}}A( 118 119 A a = { 0.0 }; //expected-error {{explicit deduction guide}} 120 A a1 = { 0 }; 121 122 #endif 123 124 } 125