On 1/18/25 10:16 PM, Nathaniel Shead wrote:
On Fri, Jan 17, 2025 at 11:35:19AM -0500, Patrick Palka wrote:
On Fri, 17 Jan 2025, Nathaniel Shead wrote:

Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk?

-- >8 --

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'.

Is this a regression caused by the PR114795 fix?  Maybe we should
backport this.


I don't think it's a regression, rather just a case that was missed by
the original fix; the testcase doesn't work without PR114795 fix either.
That said backporting could be reasonable as I feel this is a pretty
safe change.

OK.


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 <nathanielosh...@gmail.com>
---
  gcc/cp/module.cc                        |  5 +++++
  gcc/testsuite/g++.dg/modules/auto-5_a.C | 10 ++++++++++
  gcc/testsuite/g++.dg/modules/auto-5_b.C | 14 ++++++++++++++
  gcc/testsuite/g++.dg/modules/auto-5_c.C |  4 ++++
  gcc/testsuite/g++.dg/modules/auto-6_a.H |  5 +++++
  gcc/testsuite/g++.dg/modules/auto-6_b.C |  6 ++++++
  6 files changed, 44 insertions(+)
  create mode 100644 gcc/testsuite/g++.dg/modules/auto-5_a.C
  create mode 100644 gcc/testsuite/g++.dg/modules/auto-5_b.C
  create mode 100644 gcc/testsuite/g++.dg/modules/auto-5_c.C
  create mode 100644 gcc/testsuite/g++.dg/modules/auto-6_a.H
  create mode 100644 gcc/testsuite/g++.dg/modules/auto-6_b.C

diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 61116fe7669..6fe64bb538c 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -11902,8 +11902,13 @@ trees_in::is_matching_decl (tree existing, tree decl, 
bool is_typedef)
        {
          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)
      {
diff --git a/gcc/testsuite/g++.dg/modules/auto-5_a.C 
b/gcc/testsuite/g++.dg/modules/auto-5_a.C
new file mode 100644
index 00000000000..fcab6f301e1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/auto-5_a.C
@@ -0,0 +1,10 @@
+// PR c++/118049
+// { dg-additional-options "-fmodules -Wno-global-module" }
+// { dg-module-cmi A }
+
+module;
+template <typename T> struct S {
+  auto foo() {}
+};
+export module A;
+template struct S<char>;
diff --git a/gcc/testsuite/g++.dg/modules/auto-5_b.C 
b/gcc/testsuite/g++.dg/modules/auto-5_b.C
new file mode 100644
index 00000000000..f75ed2d0f0c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/auto-5_b.C
@@ -0,0 +1,14 @@
+// PR c++/118049
+// { dg-additional-options "-fmodules -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();
+}
diff --git a/gcc/testsuite/g++.dg/modules/auto-5_c.C 
b/gcc/testsuite/g++.dg/modules/auto-5_c.C
new file mode 100644
index 00000000000..f351c2b1ae4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/auto-5_c.C
@@ -0,0 +1,4 @@
+// PR c++/118049
+// { dg-additional-options "-fmodules -fno-module-lazy 
-fdump-lang-module-alias" }
+
+import B;
diff --git a/gcc/testsuite/g++.dg/modules/auto-6_a.H 
b/gcc/testsuite/g++.dg/modules/auto-6_a.H
new file mode 100644
index 00000000000..3ad08ab81ce
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/auto-6_a.H
@@ -0,0 +1,5 @@
+// { dg-additional-options "-fmodule-header" }
+
+inline auto foo() {
+  return 1;
+}
diff --git a/gcc/testsuite/g++.dg/modules/auto-6_b.C 
b/gcc/testsuite/g++.dg/modules/auto-6_b.C
new file mode 100644
index 00000000000..aab7be4e530
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/auto-6_b.C
@@ -0,0 +1,6 @@
+// { dg-additional-options "-fmodules-ts -fno-module-lazy" }
+
+inline auto foo() {  // { dg-error "conflicting" }
+  return 1.0;
+}
+import "auto-6_a.H";
--
2.47.0





Reply via email to