From: Volker Reichelt Date: Sat, 27 Jan 2007 19:58:38 +0000 (+0000) Subject: Backport: X-Git-Tag: releases/gcc-4.0.4~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b9987f2d01f68d35ca1c62d955c83416022c25d;p=thirdparty%2Fgcc.git Backport: 2006-11-13 Mark Mitchell PR c++/29106 * init.c (constant_value_1): Treat a DECL_INITIAL of error_mark_node as meaning that the variable is uninitialized, rather than erroneously initialized. * g++.dg/init/self1.C: New test. * g++.dg/other/fold1.C: Adjust error markers. * g++.dg/init/member1.C: Likewise. 2006-08-27 Simon Martin PR c++/28284 * pt.c (fold_non_dependent_expr): Make sure expr is not dereferenced if it is NULL. * g++.dg/template/pr28284.C: New test. From-SVN: r121238 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 22ca0608540f..bc7528695398 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,18 @@ +2007-01-27 Volker Reichelt + + Backport: + 2006-11-13 Mark Mitchell + + PR c++/29106 + * g++.dg/init/self1.C: New test. + * g++.dg/other/fold1.C: Adjust error markers. + * g++.dg/init/member1.C: Likewise. + + 2006-08-27 Simon Martin + + PR c++/28284 + * g++.dg/template/pr28284.C: New test. + 2006-11-18 Lee Millward PR c++/29022 diff --git a/gcc/cp/init.c b/gcc/cp/init.c index a8249e7f452c..7ce088118394 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1608,8 +1608,11 @@ constant_value_1 (tree decl, bool integral_p) mark_used (decl); init = DECL_INITIAL (decl); } + /* If INIT is ERROR_MARK_NODE, that may mean that we are + presently processing the initializer, so we conservatively + treat this situation as meaning that DECL is uninitialized. */ if (init == error_mark_node) - return error_mark_node; + break; if (!init || !TREE_TYPE (init) || (integral_p diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 75b063b75588..f6a4f3a83b34 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -3314,6 +3314,9 @@ redeclare_class_template (tree type, tree parms) tree fold_non_dependent_expr (tree expr) { + if (expr == NULL_TREE) + return NULL_TREE; + /* If we're in a template, but EXPR isn't value dependent, simplify it. We're supposed to treat: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0e0027d05f4c..7ca006e02b3b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,19 @@ +2007-01-27 Volker Reichelt + + Backport: + 2006-11-13 Mark Mitchell + + PR c++/29106 + * init.c (constant_value_1): Treat a DECL_INITIAL of + error_mark_node as meaning that the variable is uninitialized, + rather than erroneously initialized. + + 2006-08-27 Simon Martin + + PR c++/28284 + * pt.c (fold_non_dependent_expr): Make sure expr is not dereferenced if it + is NULL. + 2007-01-25 Richard Guenther Backport from mainline: diff --git a/gcc/testsuite/g++.dg/init/member1.C b/gcc/testsuite/g++.dg/init/member1.C index aededf23e7b7..e2af0809c713 100644 --- a/gcc/testsuite/g++.dg/init/member1.C +++ b/gcc/testsuite/g++.dg/init/member1.C @@ -11,7 +11,7 @@ template struct B {}; template struct C { static const int i = A::i; // { dg-error "incomplete" } - static const int j = i; + static const int j = i; // { dg-error "non-constant expression" } B b; // { dg-error "not a valid template arg" } }; diff --git a/gcc/testsuite/g++.dg/init/self1.C b/gcc/testsuite/g++.dg/init/self1.C new file mode 100644 index 000000000000..dd37c8e609d9 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/self1.C @@ -0,0 +1,19 @@ +// PR c++/29106 +// { dg-do run } + +int i; + +void f(__SIZE_TYPE__) { + i = 3; +} + + +int main() +{ + int* const savepos = sizeof(*savepos) ? 0 : 0; + + f (sizeof (*savepos)); + + if (i != 3) + return 1; +} diff --git a/gcc/testsuite/g++.dg/other/fold1.C b/gcc/testsuite/g++.dg/other/fold1.C index f1f0dd9b99b5..b085a84f0dda 100644 --- a/gcc/testsuite/g++.dg/other/fold1.C +++ b/gcc/testsuite/g++.dg/other/fold1.C @@ -4,5 +4,5 @@ struct A { static const int i = i; // { dg-error "not declared" } - int x[i]; // { dg-error "variable-size array" } + int x[i]; // { dg-error "integral constant-expression" } }; diff --git a/gcc/testsuite/g++.dg/template/pr28284.C b/gcc/testsuite/g++.dg/template/pr28284.C new file mode 100644 index 000000000000..7ef9aa12b2b3 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/pr28284.C @@ -0,0 +1,12 @@ +/* { dg-do compile } */ + +template struct A +{ + static const int i=x; /* { dg-error "was not declared in this scope" } */ + static const int j, k; +}; + +template const int A::j = i; +template const int A::k = j; + +A<0> a;