semantics.c (speculative_access_check): New.
authorJason Merrill <jason@redhat.com>
Thu, 4 Nov 2010 15:52:18 +0000 (11:52 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 4 Nov 2010 15:52:18 +0000 (11:52 -0400)
* semantics.c (speculative_access_check): New.
* cp-tree.h: Declare it.
* call.c (build_over_call): Use it.
* class.c (type_has_constexpr_default_constructor): Use locate_ctor.
* method.c (locate_ctor): Use push/pop_deferring_access_checks.

From-SVN: r166317

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/class.c
gcc/cp/cp-tree.h
gcc/cp/method.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-access.C [new file with mode: 0644]

index c432ca8150c9fea2dcacbc8b3fde4c38b496d0e2..ab00a0f12ff37c2cebf0607c0d1d66fcb6986c9a 100644 (file)
@@ -1,3 +1,11 @@
+2010-11-04  Jason Merrill  <jason@redhat.com>
+
+       * semantics.c (speculative_access_check): New.
+       * cp-tree.h: Declare it.
+       * call.c (build_over_call): Use it.
+       * class.c (type_has_constexpr_default_constructor): Use locate_ctor.
+       * method.c (locate_ctor): Use push/pop_deferring_access_checks.
+
 2010-11-03  Jason Merrill  <jason@redhat.com>
 
        PR c++/46293
index 4507f3d37b99485b1632f51e16c9ac3aace03f19..eb7247dad93fbde156fe1d9ff91d43cd7a265eef 100644 (file)
@@ -5823,15 +5823,9 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain)
        access_fn = fn;
       if (flags & LOOKUP_SPECULATIVE)
        {
-         /* If we're checking for implicit delete, we don't want access
-            control errors.  */
-         if (!accessible_p (cand->access_path, access_fn, true))
-           {
-             /* Unless we're under maybe_explain_implicit_delete.  */
-             if (flags & LOOKUP_COMPLAIN)
-               enforce_access (cand->access_path, access_fn, fn);
-             return error_mark_node;
-           }
+         if (!speculative_access_check (cand->access_path, access_fn, fn,
+                                        !!(flags & LOOKUP_COMPLAIN)))
+           return error_mark_node;
        }
       else
        perform_or_defer_access_check (cand->access_path, access_fn, fn);
index ded0a0399726fc85365235625acca2ef19ae8145..435fa71c3f5bb83122e6e9f2e69a601319a2e728 100644 (file)
@@ -4349,7 +4349,7 @@ type_has_constexpr_default_constructor (tree t)
     return false;
   if (CLASSTYPE_LAZY_DEFAULT_CTOR (t))
     return synthesized_default_constructor_is_constexpr (t);
-  fns = get_default_ctor (t);
+  fns = locate_ctor (t);
   return (fns && DECL_DECLARED_CONSTEXPR_P (fns));
 }
 
index fc4772d7403043c62f12dc5f64b0ad8431b16092..8f5227800f5190a843cf92936b2fcc7fb03d8520 100644 (file)
@@ -5192,6 +5192,7 @@ extern void pop_to_parent_deferring_access_checks (void);
 extern void perform_access_checks              (VEC (deferred_access_check,gc)*);
 extern void perform_deferred_access_checks     (void);
 extern void perform_or_defer_access_check      (tree, tree, tree);
+extern bool speculative_access_check           (tree, tree, tree, bool);
 extern int stmts_are_full_exprs_p              (void);
 extern void init_cp_semantics                  (void);
 extern tree do_poplevel                                (tree);
index ca5964e35ae38b3d49d5a0994c0027a494e0ee11..c1d30d476a1c3f6eb89f6158b170f13b514e572d 100644 (file)
@@ -849,8 +849,12 @@ get_dtor (tree type)
 tree
 locate_ctor (tree type)
 {
-  tree fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
-                            LOOKUP_SPECULATIVE, tf_none);
+  tree fn;
+
+  push_deferring_access_checks (dk_no_check);
+  fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
+                       LOOKUP_SPECULATIVE, tf_none);
+  pop_deferring_access_checks ();
   if (fn == error_mark_node)
     return NULL_TREE;
   return fn;
index 9061a89ed245de6ae580d064d680e4ee90542c8e..3d62cd1930631a872e16a5012175560c58da5ef5 100644 (file)
@@ -337,6 +337,30 @@ perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl)
   new_access->diag_decl = diag_decl;
 }
 
+/* Used by build_over_call in LOOKUP_SPECULATIVE mode: return whether DECL
+   is accessible in BINFO, and possibly complain if not.  If we're not
+   checking access, everything is accessible.  */
+
+bool
+speculative_access_check (tree binfo, tree decl, tree diag_decl,
+                         bool complain)
+{
+  if (deferred_access_no_check)
+    return true;
+
+  /* If we're checking for implicit delete, we don't want access
+     control errors.  */
+  if (!accessible_p (binfo, decl, true))
+    {
+      /* Unless we're under maybe_explain_implicit_delete.  */
+      if (complain)
+       enforce_access (binfo, decl, diag_decl);
+      return false;
+    }
+
+  return true;
+}
+
 /* Returns nonzero if the current statement is a full expression,
    i.e. temporaries created during that statement should be destroyed
    at the end of the statement.  */
index 6928ea0b1840693f466b5b9d3acc6f084bf33649..0fa52176934c8e63d784d3edc75e033904e8f714 100644 (file)
@@ -1,3 +1,7 @@
+2010-11-04  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/cpp0x/constexpr-access.C: New.
+
 2010-11-04  Richard Guenther  <rguenther@suse.de>
 
        PR rtl-optimization/46183
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-access.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-access.C
new file mode 100644 (file)
index 0000000..ee5fc98
--- /dev/null
@@ -0,0 +1,14 @@
+// { dg-options -std=c++0x }
+
+class base
+{
+protected:
+  constexpr base() { }
+};
+
+struct A : base { };
+
+int main()
+{
+  A a;
+}