OSDN Git Service

PR c++/30328
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 12 Mar 2007 00:26:39 +0000 (00:26 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 12 Mar 2007 00:26:39 +0000 (00:26 +0000)
* semantics.c (finish_typeof): Use unlowered_expr_type.

PR c++/30328
* g++.dg/ext/bitfield1.C: New test.

PR c++/31038
* parser.c (cp_parser_postfix_expression): Disallow compound
literals in constant expressions.

PR c++/31038
* g++.dg/template/complit2.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@122829 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/bitfield1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/complit2.C [new file with mode: 0644]

index 2f9b251..acc6435 100644 (file)
@@ -1,3 +1,12 @@
+2007-03-11  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/31038
+       * parser.c (cp_parser_postfix_expression): Disallow compound
+       literals in constant expressions.
+
+       PR c++/30328
+       * semantics.c (finish_typeof): Use unlowered_expr_type.
+       
 2007-03-10  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/30274
index f81fbdf..54c7668 100644 (file)
@@ -4343,6 +4343,21 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p)
                   allowed in standard C++.  */
                if (pedantic)
                  pedwarn ("ISO C++ forbids compound-literals");
+               /* For simplicitly, we disallow compound literals in
+                  constant-expressions for simpliicitly.  We could
+                  allow compound literals of integer type, whose
+                  initializer was a constant, in constant
+                  expressions.  Permitting that usage, as a further
+                  extension, would not change the meaning of any
+                  currently accepted programs.  (Of course, as
+                  compound literals are not part of ISO C++, the
+                  standard has nothing to say.)  */
+               if (cp_parser_non_integral_constant_expression 
+                   (parser, "non-constant compound literals"))
+                 {
+                   postfix_expression = error_mark_node;
+                   break;
+                 }
                /* Form the representation of the compound-literal.  */
                postfix_expression
                  = finish_compound_literal (type, initializer_list);
index f63ed2f..e016b0a 100644 (file)
@@ -2927,7 +2927,7 @@ finish_typeof (tree expr)
       return type;
     }
 
-  type = TREE_TYPE (expr);
+  type = unlowered_expr_type (expr);
 
   if (!type || type == unknown_type_node)
     {
index 2276ea0..fb51c23 100644 (file)
@@ -1,3 +1,11 @@
+2007-03-11  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/31038
+       * g++.dg/template/complit2.C: New test.
+
+       PR c++/30328
+       * g++.dg/ext/bitfield1.C: New test.
+
 2007-03-11  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/30883
diff --git a/gcc/testsuite/g++.dg/ext/bitfield1.C b/gcc/testsuite/g++.dg/ext/bitfield1.C
new file mode 100644 (file)
index 0000000..25c90df
--- /dev/null
@@ -0,0 +1,22 @@
+// PR c++/30328
+// { dg-do link }
+// { dg-options "" }
+
+struct S
+{
+  signed int a:17;
+} x;
+
+typedef typeof (x.a) foo;
+
+template <class T>
+T* inc(T* p) { return p+1; }
+
+int main ()
+{
+  foo x[2] = { 1,2 };
+  int y[2] = { 1,2 };
+  *inc(x);
+  *inc(y);
+  return 0;
+}
diff --git a/gcc/testsuite/g++.dg/template/complit2.C b/gcc/testsuite/g++.dg/template/complit2.C
new file mode 100644 (file)
index 0000000..cf3856d
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/31038
+// { dg-options "" }
+
+template<int> void foo()
+{
+  int i = (int) { 0 };
+}
+
+template void foo<0>();
+int f();
+
+template<int> void bar()
+{
+  int i = (int) { f() };
+}
+
+template void bar<0>();