/* Similarly if EXISTING has an undeduced return type, but DECL's
is already deduced. */
- if (undeduced_auto_decl (existing) && !undeduced_auto_decl (decl))
+ bool e_undeduced = undeduced_auto_decl (existing);
+ bool d_undeduced = undeduced_auto_decl (decl);
+ if (e_undeduced && !d_undeduced)
{
dump (dumper::MERGE)
&& dump ("Propagating deduced return type to %N", existing);
DECL_SAVED_AUTO_RETURN_TYPE (existing) = TREE_TYPE (e_type);
TREE_TYPE (existing) = change_return_type (TREE_TYPE (d_type), e_type);
}
+ else if (d_undeduced && !e_undeduced)
+ /* EXISTING was deduced, leave it alone. */;
else if (type_uses_auto (d_ret)
&& !same_type_p (TREE_TYPE (d_type), TREE_TYPE (e_type)))
{
--- /dev/null
+// PR c++/124735
+// { dg-additional-options "-fmodules" }
+
+struct S {
+ auto foo();
+};
+
+auto S::foo() { return 123; }
+auto pfn = &S::foo;
+
+import "auto-8_a.H";
+
+int main() {
+ return S{}.foo() != 123;
+}