--- /dev/null
+// C++20 P1766R1 - Mitigating minor modules maladies
+// { dg-additional-options "-fmodules-ts -Wno-global-module" }
+// { dg-module-cmi M }
+
+module;
+
+int foo (int i = 42);
+template <typename T, typename U = int>
+int bar ();
+template <typename T, int N = 42>
+int baz ();
+
+export module M;
+
+export inline int
+qux ()
+{
+ return foo () + bar <int> () + baz <int> ();
+}
--- /dev/null
+// C++20 P1766R1 - Mitigating minor modules maladies
+// { dg-do run }
+// { dg-additional-options "-fmodules-ts" }
+
+import M;
+
+int
+foo (int i = 42)
+{
+ return i;
+}
+
+template <typename T, typename U = int>
+int
+bar ()
+{
+ return sizeof (U);
+}
+
+template <typename T, int N = 42>
+int
+baz ()
+{
+ return N;
+}
+
+int
+main ()
+{
+ if (foo () + bar <int> () + baz <int> () != qux ())
+ __builtin_abort ();
+ if (foo () != foo (42)
+ || bar <int> () != bar <int, int> ()
+ || baz <int> () != baz <int, 42> ())
+ __builtin_abort ();
+}
--- /dev/null
+// C++20 P1766R1 - Mitigating minor modules maladies
+// { dg-additional-options "-fmodules-ts -Wno-global-module" }
+// { dg-module-cmi M }
+
+module;
+
+int foo (int i = 42);
+template <typename T, typename U = int>
+int bar ();
+template <typename T, int N = 42>
+int baz ();
+
+export module M;
+
+export inline int
+qux ()
+{
+ return foo () + bar <int> () + baz <int> ();
+}
+
+export using ::foo;
+export using ::bar;
+export using ::baz;
--- /dev/null
+// C++20 P1766R1 - Mitigating minor modules maladies
+// { dg-additional-options "-fmodules-ts" }
+
+import M;
+
+int
+foo (int i = 42) // { dg-error "default argument given for parameter 1 of 'int foo\\\(int\\\)'" }
+{
+ return i;
+}
+
+template <typename T, typename U = int> // { dg-error "redefinition of default argument for 'class U'" }
+int
+bar ()
+{
+ return sizeof (U);
+}
+
+template <typename T, int N = 42> // { dg-error "redefinition of default argument for 'int N'" }
+int
+baz ()
+{
+ return N;
+}
+
+int
+main ()
+{
+ if (foo () + bar <int> () + baz <int> () != qux ())
+ __builtin_abort ();
+ if (foo () != foo (42)
+ || bar <int> () != bar <int, int> ()
+ || baz <int> () != baz <int, 42> ())
+ __builtin_abort ();
+}
--- /dev/null
+// 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);
+ }
+ }
+}
--- /dev/null
+// C++20 P1766R1 - Mitigating minor modules maladies
+// { dg-do compile { target c++11 } }
+
+template <int N>
+int f1 (int);
+template <int N = 42>
+int f1 (int);
+template <int N> // { dg-message "original definition appeared here" }
+int f2 (int);
+template <int N = 42>
+int f2 (int);
+template <int N = 42> // { dg-error "redefinition of default argument for 'int N'" }
+int f2 (int);
+template <int N = 42> // { dg-message "original definition appeared here" }
+int f3 (int);
+template <int N = 43> // { dg-error "redefinition of default argument for 'int N'" }
+int f3 (int);
+template <typename T>
+int f4 (int);
+template <typename T = int>
+int f4 (int);
+namespace A
+{
+ template <typename T> // { dg-message "original definition appeared here" }
+ int f5 (int);
+ template <typename T = int>
+ int f5 (int);
+ template <typename T = int> // { dg-message "original definition appeared here" }
+ int f6 (int);
+}
+namespace A
+{
+ template <typename T = int> // { dg-error "redefinition of default argument for 'class T'" }
+ int f5 (int);
+ template <typename T = long> // { dg-error "redefinition of default argument for 'class T'" }
+ int f6 (int);
+}