On 5/11/20 7:06 PM, Marek Polacek wrote:
I forgot to set DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P when merging two
function declarations and as a sad consequence, we never tsubsted
the dependent explicit-specifier in tsubst_function_decl, leading to
disregarding the explicit-specifier altogether, and wrongly accepting
this test.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/10/9?

OK.

        PR c++/95066
        * decl.c (duplicate_decls): Set DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P.

        * g++.dg/cpp2a/explicit16.C: New test.
---
  gcc/cp/decl.c                           |  2 ++
  gcc/testsuite/g++.dg/cpp2a/explicit16.C | 21 +++++++++++++++++++++
  2 files changed, 23 insertions(+)
  create mode 100644 gcc/testsuite/g++.dg/cpp2a/explicit16.C

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 1b6a5672334..604ecf42e95 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -2035,6 +2035,8 @@ duplicate_decls (tree newdecl, tree olddecl, bool 
newdecl_is_friend)
        DECL_FINAL_P (newdecl) |= DECL_FINAL_P (olddecl);
        DECL_OVERRIDE_P (newdecl) |= DECL_OVERRIDE_P (olddecl);
        DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
+      DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (newdecl)
+       |= DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (olddecl);
        if (DECL_OVERLOADED_OPERATOR_P (olddecl))
        DECL_OVERLOADED_OPERATOR_CODE_RAW (newdecl)
          = DECL_OVERLOADED_OPERATOR_CODE_RAW (olddecl);
diff --git a/gcc/testsuite/g++.dg/cpp2a/explicit16.C 
b/gcc/testsuite/g++.dg/cpp2a/explicit16.C
new file mode 100644
index 00000000000..9d95b0d669e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/explicit16.C
@@ -0,0 +1,21 @@
+// PR c++/95066 - explicit malfunction with dependent expression.
+// { dg-do compile { target c++2a } }
+
+template <typename T>
+struct Foo {
+  template <typename U>
+  explicit(static_cast<U>(true)) operator Foo<U>();
+};
+
+template <typename T>
+template <typename U>
+Foo<T>::operator Foo<U>() {
+  return {};
+}
+
+int
+main ()
+{
+  Foo<float> a;
+  Foo<int> b = a; // { dg-error "conversion" }
+}

base-commit: 840ac85ced0695fefecee433327e4298b4adb20a


Reply via email to