On 2/22/26 5:34 AM, Jakub Jelinek wrote:
Hi!
The following testcase is rejected since my recent convert_nontype_argument
change, but only in C++11/14 modes.
The problem is that C++17 says that all NTTPs should be converted constant
expressions, but C++11 only said that for integral and enumeration ones and
something that applied to the decltype(nullptr) case was
- a constant expression that evaluates to a null pointer value
The problem is that for NULLPTR_TYPE_P for C++11/14, we just never called
maybe_constant_value, so obviously just making sure it is integer_zerop and
without tf_error returning NULL_TREE otherwise changes behavior on valid
programs, we really need to constant evaluate it first.
The following patch fixes that.
I'm afraid I actually don't know what exactly C++14 specifies, whether I've
grabbed a pre-C++14 or post-C++14 draft, which looked like the C++17
wording. So, if C++14 needs something different, we'll need a further
change, but this at least fixes the regression.
This looks right to me.
For future reference: https://timsong-cpp.github.io/cppwp/n4140/
Bootstrapped/regtested on x86_64-linux, ok for trunk>
OK.
2026-02-21 Jakub Jelinek <[email protected]>
PR c++/124173
* pt.cc (convert_nontype_argument): For C++11/C++14 handle
NULLPTR_TYPE_P non-type arguments like TYPE_PTR_P.
* g++.dg/cpp0x/pr124173.C: New test.
--- gcc/cp/pt.cc.jj 2026-02-20 13:29:35.824439071 +0100
+++ gcc/cp/pt.cc 2026-02-20 20:13:05.074572910 +0100
@@ -7690,10 +7690,12 @@ convert_nontype_argument (tree type, tre
/* EXPR may have become value-dependent. */
val_dep_p = value_dependent_expression_p (expr);
}
- else if (TYPE_PTR_OR_PTRMEM_P (type))
+ else if (TYPE_PTR_OR_PTRMEM_P (type)
+ || NULLPTR_TYPE_P (type))
{
tree folded = maybe_constant_value (expr, NULL_TREE, mce_true);
- if (TYPE_PTR_P (type) ? integer_zerop (folded)
+ if ((TYPE_PTR_P (type) || NULLPTR_TYPE_P (type))
+ ? integer_zerop (folded)
: null_member_pointer_value_p (folded))
expr = folded;
}
--- gcc/testsuite/g++.dg/cpp0x/pr124173.C.jj 2026-02-20 20:29:26.948958968
+0100
+++ gcc/testsuite/g++.dg/cpp0x/pr124173.C 2026-02-20 20:28:30.846049284
+0100
@@ -0,0 +1,15 @@
+// PR c++/124173
+// { dg-do compile { target c++11 } }
+
+template <decltype (nullptr)>
+void
+foo ()
+{
+}
+
+int
+main ()
+{
+ constexpr decltype (nullptr) t = nullptr;
+ foo <t> ();
+}
Jakub