| 1 | // { dg-do run { target c++14 } } |
| 2 | |
| 3 | #include <experimental/propagate_const> |
| 4 | #include <testsuite_hooks.h> |
| 5 | |
| 6 | using std::experimental::propagate_const; |
| 7 | |
| 8 | void |
| 9 | test_base_conversion() |
| 10 | { |
| 11 | struct Base { }; |
| 12 | struct Derived : Base { }; |
| 13 | |
| 14 | static_assert(std::is_convertible<propagate_const<Derived*>, Base*>::value, |
| 15 | "PR libstdc++/107525 - SFINAE breaks conversion operators"); |
| 16 | static_assert(std::is_convertible<const propagate_const<Derived*>, const Base*>::value, |
| 17 | "PR libstdc++/107525 - SFINAE breaks conversion operators"); |
| 18 | } |
| 19 | |
| 20 | void |
| 21 | test_const_conversion() |
| 22 | { |
| 23 | struct X |
| 24 | { |
| 25 | int* p = nullptr; |
| 26 | |
| 27 | int& operator*() const { return *p; } |
| 28 | int* operator->() const { return p; } |
| 29 | int* get() const { return p; } |
| 30 | |
| 31 | operator int*() { return p; } |
| 32 | operator const int*() const = delete; |
| 33 | }; |
| 34 | |
| 35 | static_assert(!std::is_convertible<const X, const int*>::value, |
| 36 | "Cannot convert const X to const int*"); |
| 37 | // So should not be able to convert const propagate_const<X> to const int*. |
| 38 | static_assert(!std::is_convertible<const propagate_const<X>, const int*>::value, |
| 39 | "So should not be able to convert const propagate_const<X> to " |
| 40 | "const int* (although this is not what LFTSv3 says)"); |
| 41 | } |
| 42 | |
| 43 | int main() |
| 44 | { |
| 45 | test_base_conversion(); |
| 46 | test_const_conversion(); |
| 47 | } |