This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/38877
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 16 Jan 2009 17:34:59 -0500
- Subject: C++ PATCH for c++/38877
My previous patch changed the test from the "field" of the COMPONENT_REF
not having FIELD_DECL code, to just checking for a possibly overloaded
function. Apparently that doesn't cover all the cases, as in templates
we can end up with an IDENTIFIER_NODE for the "field".
The build_new change also fixes this testcase by not calling lvalue_p in
the first place.
Tested x86_64-pc-linux-gnu, applied to trunk.
2009-01-16 Jason Merrill <jason@redhat.com>
PR c++/38877
* tree.c (lvalue_p_1): Allow non-fields in COMPONENT_REF.
* init.c (build_new): Don't call describable_type unless we
have an auto.
* g++.dg/template/lvalue1.C: New test.
Index: cp/init.c
===================================================================
*** cp/init.c (revision 143443)
--- cp/init.c (working copy)
*************** build_new (tree placement, tree type, tr
*** 2334,2344 ****
orig_nelts = nelts;
orig_init = init;
! if (nelts == NULL_TREE && init != void_zero_node && list_length (init) == 1
! && describable_type (TREE_VALUE (init)))
{
tree auto_node = type_uses_auto (type);
! if (auto_node)
type = do_auto_deduction (type, TREE_VALUE (init), auto_node);
}
--- 2334,2343 ----
orig_nelts = nelts;
orig_init = init;
! if (nelts == NULL_TREE && init != void_zero_node && list_length (init) == 1)
{
tree auto_node = type_uses_auto (type);
! if (auto_node && describable_type (TREE_VALUE (init)))
type = do_auto_deduction (type, TREE_VALUE (init), auto_node);
}
Index: cp/tree.c
===================================================================
*** cp/tree.c (revision 143443)
--- cp/tree.c (working copy)
*************** lvalue_p_1 (tree ref,
*** 114,122 ****
;
else if (is_overloaded_fn (TREE_OPERAND (ref, 1)))
/* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
! situations. */
! op1_lvalue_kind = lvalue_p_1 (TREE_OPERAND (ref, 1),
! treat_class_rvalues_as_lvalues);
else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
{
/* Clear the ordinary bit. If this object was a class
--- 114,124 ----
;
else if (is_overloaded_fn (TREE_OPERAND (ref, 1)))
/* The "field" can be a FUNCTION_DECL or an OVERLOAD in some
! situations. If we're seeing a COMPONENT_REF, it's a non-static
! member, so it isn't an lvalue. */
! op1_lvalue_kind = clk_none;
! else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL)
! /* This can be IDENTIFIER_NODE in a template. */;
else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1)))
{
/* Clear the ordinary bit. If this object was a class
Index: testsuite/g++.dg/template/lvalue1.C
===================================================================
*** testsuite/g++.dg/template/lvalue1.C (revision 0)
--- testsuite/g++.dg/template/lvalue1.C (revision 0)
***************
*** 0 ****
--- 1,31 ----
+ // PR c++/38877
+
+ template<class _T1, class _T2>
+ struct pair
+ {
+ typedef _T1 first_type;
+ typedef _T2 second_type;
+ _T1 first;
+ _T2 second;
+ pair () : first(), second() { }
+ pair(const _T1& __a, const _T2& __b)
+ : first(__a), second(__b) { }
+ };
+
+ template<class _T1, class _T2>
+ inline pair<_T1, _T2>
+ make_pair(_T1 __x, _T2 __y)
+ {
+ return pair<_T1, _T2>(__x, __y);
+ }
+
+ template <int dim> class bar;
+
+ template <int dim>
+ pair<bar<dim> *, unsigned int>
+ foo (unsigned int position)
+ {
+ const pair<int,unsigned int> tmp;
+ return make_pair (new bar<dim>(tmp.first),
+ position);
+ }