| 1 |
// { dg-do compile { target c++11 } } |
| 2 |
// { dg-options "-Wignored-qualifiers" } |
| 3 |
// c++/80544 cast expressions returned cv-qualified prvalues |
| 4 |
|
| 5 |
template<typename T> void f(T&&) { } |
| 6 |
template<typename T> void f(T const&&) = delete; |
| 7 |
|
| 8 |
template<typename T> void g(T&&) = delete; |
| 9 |
template<typename T> void g(T const&&) { } |
| 10 |
|
| 11 |
struct B { int i; const char c; } b = {}; |
| 12 |
|
| 13 |
void f1() |
| 14 |
{ |
| 15 |
int i = 0; |
| 16 |
f((long const)i); // { dg-warning "5:type qualifiers ignored" } |
| 17 |
f((int* const)&i); // { dg-warning "5:type qualifiers ignored" } |
| 18 |
f((int const* const)&i); // { dg-warning "5:type qualifiers ignored" } |
| 19 |
f((long* const)&i); // { dg-warning "5:type qualifiers ignored" } |
| 20 |
|
| 21 |
f(static_cast<long const>(i)); // { dg-warning "5:type qualifiers ignored" } |
| 22 |
f(reinterpret_cast<long const>(&i)); // { dg-warning "5:type qualifiers ignored" } |
| 23 |
|
| 24 |
f(static_cast<int* const>(&i)); // { dg-warning "5:type qualifiers ignored" } |
| 25 |
f(const_cast<int* const>(&i)); // { dg-warning "5:type qualifiers ignored" } |
| 26 |
f(reinterpret_cast<long* const>(&i)); // { dg-warning "5:type qualifiers ignored" } |
| 27 |
|
| 28 |
using ptrmem = int B::*; |
| 29 |
f(static_cast<ptrmem const>(&B::i)); // { dg-warning "5:type qualifiers ignored" } |
| 30 |
f(const_cast<ptrmem const>(&B::i)); // { dg-warning "5:type qualifiers ignored" } |
| 31 |
f(reinterpret_cast<ptrmem const>(&B::i)); // { dg-warning "5:type qualifiers ignored" } |
| 32 |
|
| 33 |
// No warnings, not a cv-qualified type: |
| 34 |
using ptrmem2 = const char B::*; |
| 35 |
f(static_cast<ptrmem2>(&B::c)); |
| 36 |
f(const_cast<ptrmem2>(&B::c)); |
| 37 |
f(reinterpret_cast<ptrmem2>(&B::c)); |
| 38 |
|
| 39 |
// prvalue of class type can have cv-quals: |
| 40 |
g(static_cast<const B>(b)); |
| 41 |
} |