|
1 | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
2 | 2 | // RUN: %clang_cc1 -fsyntax-only -verify -fexperimental-new-constant-interpreter %s |
3 | | -// expected-no-diagnostics |
4 | 3 |
|
5 | 4 | void test_basic_type_checks() { |
6 | 5 | static_assert(__is_same(char, decltype(__builtin_bswapg((char)0))), ""); |
@@ -83,3 +82,79 @@ template struct ValueTemplateTypeTest<0x1234>; |
83 | 82 | template struct ValueTemplateTypeTest<0x12345678UL>; |
84 | 83 | template struct ValueTemplateTypeTest<(short)0x1234>; |
85 | 84 | template struct ValueTemplateTypeTest<(char)0x12>; |
| 85 | + |
| 86 | +template<typename T> |
| 87 | +void test_invalid_type() { |
| 88 | + __builtin_bswapg(T{}); // #invalid_type_use |
| 89 | +} |
| 90 | + |
| 91 | +void test_basic_errors() { |
| 92 | + test_invalid_type<float>(); |
| 93 | + // expected-note@-1 {{in instantiation of function template specialization 'test_invalid_type<float>' requested here}} |
| 94 | + // expected-error@#invalid_type_use {{1st argument must be a scalar integer type (was 'float')}} |
| 95 | + |
| 96 | + test_invalid_type<double>(); |
| 97 | + // expected-note@-1 {{in instantiation of function template specialization 'test_invalid_type<double>' requested here}} |
| 98 | + // expected-error@#invalid_type_use {{1st argument must be a scalar integer type (was 'double')}} |
| 99 | + |
| 100 | + test_invalid_type<void*>(); |
| 101 | + // expected-note@-1 {{in instantiation of function template specialization 'test_invalid_type<void *>' requested here}} |
| 102 | + // expected-error@#invalid_type_use {{1st argument must be a scalar integer type (was 'void *')}} |
| 103 | +} |
| 104 | + |
| 105 | +template<typename T> |
| 106 | +auto test_dependent_context(T value) -> decltype(__builtin_bswapg(value)) { // #dependent_use |
| 107 | + return __builtin_bswapg(value); |
| 108 | +} |
| 109 | + |
| 110 | +void test_dependent_errors() { |
| 111 | + test_dependent_context(1.0f); |
| 112 | + // expected-error@-1 {{no matching function for call to 'test_dependent_context'}} |
| 113 | + // expected-note@#dependent_use {{candidate template ignored: substitution failure [with T = float]: 1st argument must be a scalar integer type (was 'float')}} |
| 114 | + test_dependent_context(1.0l); |
| 115 | + // expected-error@-1 {{no matching function for call to 'test_dependent_context'}} |
| 116 | + // expected-note@#dependent_use {{candidate template ignored: substitution failure [with T = long double]: 1st argument must be a scalar integer type (was 'long double')}} |
| 117 | + test_dependent_context("hello"); |
| 118 | + // expected-error@-1 {{no matching function for call to 'test_dependent_context'}} |
| 119 | + // expected-note@#dependent_use {{candidate template ignored: substitution failure [with T = const char *]: 1st argument must be a scalar integer type (was 'const char *')}} |
| 120 | +} |
| 121 | + |
| 122 | +void test_lambda_errors() { |
| 123 | + auto lambda = [](auto x) { |
| 124 | + return __builtin_bswapg(x); // #lambda_use |
| 125 | + }; |
| 126 | + |
| 127 | + lambda(1.0f); |
| 128 | + // expected-error@#lambda_use {{1st argument must be a scalar integer type (was 'float')}} |
| 129 | + // expected-note@-2 {{in instantiation of function template specialization 'test_lambda_errors()::(anonymous class)::operator()<float>' requested here}} |
| 130 | + lambda(1.0l); |
| 131 | + // expected-error@#lambda_use {{1st argument must be a scalar integer type (was 'long double')}} |
| 132 | + // expected-note@-2 {{in instantiation of function template specialization 'test_lambda_errors()::(anonymous class)::operator()<long double>' requested here}} |
| 133 | + lambda("hello"); |
| 134 | + // expected-error@#lambda_use {{1st argument must be a scalar integer type (was 'const char *')}} |
| 135 | + // expected-note@-2 {{in instantiation of function template specialization 'test_lambda_errors()::(anonymous class)::operator()<const char *>' requested here}} |
| 136 | +} |
| 137 | + |
| 138 | +void test_argument_count_errors() { |
| 139 | + int h14 = __builtin_bswapg(1, 2); // expected-error {{too many arguments to function call, expected 1, have 2}} |
| 140 | +} |
| 141 | + |
| 142 | +void test_lvalue_reference(int& a) { |
| 143 | + auto result = __builtin_bswapg(a); |
| 144 | + static_assert(__is_same(int, decltype(result)), "Should decay reference to value type"); |
| 145 | +} |
| 146 | + |
| 147 | +void test_const_lvalue_reference(const int& a) { |
| 148 | + auto result = __builtin_bswapg(a); |
| 149 | + static_assert(__is_same(int, decltype(result)), "Should decay const reference to value type"); |
| 150 | +} |
| 151 | + |
| 152 | +void test_rvalue_reference(int&& a) { |
| 153 | + auto result = __builtin_bswapg(a); |
| 154 | + static_assert(__is_same(int, decltype(result)), "Should decay rvalue reference to value type"); |
| 155 | +} |
| 156 | + |
| 157 | +void test_const_rvalue_reference(const int&& a) { |
| 158 | + auto result = __builtin_bswapg(a); |
| 159 | + static_assert(__is_same(int, decltype(result)), "Should decay const rvalue reference to value type"); |
| 160 | +} |
0 commit comments