[clang] c32d261 - Don't diagnose a redeclaration of a deduction guide if the prior

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 12 10:29:14 PDT 2020


Author: Richard Smith
Date: 2020-06-12T10:29:01-07:00
New Revision: c32d261e27c8c63653799fa6e411c373bd81d519

URL: https://github.com/llvm/llvm-project/commit/c32d261e27c8c63653799fa6e411c373bd81d519
DIFF: https://github.com/llvm/llvm-project/commit/c32d261e27c8c63653799fa6e411c373bd81d519.diff

LOG: Don't diagnose a redeclaration of a deduction guide if the prior
declaration is not visible.

In passing, add a test for a similar case of conflicting redeclarations
of internal-linkage structured bindings. (This case already works).

Added: 
    clang/test/Modules/Inputs/cxx17/unimported.h
    clang/test/Modules/Inputs/cxx20/decls.h
    clang/test/Modules/Inputs/cxx20/module.modulemap
    clang/test/Modules/Inputs/cxx20/unimported.h
    clang/test/Modules/cxx20.cpp

Modified: 
    clang/lib/Sema/SemaDeclCXX.cpp
    clang/test/Modules/Inputs/cxx17/module.modulemap
    clang/test/Modules/cxx17.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index a77f7a460242..f1ade752e2fe 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -678,7 +678,7 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old,
   //   for the same class template shall not have equivalent
   //   parameter-declaration-clauses.
   if (isa<CXXDeductionGuideDecl>(New) &&
-      !New->isFunctionTemplateSpecialization()) {
+      !New->isFunctionTemplateSpecialization() && isVisible(Old)) {
     Diag(New->getLocation(), diag::err_deduction_guide_redeclared);
     Diag(Old->getLocation(), diag::note_previous_declaration);
   }

diff  --git a/clang/test/Modules/Inputs/cxx17/module.modulemap b/clang/test/Modules/Inputs/cxx17/module.modulemap
index 2339e49e03bd..c80e6e7b13eb 100644
--- a/clang/test/Modules/Inputs/cxx17/module.modulemap
+++ b/clang/test/Modules/Inputs/cxx17/module.modulemap
@@ -1 +1,4 @@
-module Decls { header "decls.h" }
+module Decls {
+  header "decls.h"
+  explicit module Unimported { header "unimported.h" }
+}

diff  --git a/clang/test/Modules/Inputs/cxx17/unimported.h b/clang/test/Modules/Inputs/cxx17/unimported.h
new file mode 100644
index 000000000000..97c75e635d83
--- /dev/null
+++ b/clang/test/Modules/Inputs/cxx17/unimported.h
@@ -0,0 +1,2 @@
+template<typename T> struct DeductionGuide {};
+DeductionGuide() -> DeductionGuide<int>;

diff  --git a/clang/test/Modules/Inputs/cxx20/decls.h b/clang/test/Modules/Inputs/cxx20/decls.h
new file mode 100644
index 000000000000..e69de29bb2d1

diff  --git a/clang/test/Modules/Inputs/cxx20/module.modulemap b/clang/test/Modules/Inputs/cxx20/module.modulemap
new file mode 100644
index 000000000000..c80e6e7b13eb
--- /dev/null
+++ b/clang/test/Modules/Inputs/cxx20/module.modulemap
@@ -0,0 +1,4 @@
+module Decls {
+  header "decls.h"
+  explicit module Unimported { header "unimported.h" }
+}

diff  --git a/clang/test/Modules/Inputs/cxx20/unimported.h b/clang/test/Modules/Inputs/cxx20/unimported.h
new file mode 100644
index 000000000000..226b087c0848
--- /dev/null
+++ b/clang/test/Modules/Inputs/cxx20/unimported.h
@@ -0,0 +1,4 @@
+namespace StructuredBinding {
+  struct Q { int p, q; };
+  static auto [a, b] = Q();
+}

diff  --git a/clang/test/Modules/cxx17.cpp b/clang/test/Modules/cxx17.cpp
index 1efb490828db..87039ef76656 100644
--- a/clang/test/Modules/cxx17.cpp
+++ b/clang/test/Modules/cxx17.cpp
@@ -9,3 +9,7 @@ struct MergeExceptionSpec {
 #include "decls.h"
 
 MergeExceptionSpec mergeExceptionSpec2;
+
+template<typename T> struct DeductionGuide {};
+DeductionGuide() -> DeductionGuide<int>;
+DeductionGuide a;

diff  --git a/clang/test/Modules/cxx20.cpp b/clang/test/Modules/cxx20.cpp
new file mode 100644
index 000000000000..e85bc9ad8a8f
--- /dev/null
+++ b/clang/test/Modules/cxx20.cpp
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x c++ -std=c++20 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs/cxx20 %s -verify -fno-modules-error-recovery
+
+// expected-no-diagnostics
+
+#include "decls.h"
+
+namespace StructuredBinding {
+  struct R { int x, y; };
+  static auto [a, b] = R();
+}


        


More information about the cfe-commits mailing list