On 3/9/26 9:36 AM, Marek Polacek wrote:
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
LGTM, but I'd like David to comment as well.
-- >8 --
As discussed in
<https://gcc.gnu.org/pipermail/gcc-patches/2026-March/710075.html>
we shouldn't override complain with tf_warning_or_error when we are
emitting cp_printer diagnostics. We had no way to check that so
this patch adds emitting_diagnostic_p.
PR c++/124397
gcc/cp/ChangeLog:
* pt.cc (tsubst_lambda_expr): Don't override complain when emitting
diagnostics.
gcc/ChangeLog:
* diagnostic.h (emitting_diagnostic_p): New.
* diagnostics/context.h (context::emitting_diagnostic_p): New.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/lambda-uneval30.C: New test.
---
gcc/cp/pt.cc | 3 ++-
gcc/diagnostic.h | 6 ++++++
gcc/diagnostics/context.h | 5 +++++
gcc/testsuite/g++.dg/cpp2a/lambda-uneval30.C | 11 +++++++++++
4 files changed, 24 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-uneval30.C
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index ddf492b3435..3a9fc488e72 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -21049,7 +21049,8 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t
complain, tree in_decl)
/* [temp.deduct] A lambda-expression appearing in a function type or a
template parameter is not considered part of the immediate context for
the purposes of template argument deduction. */
- complain = tf_warning_or_error;
+ if (!emitting_diagnostic_p ())
+ complain = tf_warning_or_error;
tree saved = DECL_SAVED_TREE (oldfn);
if (TREE_CODE (saved) == BIND_EXPR && BIND_EXPR_BODY_BLOCK (saved))
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index da9eb7d8c3c..37e48d77187 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -272,6 +272,12 @@ option_unspecified_p (diagnostics::option_id opt_id)
return global_dc->option_unspecified_p (opt_id);
}
+inline bool
+emitting_diagnostic_p ()
+{
+ return global_dc->emitting_diagnostic_p ();
+}
+
namespace diagnostics {
/* Compute the number of digits in the decimal representation of an integer. */
diff --git a/gcc/diagnostics/context.h b/gcc/diagnostics/context.h
index 514ff1e68f9..dcfb80760b6 100644
--- a/gcc/diagnostics/context.h
+++ b/gcc/diagnostics/context.h
@@ -313,6 +313,11 @@ public:
return m_option_classifier.option_unspecified_p (opt_id);
}
+ bool emitting_diagnostic_p () const
+ {
+ return m_lock > 0;
+ }
+
bool emit_diagnostic_with_group (enum kind kind,
rich_location &richloc,
const metadata *metadata,
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-uneval30.C
b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval30.C
new file mode 100644
index 00000000000..f6beb12faab
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-uneval30.C
@@ -0,0 +1,11 @@
+// PR c++/124397
+// { dg-do compile { target c++20 } }
+
+template <class T>
+auto f(T) -> decltype([]() { T::invalid; } ()); // { dg-error "'invalid' is not a
member of 'int'" }
+template<typename T>
+void f(T, ...);
+
+void d() {
+ f(0); // { dg-error "ambiguous" }
+}
base-commit: 6c5de6335f5da035911d481c6d52de21596a8bed