This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Support [dcl.init] para 13
- From: Geoffrey Keating <gkeating at apple dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 26 Nov 2002 17:58:03 -0800 (PST)
- Subject: Support [dcl.init] para 13
Mark's recent rewrite of the initialization stuff lost a bit of
functionality, this puts it back.
Tested by a C++ frontend + library build and test run on powerpc-darwin.
--
- Geoffrey Keating <geoffk@apple.com>
===File ~/patches/gcc-cpbraceinit.patch=====================
Index: cp/ChangeLog
2002-11-26 Geoffrey Keating <geoffk@apple.com>
* 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 <geoffk@apple.com>
* g++.dg/init/brace2.C: New test.
* g++.old-deja/g++.mike/p9129.C: Correct.
Index: testsuite/g++.dg/init/brace2.C
===================================================================
RCS file: testsuite/g++.dg/init/brace2.C
diff -N testsuite/g++.dg/init/brace2.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/g++.dg/init/brace2.C 27 Nov 2002 01:53:39 -0000
@@ -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" }
+
Index: testsuite/g++.old-deja/g++.mike/p9129.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.mike/p9129.C,v
retrieving revision 1.4
diff -u -p -u -p -r1.4 p9129.C
--- testsuite/g++.old-deja/g++.mike/p9129.C 11 Oct 2002 16:50:44 -0000 1.4
+++ testsuite/g++.old-deja/g++.mike/p9129.C 27 Nov 2002 01:53:52 -0000
@@ -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 -
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.959
diff -u -p -u -p -r1.959 decl.c
--- cp/decl.c 31 Oct 2002 00:04:12 -0000 1.959
+++ cp/decl.c 27 Nov 2002 01:54:29 -0000
@@ -8017,7 +8017,19 @@ check_initializer (tree decl, tree init,
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. */
============================================================