brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · c7cd2c5 Raw
132 lines · cpp
1// RUN: %clang_cc1 -std=c++2a -include %s %s -ast-print -verify | FileCheck %s2//3// RUN: %clang_cc1 -std=c++2a -emit-pch %s -o %t-cxx2a4// RUN: %clang_cc1 -std=c++2a -include-pch %t-cxx2a %s -ast-print -verify | FileCheck %s5 6// RUN: %clang_cc1 -std=c++2a -emit-pch -fpch-instantiate-templates %s -o %t-cxx2a7// RUN: %clang_cc1 -std=c++2a -include-pch %t-cxx2a %s -ast-print -verify | FileCheck %s8 9#ifndef USE_PCH10namespace inheriting_constructor {11  struct S {};12 13  template<typename X, typename Y> struct T {14    template<typename A>15    explicit(((void)Y{}, true)) T(A &&a) {}16  };17 18  template<typename X, typename Y> struct U : T<X, Y> {19    using T<X, Y>::T;20  };21 22  U<S, char> foo(char ch) {23    return U<S, char>(ch);24  }25}26#else27namespace inheriting_constructor {28U<S, char> a = foo('0');29}30 31//CHECK: explicit(((void)char{} , true))32 33#endif34 35namespace basic {36#ifndef USE_PCH37 38struct B {};39 40struct A {41  explicit A(int);42  explicit(false) operator bool();43  explicit(true) operator B();44};45#else46//expected-note@-6+ {{candidate constructor}}47//expected-note@-9+ {{candidate constructor}}48//expected-note-re@-7+ {{explicit constructor is not a candidate{{$}}}}49//expected-note@-7+ {{candidate function}}50//expected-note@-7+ {{explicit conversion function is not a candidate (explicit specifier evaluates to true)}}51 52//CHECK: explicit{{ +}}A(53//CHECK-NEXT: explicit(false){{ +}}operator54//CHECK-NEXT: explicit(true){{ +}}operator55A a = 0; //expected-error {{no viable conversion}}56A a1(0);57 58bool b = a1;59B b1 = a1; //expected-error {{no viable conversion}}60 61#endif62}63 64 65namespace templ {66#ifndef USE_PCH67 68template<bool b>69struct B {70  static constexpr bool value = b;71};72 73template<bool b>74struct A {75  explicit(b) A(B<b>) {}76  template<typename T>77  explicit(b ^ T::value) operator T();78};79B<true> b_true;80B<false> b_false;81#else82//expected-note@-8 {{candidate template ignored}} expected-note@-8 {{implicit deduction guide declared as 'template <bool b> A(templ::A<b>) -> templ::A<b>'}}83//expected-note@-8 {{explicit constructor declared here}} expected-note@-8 {{implicit deduction guide declared as 'template <bool b> explicit(b) A(B<b>) -> templ::A<b>'}}84//expected-note@-15+ {{candidate constructor}}85//expected-note@-8+ {{explicit conversion function is not a candidate (explicit specifier}}86//expected-note@-11 {{explicit constructor is not a candidate (explicit specifier}}87 88//CHECK: explicit(b){{ +}}A89//CHECK: explicit(b{{ +}}^{{ +}}T::value){{ +}}operator90 91A a = { b_true }; //expected-error {{class template argument deduction}}92A a0 = b_true; //expected-error {{no viable constructor or deduction guide}}93A a_true(b_true);94A a_false = b_false;95 96B<true> b = a_true;97B<true> b1 = a_false; //expected-error {{no viable conversion}}98B<false> b2(a_true);99 100#endif101 102}103 104namespace guide {105 106#ifndef USE_PCH107 108template<typename T>109struct A {110  A(T);111};112 113template<typename T>114explicit(true) A(T) -> A<T>;115 116explicit(false) A(int) -> A<int>;117 118#else119//expected-note@-5 {{explicit deduction guide}}120 121//CHECK: explicit(true){{ +}}A(122//CHECK: explicit(false){{ +}}A(123 124A a = { 0.0 }; //expected-error {{explicit deduction guide}}125A a1 = { 0 };126 127#endif128 129}130 131#define USE_PCH132