diff options
Diffstat (limited to 'meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0234-PR-c-48911.patch')
-rw-r--r-- | meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0234-PR-c-48911.patch | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0234-PR-c-48911.patch b/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0234-PR-c-48911.patch new file mode 100644 index 0000000000..24270d4efc --- /dev/null +++ b/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0234-PR-c-48911.patch | |||
@@ -0,0 +1,96 @@ | |||
1 | From 68a4f9142fb55bcae7e9d73a9f68450d00ff0307 Mon Sep 17 00:00:00 2001 | ||
2 | From: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | ||
3 | Date: Fri, 6 May 2011 21:58:37 +0000 | ||
4 | Subject: [PATCH] PR c++/48911 | ||
5 | * semantics.c (cxx_eval_array_reference): Handle implicit | ||
6 | initializers. | ||
7 | |||
8 | git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@173515 138bc75d-0d04-0410-961f-82ee72b054a4 | ||
9 | |||
10 | index 8f621b9..8fd1820 100644 | ||
11 | --- a/gcc/cp/semantics.c | ||
12 | +++ b/gcc/cp/semantics.c | ||
13 | @@ -6280,6 +6280,7 @@ cxx_eval_array_reference (const constexpr_call *call, tree t, | ||
14 | non_constant_p); | ||
15 | tree index, oldidx; | ||
16 | HOST_WIDE_INT i; | ||
17 | + tree elem_type; | ||
18 | unsigned len, elem_nchars = 1; | ||
19 | if (*non_constant_p) | ||
20 | return t; | ||
21 | @@ -6292,16 +6293,27 @@ cxx_eval_array_reference (const constexpr_call *call, tree t, | ||
22 | return t; | ||
23 | else if (addr) | ||
24 | return build4 (ARRAY_REF, TREE_TYPE (t), ary, index, NULL, NULL); | ||
25 | + elem_type = TREE_TYPE (TREE_TYPE (ary)); | ||
26 | if (TREE_CODE (ary) == CONSTRUCTOR) | ||
27 | len = CONSTRUCTOR_NELTS (ary); | ||
28 | else | ||
29 | { | ||
30 | - elem_nchars = (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (ary))) | ||
31 | + elem_nchars = (TYPE_PRECISION (elem_type) | ||
32 | / TYPE_PRECISION (char_type_node)); | ||
33 | len = (unsigned) TREE_STRING_LENGTH (ary) / elem_nchars; | ||
34 | } | ||
35 | if (compare_tree_int (index, len) >= 0) | ||
36 | { | ||
37 | + if (tree_int_cst_lt (index, array_type_nelts_top (TREE_TYPE (ary)))) | ||
38 | + { | ||
39 | + /* If it's within the array bounds but doesn't have an explicit | ||
40 | + initializer, it's value-initialized. */ | ||
41 | + tree val = build_value_init (elem_type, tf_warning_or_error); | ||
42 | + return cxx_eval_constant_expression (call, val, | ||
43 | + allow_non_constant, addr, | ||
44 | + non_constant_p); | ||
45 | + } | ||
46 | + | ||
47 | if (!allow_non_constant) | ||
48 | error ("array subscript out of bound"); | ||
49 | *non_constant_p = true; | ||
50 | new file mode 100644 | ||
51 | index 0000000..547f552 | ||
52 | --- /dev/null | ||
53 | +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-missing.C | ||
54 | @@ -0,0 +1,39 @@ | ||
55 | +// PR c++/48911 | ||
56 | +// { dg-do compile } | ||
57 | +// { dg-options "-std=c++0x" } | ||
58 | + | ||
59 | +#define SA(X) static_assert((X),#X) | ||
60 | + | ||
61 | +struct A | ||
62 | +{ | ||
63 | + constexpr A () : a (6) {} | ||
64 | + int a; | ||
65 | +}; | ||
66 | + | ||
67 | +int | ||
68 | +main () | ||
69 | +{ | ||
70 | + constexpr int a[2] = { 42 }; | ||
71 | + constexpr int i = a[1]; | ||
72 | + SA(i==0); | ||
73 | + constexpr int b[1] = { }; | ||
74 | + constexpr int j = b[0]; | ||
75 | + SA(j==0); | ||
76 | + constexpr char c[2] = "a"; | ||
77 | + constexpr char k = c[1]; | ||
78 | + SA(k==0); | ||
79 | + constexpr char d[2] = ""; | ||
80 | + constexpr char l = d[1]; | ||
81 | + SA(l==0); | ||
82 | + constexpr wchar_t e[2] = L"a"; | ||
83 | + constexpr wchar_t m = e[1]; | ||
84 | + SA(m==0); | ||
85 | + constexpr wchar_t f[2] = L""; | ||
86 | + constexpr wchar_t n = f[1]; | ||
87 | + SA(n==0); | ||
88 | + constexpr A g[2] = { A () }; | ||
89 | + constexpr A o = g[0]; | ||
90 | + SA(o.a == 6); | ||
91 | + constexpr A p = g[1]; | ||
92 | + SA(p.a == 6); | ||
93 | +} | ||
94 | -- | ||
95 | 1.7.0.4 | ||
96 | |||