This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ Patch] PR 33460
- From: Paolo Carlini <pcarlini at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Mark Mitchell <mark at codesourcery dot com>
- Date: Tue, 18 Sep 2007 22:05:11 +0200
- Subject: [C++ Patch] PR 33460
Hi,
this is a follow-up to 30302, which indeed seems just do to not
consistently replacing both uses of DECL_CONTEXT with
context_for_name_lookup.
Tested x86_64-linux, Ok for mainline?
Paolo.
PS: independently of this ICE, it could be argued that the diagnostic
having to do with anonymous structs appear not always emitted at the
right line number. I don't know if it's a known issue...
cp/
2007-09-18 Paolo Carlini <pcarlini@suse.de>
PR c++/33460
* semantics.c (finish_id_expression): Use consistently
context_for_name_lookup.
* decl.c (fixup_anonymous_aggr): Fix error message for
anonymous struct (vs union).
testsuite/
2007-09-18 Paolo Carlini <pcarlini@suse.de>
PR c++/33460
* g++.dg/ext/anon-struct6.C: New.
Index: testsuite/g++.dg/ext/anon-struct6.C
===================================================================
*** testsuite/g++.dg/ext/anon-struct6.C (revision 0)
--- testsuite/g++.dg/ext/anon-struct6.C (revision 0)
***************
*** 0 ****
--- 1,10 ----
+ // PR c++/33460
+
+ struct A
+ {
+ struct
+ { // { dg-error "anonymous struct cannot have function members" }
+ struct { static int i; }; // { dg-error "prohibits anonymous structs|non-static data members" }
+ void foo() { i; }
+ }; // { dg-error "prohibits anonymous structs" }
+ };
Index: cp/decl.c
===================================================================
*** cp/decl.c (revision 128584)
--- cp/decl.c (working copy)
*************** fixup_anonymous_aggr (tree t)
*** 3704,3711 ****
/* ISO C++ 9.5.3. Anonymous unions may not have function members. */
if (TYPE_METHODS (t))
! error ("%Jan anonymous union cannot have function members",
! TYPE_MAIN_DECL (t));
/* Anonymous aggregates cannot have fields with ctors, dtors or complex
assignment operators (because they cannot have these methods themselves).
--- 3704,3717 ----
/* ISO C++ 9.5.3. Anonymous unions may not have function members. */
if (TYPE_METHODS (t))
! {
! tree decl = TYPE_MAIN_DECL (t);
!
! if (TREE_CODE (t) != UNION_TYPE)
! error ("%Jan anonymous struct cannot have function members", decl);
! else
! error ("%Jan anonymous union cannot have function members", decl);
! }
/* Anonymous aggregates cannot have fields with ctors, dtors or complex
assignment operators (because they cannot have these methods themselves).
Index: cp/semantics.c
===================================================================
*** cp/semantics.c (revision 128583)
--- cp/semantics.c (working copy)
*************** finish_id_expression (tree id_expression
*** 2926,2938 ****
else
{
if (DECL_P (decl) && DECL_NONLOCAL (decl)
! && DECL_CLASS_SCOPE_P (decl)
! && context_for_name_lookup (decl) != current_class_type)
{
! tree path;
!
! path = currently_open_derived_class (DECL_CONTEXT (decl));
! perform_or_defer_access_check (TYPE_BINFO (path), decl, decl);
}
decl = convert_from_reference (decl);
--- 2926,2940 ----
else
{
if (DECL_P (decl) && DECL_NONLOCAL (decl)
! && DECL_CLASS_SCOPE_P (decl))
{
! tree context = context_for_name_lookup (decl);
! if (context != current_class_type)
! {
! tree path = currently_open_derived_class (context);
! perform_or_defer_access_check (TYPE_BINFO (path),
! decl, decl);
! }
}
decl = convert_from_reference (decl);