Clang Project

clang_source_code/test/SemaCXX/int-ptr-cast-SFINAE.cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14
2// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++17
3
4void foo(int* a, int *b) {
5  a -= b; // expected-warning {{incompatible integer to pointer conversion assigning to 'int *' from}}
6}
7
8template<typename T> T declval();
9struct true_type { static const bool value = true; };
10struct false_type { static const bool value = false; };
11template<bool, typename T, typename U> struct select { using type = T; };
12template<typename T, typename U> struct select<false, T, U> { using type = U; };
13
14
15template<typename T>
16typename select<(sizeof(declval<T>() -= declval<T>(), 1) != 1), true_type, false_type>::type test(...);
17template<typename T> false_type test(...);
18
19template<typename T>
20static const auto has_minus_assign = decltype(test<T>())::value;
21
22static_assert(has_minus_assign<int*>, "failed"); // expected-error {{static_assert failed due to requirement 'has_minus_assign<int *>' "failed"}}
23