1 // RUN: %clang_cc1 %s -fopenacc -verify 2 3 struct NotConvertible{} NC; 4 struct Incomplete *SomeIncomplete; // #INCOMPLETE 5 enum E{} SomeE; 6 enum class E2{} SomeE2; 7 8 struct CorrectConvert { 9 operator int(); 10 } Convert; 11 12 struct ExplicitConvertOnly { 13 explicit operator int() const; // #EXPL_CONV 14 } Explicit; 15 16 struct AmbiguousConvert{ 17 operator int(); // #AMBIG_INT 18 operator short(); // #AMBIG_SHORT 19 operator float(); 20 } Ambiguous; 21 22 void Test() { 23 #pragma acc parallel num_workers(1) 24 while(1); 25 #pragma acc kernels num_workers(1) 26 while(1); 27 28 // expected-error@+1{{OpenACC clause 'num_workers' requires expression of integer type ('struct NotConvertible' invalid}} 29 #pragma acc parallel num_workers(NC) 30 while(1); 31 32 // expected-error@+2{{OpenACC integer expression has incomplete class type 'struct Incomplete'}} 33 // expected-note@#INCOMPLETE{{forward declaration of 'Incomplete'}} 34 #pragma acc kernels num_workers(*SomeIncomplete) 35 while(1); 36 37 #pragma acc parallel num_workers(SomeE) 38 while(1); 39 40 // expected-error@+1{{OpenACC clause 'num_workers' requires expression of integer type ('enum E2' invalid}} 41 #pragma acc kernels num_workers(SomeE2) 42 while(1); 43 44 #pragma acc parallel num_workers(Convert) 45 while(1); 46 47 // expected-error@+2{{OpenACC integer expression requires explicit conversion from 'struct ExplicitConvertOnly' to 'int'}} 48 // expected-note@#EXPL_CONV{{conversion to integral type 'int'}} 49 #pragma acc kernels num_workers(Explicit) 50 while(1); 51 52 // expected-error@+3{{multiple conversions from expression type 'struct AmbiguousConvert' to an integral type}} 53 // expected-note@#AMBIG_INT{{conversion to integral type 'int'}} 54 // expected-note@#AMBIG_SHORT{{conversion to integral type 'short'}} 55 #pragma acc parallel num_workers(Ambiguous) 56 while(1); 57 } 58 59 struct HasInt { 60 using IntTy = int; 61 using ShortTy = short; 62 static constexpr int value = 1; 63 static constexpr AmbiguousConvert ACValue; 64 static constexpr ExplicitConvertOnly EXValue; 65 66 operator char(); 67 }; 68 69 template<typename T> 70 void TestInst() { 71 72 // expected-error@+1{{no member named 'Invalid' in 'HasInt'}} 73 #pragma acc parallel num_workers(HasInt::Invalid) 74 while (1); 75 76 // expected-error@+2{{no member named 'Invalid' in 'HasInt'}} 77 // expected-note@#INST{{in instantiation of function template specialization 'TestInst<HasInt>' requested here}} 78 #pragma acc kernels num_workers(T::Invalid) 79 while (1); 80 81 // expected-error@+3{{multiple conversions from expression type 'const AmbiguousConvert' to an integral type}} 82 // expected-note@#AMBIG_INT{{conversion to integral type 'int'}} 83 // expected-note@#AMBIG_SHORT{{conversion to integral type 'short'}} 84 #pragma acc parallel num_workers(HasInt::ACValue) 85 while (1); 86 87 // expected-error@+3{{multiple conversions from expression type 'const AmbiguousConvert' to an integral type}} 88 // expected-note@#AMBIG_INT{{conversion to integral type 'int'}} 89 // expected-note@#AMBIG_SHORT{{conversion to integral type 'short'}} 90 #pragma acc kernels num_workers(T::ACValue) 91 while (1); 92 93 // expected-error@+2{{OpenACC integer expression requires explicit conversion from 'const ExplicitConvertOnly' to 'int'}} 94 // expected-note@#EXPL_CONV{{conversion to integral type 'int'}} 95 #pragma acc parallel num_workers(HasInt::EXValue) 96 while (1); 97 98 // expected-error@+2{{OpenACC integer expression requires explicit conversion from 'const ExplicitConvertOnly' to 'int'}} 99 // expected-note@#EXPL_CONV{{conversion to integral type 'int'}} 100 #pragma acc kernels num_workers(T::EXValue) 101 while (1); 102 103 #pragma acc parallel num_workers(HasInt::value) 104 while (1); 105 106 #pragma acc kernels num_workers(T::value) 107 while (1); 108 109 #pragma acc parallel num_workers(HasInt::IntTy{}) 110 while (1); 111 112 #pragma acc kernels num_workers(typename T::ShortTy{}) 113 while (1); 114 115 #pragma acc parallel num_workers(HasInt::IntTy{}) 116 while (1); 117 118 #pragma acc kernels num_workers(typename T::ShortTy{}) 119 while (1); 120 121 HasInt HI{}; 122 T MyT{}; 123 124 #pragma acc parallel num_workers(HI) 125 while (1); 126 127 #pragma acc kernels num_workers(MyT) 128 while (1); 129 } 130 131 void Inst() { 132 TestInst<HasInt>(); // #INST 133 } 134