diff options
author | Marek Polacek <polacek@redhat.com> | 2024-03-15 09:23:28 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2024-03-25 18:20:55 -0400 |
commit | 8651991fe2ea90a7276e91673b15b5c3865f14d7 (patch) | |
tree | ea04b3f801fc2a7b9cf97fb0b0bf58878dbf5e44 | |
parent | de0886d48032332d10e4acb5d15c8789b281b6fe (diff) | |
download | gcc-8651991fe2ea90a7276e91673b15b5c3865f14d7.zip gcc-8651991fe2ea90a7276e91673b15b5c3865f14d7.tar.gz gcc-8651991fe2ea90a7276e91673b15b5c3865f14d7.tar.bz2 |
c++: ICE with noexcept and local specialization, again [PR114349]
Patrick noticed that my r14-9339-gdc6c3bfb59baab patch is wrong;
we're dealing with a noexcept-spec there, not a noexcept-expr, so
setting cp_noexcept_operand et al is incorrect. Back to the drawing
board then.
To fix noexcept84.C, we should probably avoid doing push_to_top_level
in certain cases. maybe_push_to_top_level didn't work here as-is, so
I changed it to not push to top level if decl_function_context is
non-null, when we are not dealing with a lambda.
This also fixes c++/114349, introduced by r14-9339.
PR c++/114349
gcc/cp/ChangeLog:
* name-lookup.cc (maybe_push_to_top_level): For a non-lambda,
don't push to top level if decl_function_context is non-null.
* pt.cc (maybe_instantiate_noexcept): Use maybe_push_to_top_level.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/noexcept85.C: New test.
* g++.dg/cpp0x/noexcept86.C: New test.
-rw-r--r-- | gcc/cp/name-lookup.cc | 11 | ||||
-rw-r--r-- | gcc/cp/pt.cc | 11 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/noexcept85.C | 33 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/noexcept86.C | 25 |
4 files changed, 67 insertions, 13 deletions
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc index dce4caf..7af7f00 100644 --- a/gcc/cp/name-lookup.cc +++ b/gcc/cp/name-lookup.cc @@ -8664,10 +8664,13 @@ maybe_push_to_top_level (tree d) { /* Push if D isn't function-local, or is a lambda function, for which name resolution is already done. */ - bool push_to_top - = !(current_function_decl - && !LAMBDA_FUNCTION_P (d) - && decl_function_context (d) == current_function_decl); + const bool push_to_top + = (LAMBDA_FUNCTION_P (d) + || (TREE_CODE (d) == TYPE_DECL + && TREE_TYPE (d) + && LAMBDA_TYPE_P (TREE_TYPE (d))) + || !current_function_decl + || !decl_function_context (d)); if (push_to_top) push_to_top_level (); diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 8cf0d5b..7b00a86 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -26855,7 +26855,7 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain) } else if (push_tinst_level (fn)) { - push_to_top_level (); + const bool push_to_top = maybe_push_to_top_level (fn); push_access_scope (fn); push_deferring_access_checks (dk_no_deferred); input_location = DECL_SOURCE_LOCATION (fn); @@ -26878,17 +26878,10 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain) if (orig_fn) ++processing_template_decl; - ++cp_unevaluated_operand; - ++c_inhibit_evaluation_warnings; - ++cp_noexcept_operand; /* Do deferred instantiation of the noexcept-specifier. */ noex = tsubst_expr (DEFERRED_NOEXCEPT_PATTERN (noex), DEFERRED_NOEXCEPT_ARGS (noex), tf_warning_or_error, fn); - --cp_unevaluated_operand; - --c_inhibit_evaluation_warnings; - --cp_noexcept_operand; - /* Build up the noexcept-specification. */ spec = build_noexcept_spec (noex, tf_warning_or_error); @@ -26898,7 +26891,7 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain) pop_deferring_access_checks (); pop_access_scope (fn); pop_tinst_level (); - pop_from_top_level (); + maybe_pop_from_top_level (push_to_top); } else spec = noexcept_false_spec; diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept85.C b/gcc/testsuite/g++.dg/cpp0x/noexcept85.C new file mode 100644 index 0000000..b415bb4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept85.C @@ -0,0 +1,33 @@ +// PR c++/114349 +// { dg-do compile { target c++11 } } + +using A = struct {}; +template <template <typename> class, typename, typename> +using B = A; +template <typename T> +using C = typename T::D; +struct E { + using D = B<C, int, A>; +}; +template <class> constexpr bool foo (A) { return false; } +template <class T> struct F { + using G = T; + using H = E; + F(const F &); + void operator=(F) noexcept(foo <G> (H::D{})); +}; +template <typename, typename, typename> +using I = F<int>; +template <typename K, typename V, typename H = K> +using J = I<K, V, H>; +struct K { + typedef J<long, char> L; + L k; + K(); +}; +struct M { + bool bar () const; + K::L m; +}; +K n; +bool M::bar () const { n.k = m; return true; } diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept86.C b/gcc/testsuite/g++.dg/cpp0x/noexcept86.C new file mode 100644 index 0000000..2d040c0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept86.C @@ -0,0 +1,25 @@ +// PR c++/114349 +// { dg-do compile { target c++14 } } + +struct B +{ + int i; +}; + +template <bool BA> +void +goo () +{ + constexpr bool is_yes = BA; + struct C + { + static auto g(B b) noexcept(is_yes) { } + }; + C::g({}); +} + +void +x () +{ + goo<false>(); +} |