In the linked testcase, we're erroring because the declared return types
of the functions do not appear to match. This is because when merging
the deduced return types for 'foo' in 'auto-5_b.C', we overwrote the
return type for the declaration with the deduced return type from
'auto-5_a.C' but neglected to track that we were originally declared
with 'auto'.
As a drive-by improvement to QOI, also add checks for if the deduced
return types do not match; this is currently useful because we do not
check the equivalence of the bodies of functions yet.
PR c++/118049
gcc/cp/ChangeLog:
* module.cc (trees_in::is_matching_decl): Propagate
FNDECL_USED_AUTO as well.
gcc/testsuite/ChangeLog:
* g++.dg/modules/auto-5_a.C: New test.
* g++.dg/modules/auto-5_b.C: New test.
* g++.dg/modules/auto-5_c.C: New test.
* g++.dg/modules/auto-6_a.H: New test.
* g++.dg/modules/auto-6_b.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
(cherry picked from commit
f054c36c4fcb693e04411dc691ef4172479143d6)
{
dump (dumper::MERGE)
&& dump ("Propagating deduced return type to %N", existing);
+ FNDECL_USED_AUTO (e_inner) = true;
+ DECL_SAVED_AUTO_RETURN_TYPE (existing) = TREE_TYPE (e_type);
TREE_TYPE (existing) = change_return_type (TREE_TYPE (d_type), e_type);
}
+ else if (type_uses_auto (d_ret)
+ && !same_type_p (TREE_TYPE (d_type), TREE_TYPE (e_type)))
+ goto mismatch;
}
else if (is_typedef)
{
--- /dev/null
+// PR c++/118049
+// { dg-additional-options "-fmodules-ts -Wno-global-module" }
+// { dg-module-cmi A }
+
+module;
+template <typename T> struct S {
+ auto foo() {}
+};
+export module A;
+template struct S<char>;
--- /dev/null
+// PR c++/118049
+// { dg-additional-options "-fmodules-ts -Wno-global-module" }
+// { dg-module-cmi B }
+
+module;
+template <typename T> struct S {
+ auto foo() {}
+};
+template struct S<char>;
+export module B;
+import A;
+template <typename> void x() {
+ S<char>{}.foo();
+}
--- /dev/null
+// PR c++/118049
+// { dg-additional-options "-fmodules-ts -fno-module-lazy" }
+
+import B;
--- /dev/null
+// { dg-additional-options "-fmodule-header" }
+
+inline auto foo() {
+ return 1;
+}
--- /dev/null
+// { dg-additional-options "-fmodules-ts -fno-module-lazy" }
+
+inline auto foo() { // { dg-error "conflicting" }
+ return 1.0;
+}
+import "auto-6_a.H";