| 1 |
// { dg-do assemble } |
| 2 |
// g++ 1.37.1 bug 900519_03 |
| 3 |
|
| 4 |
// The C++ Reference Manual says (in section 8.4.3) "A reference to a |
| 5 |
// volatile T can be initialized with a volatile T or a plain T but not a |
| 6 |
// const T. A reference to a const T can be initialized with a const T or |
| 7 |
// a plain T or something that can be converted into a plain T, but not a |
| 8 |
// volatile T." |
| 9 |
|
| 10 |
// g++ fails to disgnose such errors in most cases. |
| 11 |
|
| 12 |
// keywords: references, initialization, type qualifiers |
| 13 |
|
| 14 |
extern const int cint_obj; |
| 15 |
extern volatile int vint_obj; |
| 16 |
|
| 17 |
void take_cint_ref (const int& arg) { } // { dg-message "" } |
| 18 |
void take_vint_ref (volatile int& arg) { } // { dg-message "" } |
| 19 |
|
| 20 |
const int& global_cint_ref2 = vint_obj; // { dg-error "" } |
| 21 |
|
| 22 |
volatile int& global_vint_ref1 = cint_obj; // { dg-error "" } |
| 23 |
|
| 24 |
extern const int& extern_cint_ref; |
| 25 |
extern volatile int& extern_vint_ref; |
| 26 |
|
| 27 |
void test_0 () |
| 28 |
{ |
| 29 |
const int& local_cint_ref2 = vint_obj; // { dg-error "" } |
| 30 |
|
| 31 |
volatile int& local_vint_ref1 = cint_obj; // { dg-error "" } |
| 32 |
} |
| 33 |
|
| 34 |
void test_1 () |
| 35 |
{ |
| 36 |
take_cint_ref (vint_obj); // { dg-error "" } |
| 37 |
|
| 38 |
take_vint_ref (cint_obj); // { dg-error "" } caught |
| 39 |
} |
| 40 |
|
| 41 |
void test_2 () |
| 42 |
{ |
| 43 |
take_cint_ref (extern_vint_ref); // { dg-error "" } |
| 44 |
|
| 45 |
take_vint_ref (extern_cint_ref); // { dg-error "" } |
| 46 |
} |
| 47 |
|
| 48 |
int main () { return 0; } |