* C++ PATCH for c++/67550 (wrong value for reference to const class var)
@ 2015-12-17 16:50 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2015-12-17 16:50 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 341 bytes --]
In my rework of decl_constant_value and kin, I enabled its use in more
places, which revealed a problem: when it is allowing non-constexpr
aggregate initializers, we need to double-check that we aren't returning
something that had initializers stripped out in split_nonconstant_init.
Tested x86_64-pc-linux-gnu, applying to trunk and 5.
[-- Attachment #2: 67550.patch --]
[-- Type: text/x-patch, Size: 1288 bytes --]
commit 230c77258443c76da9837a078f0326fee3311f02
Author: Jason Merrill <jason@redhat.com>
Date: Thu Dec 17 09:56:20 2015 -0500
PR c++/67550
* init.c (constant_value_1): Don't return a CONSTRUCTOR missing
non-constant elements.
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index a08f7d7..b7f10a1 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -2093,6 +2093,11 @@ constant_value_1 (tree decl, bool strict_p, bool return_aggregate_cst_ok_p)
&& (TREE_CODE (init) == CONSTRUCTOR
|| TREE_CODE (init) == STRING_CST)))
break;
+ /* Don't return a CONSTRUCTOR for a variable with partial run-time
+ initialization, since it doesn't represent the entire value. */
+ if (TREE_CODE (init) == CONSTRUCTOR
+ && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
+ break;
decl = unshare_expr (init);
}
return decl;
diff --git a/gcc/testsuite/g++.dg/init/aggr13.C b/gcc/testsuite/g++.dg/init/aggr13.C
new file mode 100644
index 0000000..08248a6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/aggr13.C
@@ -0,0 +1,17 @@
+// PR c++/67550
+// { dg-do run }
+
+struct S {
+ int x;
+ int y;
+};
+int foo() { return 1; }
+
+int main() {
+ S const data[] = {{0, foo()}};
+
+ S data2[] = {data[0]};
+
+ if (!data2[0].y)
+ __builtin_abort();
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-12-17 16:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-17 16:50 C++ PATCH for c++/67550 (wrong value for reference to const class var) Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).