From a9df464b2734d75ea7f1f5491fbed8f5eb3fac4e Mon Sep 17 00:00:00 2001 From: geoffk Date: Wed, 27 Nov 2002 01:59:43 +0000 Subject: [PATCH] Index: cp/ChangeLog 2002-11-26 Geoffrey Keating * decl.c (check_initializer): Don't error on initialisation of a scalar with a brace-enclosed expression. Index: testsuite/ChangeLog 2002-11-26 Geoffrey Keating * g++.dg/init/brace2.C: New test. * g++.old-deja/g++.mike/p9129.C: Correct. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@59553 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/decl.c | 14 +++++++++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/init/brace2.C | 8 ++++++++ gcc/testsuite/g++.old-deja/g++.mike/p9129.C | 2 +- 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/init/brace2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bd596d5..42ae0dd 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2002-11-26 Geoffrey Keating + + * decl.c (check_initializer): Don't error on initialisation of + a scalar with a brace-enclosed expression. + 2002-11-26 Nathan Sidwell * cp-tree.h (DECL_LANG_FLAG_4): Document more uses. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 9ee0556..5a30e5b 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -8017,7 +8017,19 @@ check_initializer (tree decl, tree init, int flags) else if (init) { if (TREE_CODE (init) == CONSTRUCTOR && TREE_HAS_CONSTRUCTOR (init)) - init = reshape_init (type, &init); + { + /* [dcl.init] paragraph 13, + If T is a scalar type, then a declaration of the form + T x = { a }; + is equivalent to + T x = a; + + reshape_init will complain about the extra braces, + and doesn't do anything useful in the case where TYPE is + scalar, so just don't call it. */ + if (CP_AGGREGATE_TYPE_P (type)) + init = reshape_init (type, &init); + } /* If DECL has an array type without a specific bound, deduce the array size from the initializer. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 86d7df3..d9a69fc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2002-11-26 Geoffrey Keating + + * g++.dg/init/brace2.C: New test. + * g++.old-deja/g++.mike/p9129.C: Correct. + 2002-11-26 Mark Mitchell * g++.dg/abi/empty10.C: Don't run on non-x86 targets. diff --git a/gcc/testsuite/g++.dg/init/brace2.C b/gcc/testsuite/g++.dg/init/brace2.C new file mode 100644 index 0000000..488d916 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/brace2.C @@ -0,0 +1,8 @@ +// { dg-do compile } +// [dcl.init] paragraph 13. +int x = { 2 }; +const char * y = { "hello" }; +int a = 2; +int b = { 2,3 }; // { dg-error "requires one element" } +int c = { { 2 } } ; // { dg-error "braces around scalar initializer" } + diff --git a/gcc/testsuite/g++.old-deja/g++.mike/p9129.C b/gcc/testsuite/g++.old-deja/g++.mike/p9129.C index a986104..c8d5485 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/p9129.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/p9129.C @@ -7,6 +7,6 @@ public: int DoSomething(); }; -int (Foo::*pA)() = { &Foo::DoSomething }; // ERROR - +int (Foo::*pA)() = { &Foo::DoSomething }; int (Foo::*X[1])(int) = { { &Foo::DoSomething } }; // ERROR - int (Foo::*Y[])(int) = { { &Foo::DoSomething, &Foo::DoSomething, 0 } }; // ERROR - -- 2.7.4