[gcc r13-9304] c++: ICE with noexcept and local specialization, again [PR114349]
Marek Polacek
mpolacek@gcc.gnu.org
Fri Jan 10 22:27:32 GMT 2025
https://gcc.gnu.org/g:0430ec8881d657ddedff6c9d9fa4ea5db125f462
commit r13-9304-g0430ec8881d657ddedff6c9d9fa4ea5db125f462
Author: Marek Polacek <polacek@redhat.com>
Date: Fri Jan 10 17:26:18 2025 -0500
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.
This GCC 13 backport squashes r14-9659 and 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/noexcept84.C: New test.
* g++.dg/cpp0x/noexcept85.C: New test.
* g++.dg/cpp0x/noexcept86.C: New test.
Diff:
---
gcc/cp/name-lookup.cc | 11 +++++++----
gcc/cp/pt.cc | 4 ++--
gcc/testsuite/g++.dg/cpp0x/noexcept84.C | 32 ++++++++++++++++++++++++++++++++
gcc/testsuite/g++.dg/cpp0x/noexcept85.C | 33 +++++++++++++++++++++++++++++++++
gcc/testsuite/g++.dg/cpp0x/noexcept86.C | 25 +++++++++++++++++++++++++
5 files changed, 99 insertions(+), 6 deletions(-)
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 7c61bc3bf611..1ea25f076b85 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -8244,10 +8244,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 5a6bf80c3d42..ddfa3c25d10e 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -26772,7 +26772,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);
@@ -26809,7 +26809,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/noexcept84.C b/gcc/testsuite/g++.dg/cpp0x/noexcept84.C
new file mode 100644
index 000000000000..06f33264f77c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/noexcept84.C
@@ -0,0 +1,32 @@
+// PR c++/114114
+// { dg-do compile { target c++11 } }
+
+template<bool B>
+constexpr void
+test ()
+{
+ constexpr bool is_yes = B;
+ struct S {
+ constexpr S() noexcept(is_yes) { }
+ };
+ S s;
+}
+
+constexpr bool foo() { return true; }
+
+template<typename T>
+constexpr void
+test2 ()
+{
+ constexpr T (*pfn)() = &foo;
+ struct S {
+ constexpr S() noexcept(pfn()) { }
+ };
+ S s;
+}
+
+int main()
+{
+ test<true>();
+ test2<bool>();
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept85.C b/gcc/testsuite/g++.dg/cpp0x/noexcept85.C
new file mode 100644
index 000000000000..b415bb46bc94
--- /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 000000000000..2d040c090f50
--- /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>();
+}
More information about the Gcc-cvs
mailing list