OSDN Git Service

PR c++/42277
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 4 Dec 2009 22:51:12 +0000 (22:51 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 4 Dec 2009 22:51:12 +0000 (22:51 +0000)
* semantics.c (finish_decltype_type): Don't assume that op1 of a
COMPONENT_REF is always the field.
* g++.dg/cpp0x/decltype20.C: New.

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

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/decltype20.C [new file with mode: 0644]

index 0c96a78..7ec27d4 100644 (file)
@@ -1,3 +1,9 @@
+2009-12-04  Jason Merrill  <jason@redhat.com>
+
+       PR c++/42277
+       * semantics.c (finish_decltype_type): Defer handling of decltype
+       of a non-dependent COMPONENT_REF in a template.
+
 2009-12-04  Dodji Seketeli  <dodji@redhat.com>
 
        PR c++/42218
index 4c36280..841efc8 100644 (file)
@@ -4777,7 +4777,13 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p)
       return error_mark_node;
     }
 
-  if (type_dependent_expression_p (expr))
+  if (type_dependent_expression_p (expr)
+      /* In a template, a COMPONENT_REF has an IDENTIFIER_NODE for op1 even
+        if it isn't dependent, so that we can check access control at
+        instantiation time, so defer the decltype as well (PR 42277).  */
+      || (id_expression_or_member_access_p
+         && processing_template_decl
+         && TREE_CODE (expr) == COMPONENT_REF))
     {
       if (id_expression_or_member_access_p)
        {
index b20ddd2..ed866cf 100644 (file)
@@ -1,3 +1,8 @@
+2009-12-04  Jason Merrill  <jason@redhat.com>
+
+       PR c++/42277
+       * g++.dg/cpp0x/decltype20.C: New.
+
 2009-12-04  David Daney  <ddaney@caviumnetworks.com>
 
        PR rtl-optimization/42164
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype20.C b/gcc/testsuite/g++.dg/cpp0x/decltype20.C
new file mode 100644 (file)
index 0000000..3155cdc
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/42277
+// { dg-options -std=c++0x }
+
+struct S { int s; };
+template <int N>
+void foo ()
+{
+  S s;
+  decltype (s.s) i;
+}