* C++ PATCH for c++/48015 (C++0x ICE with non-constant initializer for const int var in template)
@ 2011-03-08 5:25 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2011-03-08 5:25 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 425 bytes --]
constant_value_1 has been trying to pull out DECL_INITIAL for any
variable with the proper type. This can be problematic in templates,
where DECL_INITIAL hasn't always been properly folded yet. But since we
try to reduce initializers to a constant when we process the
declaration, we can just decide whether or not we want to use the
initializer based on TREE_CONSTANT.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: 48015.patch --]
[-- Type: text/plain, Size: 1736 bytes --]
commit 9c7fa022068d56f4417aeea733e8bdf21c4a98e7
Author: Jason Merrill <jason@redhat.com>
Date: Mon Mar 7 16:00:05 2011 -0500
PR c++/48015
* init.c (constant_value_1): Always require init to be TREE_CONSTANT.
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index e590118..56f66fa 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -1760,17 +1760,15 @@ constant_value_1 (tree decl, bool integral_p)
init = TREE_VALUE (init);
if (!init
|| !TREE_TYPE (init)
- || uses_template_parms (init)
- || (integral_p
- ? false
- : (!TREE_CONSTANT (init)
- /* Do not return an aggregate constant (of which
- string literals are a special case), as we do not
- want to make inadvertent copies of such entities,
- and we must be sure that their addresses are the
- same everywhere. */
- || TREE_CODE (init) == CONSTRUCTOR
- || TREE_CODE (init) == STRING_CST)))
+ || !TREE_CONSTANT (init)
+ || (!integral_p
+ /* Do not return an aggregate constant (of which
+ string literals are a special case), as we do not
+ want to make inadvertent copies of such entities,
+ and we must be sure that their addresses are the
+ same everywhere. */
+ && (TREE_CODE (init) == CONSTRUCTOR
+ || TREE_CODE (init) == STRING_CST)))
break;
decl = unshare_expr (init);
}
diff --git a/gcc/testsuite/g++.dg/cpp0x/regress/non-const1.C b/gcc/testsuite/g++.dg/cpp0x/regress/non-const1.C
new file mode 100644
index 0000000..7fc66a7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/regress/non-const1.C
@@ -0,0 +1,9 @@
+// PR c++/48015
+// { dg-options -std=c++0x }
+
+template <typename T> T f(T);
+template <typename T> void g()
+{
+ int const c = f (1);
+ int i = c - 0;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-03-08 5:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-08 5:25 C++ PATCH for c++/48015 (C++0x ICE with non-constant initializer for const int var in template) 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).