Pushing into the right access scope isn't enough if we defer the check
until after we leave the scope...
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 31d44658775ceaedddefbeac8c7ea735be8f3576
Author: Jason Merrill <ja...@redhat.com>
Date: Tue Jan 22 10:50:53 2013 -0500
PR c++/56071
* pt.c (maybe_instantiate_noexcept): Don't defer access checks.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index e38aca6..01d4295 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -18429,12 +18429,14 @@ maybe_instantiate_noexcept (tree fn)
if (push_tinst_level (fn))
{
push_access_scope (fn);
+ push_deferring_access_checks (dk_no_deferred);
input_location = DECL_SOURCE_LOCATION (fn);
noex = tsubst_copy_and_build (DEFERRED_NOEXCEPT_PATTERN (noex),
DEFERRED_NOEXCEPT_ARGS (noex),
tf_warning_or_error, fn,
/*function_p=*/false,
/*integral_constant_expression_p=*/true);
+ pop_deferring_access_checks ();
pop_access_scope (fn);
pop_tinst_level ();
spec = build_noexcept_spec (noex, tf_warning_or_error);
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept20.C b/gcc/testsuite/g++.dg/cpp0x/noexcept20.C
new file mode 100644
index 0000000..b867602
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/noexcept20.C
@@ -0,0 +1,22 @@
+// PR c++/56071
+// { dg-options -std=c++11 }
+
+class B
+{
+ template <typename T> friend struct A;
+ B() {}
+};
+
+template <typename T>
+struct A
+{
+ A() noexcept(noexcept(B())) { }
+};
+
+struct C
+{
+ C()
+ {
+ static_assert( !noexcept(A<int>()), "" );
+ }
+};