summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0295-PR-c-48948.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0295-PR-c-48948.patch')
-rw-r--r--meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0295-PR-c-48948.patch188
1 files changed, 188 insertions, 0 deletions
diff --git a/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0295-PR-c-48948.patch b/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0295-PR-c-48948.patch
new file mode 100644
index 0000000000..53c553b878
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc-4.6.0/gcc-4_6-branch-backports/0295-PR-c-48948.patch
@@ -0,0 +1,188 @@
1From 4114bb38c8cffb97435ae4bdb6b7bef89d5228d6 Mon Sep 17 00:00:00 2001
2From: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
3Date: Fri, 20 May 2011 19:02:42 +0000
4Subject: [PATCH] PR c++/48948
5 * class.c (finalize_literal_type_property): Only check
6 for constexpr member functions of non-literal class.
7 * decl.c (cp_finish_decl): Don't call validate_constexpr_fundecl.
8 * semantics.c (literal_type_p): Call complete_type.
9
10git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@173975 138bc75d-0d04-0410-961f-82ee72b054a4
11
12index e1b8645..d412232 100644
13--- a/gcc/cp/class.c
14+++ b/gcc/cp/class.c
15@@ -4559,10 +4559,17 @@ finalize_literal_type_property (tree t)
16 && !TYPE_HAS_CONSTEXPR_CTOR (t))
17 CLASSTYPE_LITERAL_P (t) = false;
18
19- for (fn = TYPE_METHODS (t); fn; fn = DECL_CHAIN (fn))
20- if (DECL_DECLARED_CONSTEXPR_P (fn)
21- && TREE_CODE (fn) != TEMPLATE_DECL)
22- validate_constexpr_fundecl (fn);
23+ if (!CLASSTYPE_LITERAL_P (t))
24+ for (fn = TYPE_METHODS (t); fn; fn = DECL_CHAIN (fn))
25+ if (DECL_DECLARED_CONSTEXPR_P (fn)
26+ && TREE_CODE (fn) != TEMPLATE_DECL
27+ && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
28+ && !DECL_CONSTRUCTOR_P (fn))
29+ {
30+ DECL_DECLARED_CONSTEXPR_P (fn) = false;
31+ if (!DECL_TEMPLATE_INFO (fn))
32+ error ("enclosing class of %q+#D is not a literal type", fn);
33+ }
34 }
35
36 /* Check the validity of the bases and members declared in T. Add any
37diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
38index 81d5db3..2905b49 100644
39--- a/gcc/cp/decl.c
40+++ b/gcc/cp/decl.c
41@@ -5797,13 +5797,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
42 }
43 }
44
45- if (TREE_CODE (decl) == FUNCTION_DECL
46- /* For members, defer until finalize_literal_type_property. */
47- && (!DECL_CLASS_SCOPE_P (decl)
48- || !TYPE_BEING_DEFINED (DECL_CONTEXT (decl))))
49- validate_constexpr_fundecl (decl);
50-
51- else if (!ensure_literal_type_for_constexpr_object (decl))
52+ if (!ensure_literal_type_for_constexpr_object (decl))
53 DECL_DECLARED_CONSTEXPR_P (decl) = 0;
54
55 if (init && TREE_CODE (decl) == FUNCTION_DECL)
56diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
57index 6083376..bd33bac 100644
58--- a/gcc/cp/semantics.c
59+++ b/gcc/cp/semantics.c
60@@ -5327,7 +5327,7 @@ literal_type_p (tree t)
61 if (SCALAR_TYPE_P (t))
62 return true;
63 if (CLASS_TYPE_P (t))
64- return CLASSTYPE_LITERAL_P (t);
65+ return CLASSTYPE_LITERAL_P (complete_type (t));
66 if (TREE_CODE (t) == ARRAY_TYPE)
67 return literal_type_p (strip_array_types (t));
68 return false;
69@@ -5439,6 +5439,7 @@ is_valid_constexpr_fn (tree fun, bool complain)
70 rettype, fun);
71 }
72
73+ /* Check this again here for cxx_eval_call_expression. */
74 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun)
75 && !CLASSTYPE_LITERAL_P (DECL_CONTEXT (fun)))
76 {
77new file mode 100644
78index 0000000..f1d9cce
79--- /dev/null
80+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-friend.C
81@@ -0,0 +1,23 @@
82+// PR c++/48948
83+// { dg-options -std=c++0x }
84+
85+struct A { A(); };
86+
87+struct B {
88+ friend constexpr int f(B) { return 0; } // OK
89+ friend constexpr int f(A) { return 0; } // { dg-error "constexpr" }
90+};
91+
92+template <class T>
93+struct C
94+{
95+ friend constexpr int f(C) { return 0; }
96+ friend constexpr int g(C, A) { return 0; } // { dg-error "double" }
97+ constexpr int m(C) { return 0; }
98+ constexpr int m(A) { return 0; } // { dg-error "double" }
99+};
100+
101+constexpr int i = f(C<int>());
102+constexpr int j = C<int>().m(C<int>());
103+constexpr int k = C<double>().m(A()); // { dg-error "not a constexpr function" }
104+constexpr int l = g(C<double>(),A()); // { dg-error "not a constexpr function" }
105diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-incomplete1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-incomplete1.C
106new file mode 100644
107index 0000000..71372d2
108--- /dev/null
109+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-incomplete1.C
110@@ -0,0 +1,7 @@
111+// { dg-options -std=c++0x }
112+
113+struct A
114+{
115+ static constexpr A a = 1; // { dg-error "incomplete|literal" }
116+ constexpr A(int i) { }
117+};
118diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-incomplete2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-incomplete2.C
119new file mode 100644
120index 0000000..dc0b742
121--- /dev/null
122+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-incomplete2.C
123@@ -0,0 +1,31 @@
124+// A constructor that might or might not be constexpr still makes
125+// its class literal.
126+// { dg-options -std=c++0x }
127+
128+template <class T>
129+struct B
130+{
131+ constexpr B(T) { }
132+ constexpr B() {}
133+};
134+
135+struct A
136+{
137+ B<A> b;
138+};
139+
140+constexpr A a {};
141+
142+template <class T>
143+struct C
144+{
145+ constexpr C(T) { }
146+ C() {}
147+};
148+
149+struct D
150+{
151+ C<D> c;
152+};
153+
154+constexpr D d {}; // { dg-error "not a constexpr function" }
155diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-incomplete3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-incomplete3.C
156new file mode 100644
157index 0000000..81822b0
158--- /dev/null
159+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-incomplete3.C
160@@ -0,0 +1,12 @@
161+// PR c++/49015
162+// { dg-options -std=c++0x }
163+
164+class A;
165+
166+class B {
167+ friend constexpr B f(A); // Line 5
168+};
169+
170+class A {};
171+
172+constexpr B f(A) { return B(); } // Line 10
173diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-memfn1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-memfn1.C
174index 4646f82..ef7ac6b 100644
175--- a/gcc/testsuite/g++.dg/cpp0x/constexpr-memfn1.C
176+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-memfn1.C
177@@ -13,6 +13,6 @@ constexpr X X::g(X x) { return x; }
178 struct Y
179 {
180 Y() { }
181- constexpr Y f(Y y); // { dg-error "constexpr" }
182- static constexpr Y g(Y y); // { dg-error "constexpr" }
183+ constexpr Y f(Y y); // { dg-error "not a literal type" }
184+ static constexpr Y g(Y y) {} // { dg-error "constexpr" }
185 };
186--
1871.7.0.4
188