]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Fix up convert_nontype_argument [PR124070]
authorJakub Jelinek <jakub@redhat.com>
Thu, 19 Feb 2026 06:55:38 +0000 (07:55 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 19 Feb 2026 06:55:38 +0000 (07:55 +0100)
commitcb617bedc8fe8008980841e019f7bddd1cc296ee
tree60c9b3af0df9da09d9dcef2b94728cfaf713a52e
parent3cd83779574847957bf341f02b601a71d672bb0b
c++: Fix up convert_nontype_argument [PR124070]

Some of the following testcases are incorrectly accepted.
The problem is in convert_nontype_argument.  It just does
maybe_constant_value earlier.  Later on for integral/enum/floating
point args it uses cxx_constant_value for complain & tf_error if
not val_dep_p and expr is not a simple constant, similarly for
class type it calls
      /* Replace the argument with a reference to the corresponding template
         parameter object.  */
      if (!val_dep_p)
        expr = create_template_parm_object (expr, complain);
      if (expr == error_mark_node)
        return NULL_TREE;
etc.  But for NULLPTR_TYPE_P and REFLECTION_TYPE_P cases (I bet
Marek has based the latter on the former) it only verifies the type
and not the actual expression.
I think we need to do that, because if maybe_constant_value fails, it
just returns the passed in argument and if nothing checks it, we accept
whatever was there (and sometimes ICE later).

The following patch implements that.

2026-02-19  Jakub Jelinek  <jakub@redhat.com>

PR c++/124070
* pt.cc (convert_nontype_argument): For NULLPTR_TYPE_P case
if expr is not integer_zerop and is not val_dep_p try harder,
for complain & tf_error use cxx_constant_value and return NULL_TREE
for error_mark_node, without tf_error return NULL_TREE.  Similarly
for REFLECTION_TYPE_P case if expr is not REFLECT_EXPR and is not
val_dep_p try harder like for NULLPTR_TYPE_P.

* g++.dg/cpp26/pr124070.C: New test.
* g++.dg/reflect/parameters_of4.C: Expect different diagnostics.
* g++.dg/reflect/define_aggregate7.C: New test.
* g++.dg/reflect/define_aggregate8.C: New test.
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp26/pr124070.C [new file with mode: 0644]
gcc/testsuite/g++.dg/reflect/define_aggregate7.C [new file with mode: 0644]
gcc/testsuite/g++.dg/reflect/define_aggregate8.C [new file with mode: 0644]
gcc/testsuite/g++.dg/reflect/parameters_of4.C