From 6ae473ecbceecf26bc912cbbfce628dca4f16209 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 13 Jun 2005 17:20:28 +0000 Subject: [PATCH] re PR c++/20789 (ICE with incomplete type in template) cp: PR c++/20789 * decl.c (cp_finish_decl): Clear runtime runtime initialization if in-class decl's initializer is bad. testsuite: PR c++/20789 * g++.dg/init/member1.C: New. * g++.dg/other/warning1.C: Adjust. From-SVN: r100883 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl.c | 10 ++++++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/init/member1.C | 2 +- gcc/testsuite/g++.dg/other/warning1.C | 4 ++-- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 50b59ed8ea32..46941cab29e0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2005-06-13 Nathan Sidwell + + PR c++/20789 + * decl.c (cp_finish_decl): Clear runtime runtime initialization if + in-class decl's initializer is bad. + 2005-06-10 Aldy Hernandez PR c++/10611 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 699fe0225b98..12622cedfb7f 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4919,6 +4919,16 @@ cp_finish_decl (tree decl, tree init, tree asmspec_tree, int flags) "initialized", decl); init = NULL_TREE; } + if (DECL_EXTERNAL (decl) && init) + { + /* The static data member cannot be initialized by a + non-constant when being declared. */ + error ("`%D' cannot be initialized by a non-constant expression" + " when being declared", decl); + DECL_INITIALIZED_IN_CLASS_P (decl) = 0; + init = NULL_TREE; + } + /* Handle: [dcl.init] diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 95284782d31c..5792daea7c1d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2005-06-13 Nathan Sidwell + + PR c++/20789 + * g++.dg/init/member1.C: New. + * g++.dg/other/warning1.C: Adjust. + 2005-06-08 Nathan Sidwell PR c++/21903 diff --git a/gcc/testsuite/g++.dg/init/member1.C b/gcc/testsuite/g++.dg/init/member1.C index 1c89d5a1d43d..e94684fa8c0e 100644 --- a/gcc/testsuite/g++.dg/init/member1.C +++ b/gcc/testsuite/g++.dg/init/member1.C @@ -12,7 +12,7 @@ template struct C { static const int i = A::i; // { dg-error "incomplete" } static const int j = i; // { dg-error "initialized by a non-const" } - B b; // { dg-error "not a valid template arg" } + B b; // { dg-error "cannot be used as template arg" } }; C c; diff --git a/gcc/testsuite/g++.dg/other/warning1.C b/gcc/testsuite/g++.dg/other/warning1.C index 109fc46aa22b..6662c25e6e17 100644 --- a/gcc/testsuite/g++.dg/other/warning1.C +++ b/gcc/testsuite/g++.dg/other/warning1.C @@ -7,8 +7,8 @@ extern "C" int printf(const char *, ...); struct S { - static const float inf = 1.0f / 0.0f; // { dg-warning "1.0|initialization" } - static const float nan = 0.0f / 0.0f; // { dg-warning "0.0|initialization" } + static const float inf = 1.0f / 0.0f; // { dg-warning "1.0|initializ" } + static const float nan = 0.0f / 0.0f; // { dg-warning "0.0|initializ" } }; int main() -- 2.47.2