| 1 |
// PR c++/47950 |
| 2 |
|
| 3 |
template <typename T> struct empty |
| 4 |
{ |
| 5 |
// allow success case to build (not relevant to bug) |
| 6 |
operator bool() { return true; } |
| 7 |
}; |
| 8 |
|
| 9 |
template <typename T> struct from_int |
| 10 |
{ |
| 11 |
from_int(int) {} |
| 12 |
|
| 13 |
// allow success case to build (not relevant to bug) |
| 14 |
operator bool() { return true; } |
| 15 |
}; |
| 16 |
|
| 17 |
template <typename T> |
| 18 |
from_int<T> via_function(T v) |
| 19 |
{ |
| 20 |
return from_int<T>(v); |
| 21 |
} |
| 22 |
|
| 23 |
template <typename T> |
| 24 |
void f() |
| 25 |
{ |
| 26 |
// ********* this section compiles *********** |
| 27 |
|
| 28 |
// these plain initializers work fine |
| 29 |
from_int<int> a = 7; |
| 30 |
from_int<int> b = from_int<int>(7); |
| 31 |
empty<int> c = empty<int>(); |
| 32 |
from_int<T> ta = 7; |
| 33 |
from_int<T> tb = from_int<T>(7); |
| 34 |
empty<T> tc = empty<T>(); |
| 35 |
|
| 36 |
// these dependent condition decls work fine |
| 37 |
if (empty<T> x = empty<T>()) |
| 38 |
; |
| 39 |
if (from_int<T> x = 7) |
| 40 |
; |
| 41 |
if (from_int<T> x = from_int<T>(7)) |
| 42 |
; |
| 43 |
if (from_int<T> x = via_function(T())) |
| 44 |
; |
| 45 |
|
| 46 |
// this non-dependent condition decl using conversion works fine |
| 47 |
if (from_int<int> x = 7) |
| 48 |
; |
| 49 |
|
| 50 |
// these non-dependent condition decls using conversion or braced- |
| 51 |
// initialization work fine (in c++0x mode only course) |
| 52 |
#if __GXX_EXPERIMENTAL_CXX0X__ |
| 53 |
if (empty<int> x {}) |
| 54 |
; |
| 55 |
if (from_int<int> x {7}) |
| 56 |
; |
| 57 |
#endif |
| 58 |
|
| 59 |
// ********** this section fails in C++0x *********** |
| 60 |
|
| 61 |
// the following non-dependent condition decls cause an assertion |
| 62 |
// failure in |
| 63 |
// |
| 64 |
// tsubst_copy_and_build, at cp/pt.c:13370 |
| 65 |
// |
| 66 |
// in C++0x mode |
| 67 |
// |
| 68 |
if (empty<int> x = empty<int>()) |
| 69 |
; |
| 70 |
if (from_int<int> x = from_int<int>(7)) |
| 71 |
; |
| 72 |
if (from_int<int> x = via_function(7)) |
| 73 |
; |
| 74 |
} |
| 75 |
|
| 76 |
int main() |
| 77 |
{ |
| 78 |
f<int>(); |
| 79 |
} |