aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/class.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2013-05-30 15:20:08 -0400
committerJason Merrill <jason@gcc.gnu.org>2013-05-30 15:20:08 -0400
commit3a6a88c863a752e70e9a013ae89c87a3d7efe39b (patch)
treebb39bab3f2e19d7c75a3fd741f20f1059ba81b25 /gcc/cp/class.c
parent65f9e78999a8ff2dd889c0e3eec04f2aa0422542 (diff)
downloadgcc-3a6a88c863a752e70e9a013ae89c87a3d7efe39b.zip
gcc-3a6a88c863a752e70e9a013ae89c87a3d7efe39b.tar.gz
gcc-3a6a88c863a752e70e9a013ae89c87a3d7efe39b.tar.bz2
re PR c++/52377 (C++11 non-static initializers in unions are not used)
PR c++/52377 * class.c (common_enclosing_class): New. * cp-tree.h: Declare it. * init.c (sort_mem_initializers): Don't splice out a union member with an NSDMI. From-SVN: r199455
Diffstat (limited to 'gcc/cp/class.c')
-rw-r--r--gcc/cp/class.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index d6684cf..22cdf90 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -9259,4 +9259,30 @@ publicly_uniquely_derived_p (tree parent, tree type)
return base && base != error_mark_node;
}
+/* CTX1 and CTX2 are declaration contexts. Return the innermost common
+ class between them, if any. */
+
+tree
+common_enclosing_class (tree ctx1, tree ctx2)
+{
+ if (!TYPE_P (ctx1) || !TYPE_P (ctx2))
+ return NULL_TREE;
+ gcc_assert (ctx1 == TYPE_MAIN_VARIANT (ctx1)
+ && ctx2 == TYPE_MAIN_VARIANT (ctx2));
+ if (ctx1 == ctx2)
+ return ctx1;
+ for (tree t = ctx1; TYPE_P (t); t = TYPE_CONTEXT (t))
+ TYPE_MARKED_P (t) = true;
+ tree found = NULL_TREE;
+ for (tree t = ctx2; TYPE_P (t); t = TYPE_CONTEXT (t))
+ if (TYPE_MARKED_P (t))
+ {
+ found = t;
+ break;
+ }
+ for (tree t = ctx1; TYPE_P (t); t = TYPE_CONTEXT (t))
+ TYPE_MARKED_P (t) = false;
+ return found;
+}
+
#include "gt-cp-class.h"