public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: explicit() ignored on deduction guide [PR100065]
@ 2021-06-08  0:06 Marek Polacek
  2021-06-08 21:30 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2021-06-08  0:06 UTC (permalink / raw)
  To: Jason Merrill, GCC Patches

When we have explicit() with a value-dependent argument, we can't
evaluate it at parsing time, so cp_parser_function_specifier_opt stashes
the argument into the decl-specifiers and grokdeclarator then stores it
into explicit_specifier_map, which is then used when substituting the
function decl.  grokdeclarator stores it for constructors and conversion
functions, but we also need to do it for deduction guides, otherwise
we'll forget that we've seen an explicit-specifier as in the attached
test.

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

	PR c++/100065

gcc/cp/ChangeLog:

	* decl.c (grokdeclarator): Store a value-dependent
	explicit-specifier even for deduction guides.

gcc/testsuite/ChangeLog:

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

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a3687dbb0dd..cbf647dd569 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -14043,6 +14043,8 @@ grokdeclarator (const cp_declarator *declarator,
 		storage_class = sc_none;
 	      }
 	  }
+	if (declspecs->explicit_specifier)
+	  store_explicit_specifier (decl, declspecs->explicit_specifier);
       }
     else
       {
diff --git a/gcc/testsuite/g++.dg/cpp2a/explicit18.C b/gcc/testsuite/g++.dg/cpp2a/explicit18.C
new file mode 100644
index 00000000000..c8916fa4743
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/explicit18.C
@@ -0,0 +1,23 @@
+// PR c++/100065
+// { dg-do compile { target c++20 } }
+
+template<bool B>
+struct bool_constant {
+  static constexpr bool value = B;
+  constexpr operator bool() const { return value; }
+};
+
+using true_type = bool_constant<true>;
+using false_type = bool_constant<false>;
+
+template<bool>
+struct X {
+    template<typename T>
+    X(T);
+};
+
+template<bool b>
+explicit(b) X(bool_constant<b>) -> X<b>;
+
+X false_ = false_type{}; // OK
+X true_  = true_type{};  // { dg-error "explicit deduction guide" }

base-commit: e89759fdfc80db223bd852aba937acb2d7c2cd80
-- 
2.31.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++: explicit() ignored on deduction guide [PR100065]
  2021-06-08  0:06 [PATCH] c++: explicit() ignored on deduction guide [PR100065] Marek Polacek
@ 2021-06-08 21:30 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2021-06-08 21:30 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches

On 6/7/21 8:06 PM, Marek Polacek wrote:
> When we have explicit() with a value-dependent argument, we can't
> evaluate it at parsing time, so cp_parser_function_specifier_opt stashes
> the argument into the decl-specifiers and grokdeclarator then stores it
> into explicit_specifier_map, which is then used when substituting the
> function decl.  grokdeclarator stores it for constructors and conversion
> functions, but we also need to do it for deduction guides, otherwise
> we'll forget that we've seen an explicit-specifier as in the attached
> test.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/branches?

OK.

> 	PR c++/100065
> 
> gcc/cp/ChangeLog:
> 
> 	* decl.c (grokdeclarator): Store a value-dependent
> 	explicit-specifier even for deduction guides.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp2a/explicit18.C: New test.
> ---
>   gcc/cp/decl.c                           |  2 ++
>   gcc/testsuite/g++.dg/cpp2a/explicit18.C | 23 +++++++++++++++++++++++
>   2 files changed, 25 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/explicit18.C
> 
> diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
> index a3687dbb0dd..cbf647dd569 100644
> --- a/gcc/cp/decl.c
> +++ b/gcc/cp/decl.c
> @@ -14043,6 +14043,8 @@ grokdeclarator (const cp_declarator *declarator,
>   		storage_class = sc_none;
>   	      }
>   	  }
> +	if (declspecs->explicit_specifier)
> +	  store_explicit_specifier (decl, declspecs->explicit_specifier);
>         }
>       else
>         {
> diff --git a/gcc/testsuite/g++.dg/cpp2a/explicit18.C b/gcc/testsuite/g++.dg/cpp2a/explicit18.C
> new file mode 100644
> index 00000000000..c8916fa4743
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/explicit18.C
> @@ -0,0 +1,23 @@
> +// PR c++/100065
> +// { dg-do compile { target c++20 } }
> +
> +template<bool B>
> +struct bool_constant {
> +  static constexpr bool value = B;
> +  constexpr operator bool() const { return value; }
> +};
> +
> +using true_type = bool_constant<true>;
> +using false_type = bool_constant<false>;
> +
> +template<bool>
> +struct X {
> +    template<typename T>
> +    X(T);
> +};
> +
> +template<bool b>
> +explicit(b) X(bool_constant<b>) -> X<b>;
> +
> +X false_ = false_type{}; // OK
> +X true_  = true_type{};  // { dg-error "explicit deduction guide" }
> 
> base-commit: e89759fdfc80db223bd852aba937acb2d7c2cd80
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-08 21:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-08  0:06 [PATCH] c++: explicit() ignored on deduction guide [PR100065] Marek Polacek
2021-06-08 21:30 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).