On 2/17/26 3:04 PM, Jakub Jelinek wrote:
Hi!

The following testcase ICEs in C++ 20 and older, because during
diagnostics dump_template_bindings attempts to tsubst with tf_none
something and we try to emit a pedwarn during that.
While the pedwarn could be just guarded with if (complain & tf_warning),
I thought we shouldn't support extensions for tf_none and should
instead return error_mark_node.

The following patch does that.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.


2026-02-17  Jakub Jelinek  <[email protected]>

        PR c++/120685
        * typeck2.cc (build_functional_cast_1): For C++23 auto(x)
        without tf_warning or tf_error return error_mark_node instead of
        emitting pedwarn and handling it.
        * semantics.cc (finish_compound_literal): Similarly for C++26
        auto{x}.

        * g++.dg/cpp23/auto-fncast19.C: New test.

--- gcc/cp/typeck2.cc.jj        2026-02-06 11:18:47.091639968 +0100
+++ gcc/cp/typeck2.cc   2026-02-16 11:27:50.385010224 +0100
@@ -2610,9 +2610,13 @@ build_functional_cast_1 (location_t loc,
              return error_mark_node;
            }
          else if (cxx_dialect < cxx23)
-           pedwarn (loc, OPT_Wc__23_extensions,
-                    "%<auto(x)%> only available with "
-                    "%<-std=c++23%> or %<-std=gnu++23%>");
+           {
+             if ((complain & tf_warning_or_error) == 0)
+               return error_mark_node;
+             pedwarn (loc, OPT_Wc__23_extensions,
+                      "%<auto(x)%> only available with "
+                      "%<-std=c++23%> or %<-std=gnu++23%>");
+           }
        }
        else
        {
--- gcc/cp/semantics.cc.jj      2026-02-12 18:49:18.465869495 +0100
+++ gcc/cp/semantics.cc 2026-02-16 11:28:28.803359539 +0100
@@ -3874,9 +3874,13 @@ finish_compound_literal (tree type, tree
          return error_mark_node;
        }
        else if (cxx_dialect < cxx23)
-       pedwarn (input_location, OPT_Wc__23_extensions,
-                "%<auto{x}%> only available with "
-                "%<-std=c++23%> or %<-std=gnu++23%>");
+       {
+         if ((complain & tf_warning_or_error) == 0)
+           return error_mark_node;
+         pedwarn (input_location, OPT_Wc__23_extensions,
+                  "%<auto{x}%> only available with "
+                  "%<-std=c++23%> or %<-std=gnu++23%>");
+       }
        type = do_auto_deduction (type, compound_literal, type, complain,
                                adc_variable_type);
        if (type == error_mark_node)
--- gcc/testsuite/g++.dg/cpp23/auto-fncast19.C.jj       2026-02-16 
11:43:24.524190997 +0100
+++ gcc/testsuite/g++.dg/cpp23/auto-fncast19.C  2026-02-16 11:42:24.750203226 
+0100
@@ -0,0 +1,12 @@
+// PR c++/120685
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+template <typename T>
+void foo (decltype (auto (T ())) x) {} // { dg-warning "'auto\\\(x\\\)' only available 
with" "" { target c++20_down } }
+
+int
+main ()
+{
+  foo <int> (1);                 // { dg-error "no matching function for call to 
'foo<int>\\\(int\\\)'" "" { target c++20_down } }
+}

        Jakub


Reply via email to