]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/42277 (decltype error in template)
authorJason Merrill <jason@redhat.com>
Fri, 4 Dec 2009 22:51:12 +0000 (17:51 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 4 Dec 2009 22:51:12 +0000 (17:51 -0500)
PR c++/42277
* semantics.c (finish_decltype_type): Don't assume that op1 of a
COMPONENT_REF is always the field.
* g++.dg/cpp0x/decltype20.C: New.

From-SVN: r155002

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

index 0c96a780b782932372725054cc8dfaaa6100e759..7ec27d402a1090db14e1166b5985b1190df2dcea 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 4c3628034b3e4239e6744b8c2516700225f1f003..841efc8fafc6d8cd608dfcfaf403ddb8fb275fa0 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 b20ddd2fdcf595d8973fac3c31fb53217ccd8ebf..ed866cf019996a9979afd4bc22df75e757e79509 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;
+}