diff options
author | Marek Polacek <polacek@redhat.com> | 2020-05-11 18:28:19 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2020-05-13 16:25:39 -0400 |
commit | 661232da72d29f8f2385d5f588727beb74360144 (patch) | |
tree | f63a667eaf35b44b41cdf78ad8b451b16b083ada | |
parent | 7040894c4441fd3f9a39b0dd2d7b640e8e85808a (diff) | |
download | gcc-661232da72d29f8f2385d5f588727beb74360144.zip gcc-661232da72d29f8f2385d5f588727beb74360144.tar.gz gcc-661232da72d29f8f2385d5f588727beb74360144.tar.bz2 |
c++: explicit(bool) malfunction with dependent expression [PR95066]
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.
PR c++/95066
* decl.c (duplicate_decls): Set DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P.
* g++.dg/cpp2a/explicit16.C: New test.
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/decl.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp2a/explicit16.C | 21 |
4 files changed, 33 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2e53514..145a5d5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2020-05-13 Marek Polacek <polacek@redhat.com> + + PR c++/95066 + * decl.c (duplicate_decls): Set DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P. + 2020-05-13 Nathan Sidwell <nathan@acm.org> * pt.c (template_args_equal): Reorder category checking for diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 37ab481..7c7ca1f 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/ChangeLog b/gcc/testsuite/ChangeLog index cd1fa6e..e2dea4d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-05-13 Marek Polacek <polacek@redhat.com> + + PR c++/95066 + * g++.dg/cpp2a/explicit16.C: New test. + 2020-05-13 Jason Merrill <jason@redhat.com> * lib/target-supports.exp (check_effective_target_c++20_only) diff --git a/gcc/testsuite/g++.dg/cpp2a/explicit16.C b/gcc/testsuite/g++.dg/cpp2a/explicit16.C new file mode 100644 index 0000000..9d95b0d --- /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" } +} |