c++: Fix non-portable default argument of make_auto_1 [PR104197]

Message ID 20220124152740.3735632-1-ppalka@redhat.com
State Committed
Commit b1aa2a3cf1ba233ccd5a49fde85a2ca7e5f620e9
Headers
Series c++: Fix non-portable default argument of make_auto_1 [PR104197] |

Commit Message

Patrick Palka Jan. 24, 2022, 3:27 p.m. UTC
  Avoid using the macro current_template_depth, which expands to an
expression in terms of __FUNCTION__, within the signature of a function.
Clang warns about this and MSVC rejects it.

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

	PR c++/104197

gcc/cp/ChangeLog:

	* pt.cc (make_auto_1): Use -1 as a placeholder default argument
	for level.
---
 gcc/cp/pt.cc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Comments

Marek Polacek Jan. 24, 2022, 4:10 p.m. UTC | #1
On Mon, Jan 24, 2022 at 10:27:40AM -0500, Patrick Palka via Gcc-patches wrote:
> Avoid using the macro current_template_depth, which expands to an
> expression in terms of __FUNCTION__, within the signature of a function.
> Clang warns about this and MSVC rejects it.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?

LGTM.
 
> 	PR c++/104197
> 
> gcc/cp/ChangeLog:
> 
> 	* pt.cc (make_auto_1): Use -1 as a placeholder default argument
> 	for level.
> ---
>  gcc/cp/pt.cc | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index bba62a5800a..8f50b9c4d3c 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -28477,9 +28477,10 @@ make_args_non_dependent (vec<tree, va_gc> *args)
>     by default.  If set_canonical is true, we set TYPE_CANONICAL on it.  */
>  
>  static tree
> -make_auto_1 (tree name, bool set_canonical,
> -	     int level = current_template_depth + 1)
> +make_auto_1 (tree name, bool set_canonical, int level = -1)
>  {
> +  if (level == -1)
> +    level = current_template_depth + 1;
>    tree au = cxx_make_type (TEMPLATE_TYPE_PARM);
>    TYPE_NAME (au) = build_decl (input_location, TYPE_DECL, name, au);
>    TYPE_STUB_DECL (au) = TYPE_NAME (au);
> -- 
> 2.35.0.rc1
> 

Marek
  
Jason Merrill Jan. 24, 2022, 4:37 p.m. UTC | #2
On 1/24/22 10:27, Patrick Palka wrote:
> Avoid using the macro current_template_depth, which expands to an
> expression in terms of __FUNCTION__, within the signature of a function.
> Clang warns about this and MSVC rejects it.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?

OK.

> 	PR c++/104197
> 
> gcc/cp/ChangeLog:
> 
> 	* pt.cc (make_auto_1): Use -1 as a placeholder default argument
> 	for level.
> ---
>   gcc/cp/pt.cc | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index bba62a5800a..8f50b9c4d3c 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -28477,9 +28477,10 @@ make_args_non_dependent (vec<tree, va_gc> *args)
>      by default.  If set_canonical is true, we set TYPE_CANONICAL on it.  */
>   
>   static tree
> -make_auto_1 (tree name, bool set_canonical,
> -	     int level = current_template_depth + 1)
> +make_auto_1 (tree name, bool set_canonical, int level = -1)
>   {
> +  if (level == -1)
> +    level = current_template_depth + 1;
>     tree au = cxx_make_type (TEMPLATE_TYPE_PARM);
>     TYPE_NAME (au) = build_decl (input_location, TYPE_DECL, name, au);
>     TYPE_STUB_DECL (au) = TYPE_NAME (au);
  

Patch

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index bba62a5800a..8f50b9c4d3c 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -28477,9 +28477,10 @@  make_args_non_dependent (vec<tree, va_gc> *args)
    by default.  If set_canonical is true, we set TYPE_CANONICAL on it.  */
 
 static tree
-make_auto_1 (tree name, bool set_canonical,
-	     int level = current_template_depth + 1)
+make_auto_1 (tree name, bool set_canonical, int level = -1)
 {
+  if (level == -1)
+    level = current_template_depth + 1;
   tree au = cxx_make_type (TEMPLATE_TYPE_PARM);
   TYPE_NAME (au) = build_decl (input_location, TYPE_DECL, name, au);
   TYPE_STUB_DECL (au) = TYPE_NAME (au);