On 8/15/25 3:38 AM, Jakub Jelinek wrote:
Hi!

The following patch adds some testcases for the default argument (function
and template) part of the paper, making sure we diagnose multiple defargs
in the same TU and when visible in modules and DTRT when some aren't visible
and some are visible and they are equal.  Not testing when they are
different since that is IFNDR.

Tested on x86_64-linux and i686-linux, ok for trunk?

2025-08-15  Jakub Jelinek  <ja...@redhat.com>

        PR c++/121552
        * g++.dg/parse/defarg21.C: New test.
        * g++.dg/template/defarg24.C: New test.
        * g++.dg/modules/default-arg-4_a.C: New test.
        * g++.dg/modules/default-arg-4_b.C: New test.
        * g++.dg/modules/default-arg-5_a.C: New test.
        * g++.dg/modules/default-arg-5_b.C: New test.

--- gcc/testsuite/g++.dg/parse/defarg21.C.jj    2025-08-15 11:17:39.446828030 
+0200
+++ gcc/testsuite/g++.dg/parse/defarg21.C       2025-08-15 11:17:33.679900471 
+0200
@@ -0,0 +1,38 @@
+// C++20 P1766R1 - Mitigating minor modules maladies
+// { dg-do compile }
+
+int f1 (int);
+int f1 (int = 42);
+int f2 (int);
+int f2 (int = 42);             // { dg-message "previous specification in 'int 
f2\\\(int\\\)' here" }
+int f2 (int = 42);             // { dg-error "default argument given for parameter 
1 of 'int f2\\\(int\\\)'" }
+int f3 (int = 42);             // { dg-message "previous specification in 'int 
f3\\\(int\\\)' here" }
+int f3 (int = 43);             // { dg-error "default argument given for parameter 
1 of 'int f3\\\(int\\\)'" }
+namespace A
+{
+  int f4 (int = 1);            // { dg-message "previous specification in 'int 
A::f4\\\(int\\\)' here" }
+  int f5 (int = 1);            // { dg-message "previous specification in 'int 
A::f5\\\(int\\\)' here" }
+}
+namespace A
+{
+  int f4 (int = 1);            // { dg-error "default argument given for parameter 
1 of 'int A::f4\\\(int\\\)'" }
+  int f5 (int = 2);            // { dg-error "default argument given for parameter 
1 of 'int A::f5\\\(int\\\)'" }
+}
+template <int N>
+int f6 (long = 42L);
+template <int N>
+int f6 (long = 42L);           // { dg-error "redeclaration of 'template<int N> int 
f6\\\(long int\\\)' may not have default arguments" }
+
+void
+foo ()
+{
+  int f7 (int = 42);           // { dg-message "previous specification in 'int 
f7\\\(int\\\)' here" }
+  int f7 (int = 42);           // { dg-error "default argument given for parameter 
1 of 'int f7\\\(int\\\)'" }
+  int f8 (int = 42);
+  {
+    int f8 (int = 42);
+    {
+      int f8 (int = 43);

Hmm, it's unclear to me whether this is valid after P1766. Specifically, I'm not sure what "in a given scope" means -- inhabited scope, or target scope? I suppose we want to read it as inhabited and thus allow this; I think changing the defarg in a local definition is actually a deliberate feature, and local externs are ill-formed in a module anyway.

So, the patch is OK.

Jason

Reply via email to