diff options
author | Jakub Jelinek <jakub@redhat.com> | 2017-01-05 22:12:02 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2017-01-05 22:12:02 +0100 |
commit | 962c5679b3c61f09b96ab72e474a897b870fd2c1 (patch) | |
tree | 4db3ac6174fe412ca90022d363d42e2dcfeb5ba5 /gcc/cp | |
parent | 8c15f541f3e9835facb5afaa994887de48ed4b78 (diff) | |
download | gcc-962c5679b3c61f09b96ab72e474a897b870fd2c1.zip gcc-962c5679b3c61f09b96ab72e474a897b870fd2c1.tar.gz gcc-962c5679b3c61f09b96ab72e474a897b870fd2c1.tar.bz2 |
re PR c++/78890 (ICE on invalid reference type in union)
PR c++/78890
* class.c (check_field_decls): Diagnose REFERENCE_TYPE fields in
unions even for C++11 and later.
* g++.dg/init/ref14.C: Expect error even in C++11 and later.
* g++.dg/init/union1.C: Likewise.
* g++.dg/cpp0x/union6.C: Expect errors.
* g++.dg/cpp0x/union8.C: New test.
* g++.dg/cpp0x/pr78890-1.C: New test.
* g++.dg/cpp0x/pr78890-2.C: New test.
From-SVN: r244112
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/class.c | 16 |
2 files changed, 15 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 35f0a22..5bc7d52 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-01-05 Jakub Jelinek <jakub@redhat.com> + + PR c++/78890 + * class.c (check_field_decls): Diagnose REFERENCE_TYPE fields in + unions even for C++11 and later. + 2017-01-05 Nathan Sidwell <nathan@acm.org> PR c++/78765 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 1c6b401..b7c26a1 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -3759,25 +3759,27 @@ check_field_decls (tree t, tree *access_decls, /* When this goes into scope, it will be a non-local reference. */ DECL_NONLOCAL (x) = 1; - if (TREE_CODE (t) == UNION_TYPE - && cxx_dialect < cxx11) + if (TREE_CODE (t) == UNION_TYPE) { /* [class.union] (C++98) If a union contains a static data member, or a member of reference type, the program is ill-formed. - In C++11 this limitation doesn't exist anymore. */ - if (VAR_P (x)) + In C++11 [class.union] says: + If a union contains a non-static data member of reference type + the program is ill-formed. */ + if (VAR_P (x) && cxx_dialect < cxx11) { error ("in C++98 %q+D may not be static because it is " "a member of a union", x); continue; } - if (TREE_CODE (type) == REFERENCE_TYPE) + if (TREE_CODE (type) == REFERENCE_TYPE + && TREE_CODE (x) == FIELD_DECL) { - error ("in C++98 %q+D may not have reference type %qT " - "because it is a member of a union", x, type); + error ("non-static data member %q+D in a union may not " + "have reference type %qT", x, type); continue; } } |