Re: [PATCH] c++: Make *_cast<*> parsing more robust to errors [PR108438]

2024-06-08 Thread Simon Martin
Hi Jason,

On 7 Jun 2024, at 19:30, Jason Merrill wrote:

> On 6/7/24 08:12, Simon Martin wrote:
>> We ICE upon the following when trying to emit a 
>> -Wlogical-not-parentheses
>> warning:
>>
>> === cut here ===
>> template  T foo (T arg, T& ref, T* ptr) {
>>int a = 1;
>>return static_cast(a);
>> }
>> === cut here ===
>>
>> This patch makes *_cast<*> parsing more robust by skipping to the 
>> closing '>'
>> upon error in the target type.
>>
>> Successfully tested on x86_64-pc-linux-gnu.
>>
>> (Note that I have a patch pending review that also adds 
>> g++.dg/parse/crash74.C;
>> I will obviously handle the name conflict at commit time)
>>
>>  PR c++/108438
>>
>> gcc/cp/ChangeLog:
>>
>>  * parser.cc (cp_parser_postfix_expression): Skip to the closing '>'
>>  upon error parsing the target type of *_cast<*> expressions.
>>
>> gcc/testsuite/ChangeLog:
>>
>>  * g++.dg/parse/crash74.C: New test.
>>
>> ---
>>   gcc/cp/parser.cc | 3 ++-
>>   gcc/testsuite/g++.dg/parse/crash74.C | 9 +
>>   2 files changed, 11 insertions(+), 1 deletion(-)
>>   create mode 100644 gcc/testsuite/g++.dg/parse/crash74.C
>>
>> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
>> index bc4a2359153..3516c2aa38b 100644
>> --- a/gcc/cp/parser.cc
>> +++ b/gcc/cp/parser.cc
>> @@ -7569,7 +7569,8 @@ cp_parser_postfix_expression (cp_parser 
>> *parser, bool address_p, bool cast_p,
>>NULL);
>>  parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
>>  /* Look for the closing `>'.  */
>> -cp_parser_require (parser, CPP_GREATER, RT_GREATER);
>> +if (!cp_parser_require (parser, CPP_GREATER, RT_GREATER))
>> +  cp_parser_skip_to_end_of_template_parameter_list (parser);
>
> Looks like this could use 
> cp_parser_require_end_of_template_parameter_list.
Indeed, thanks for pointing me to this function.
>
> OK with that change.
Merged with the change made via 
https://gcc.gnu.org/g:2c9643c27ecddb7f597d34009d89e932b4aca58e

-- Simon
>
> Jason


[PATCH] lto: Fix build on MacOS

2024-06-07 Thread Simon Martin
The build fails on x86_64-apple-darwin19.6.0 starting with 5b6d5a886ee because
vector is included after system.h and runs into poisoned identifiers.

This patch fixes this by defining INCLUDE_VECTOR before including system.h.

Validated by doing a full build on x86_64-apple-darwin19.6.0.

gcc/lto/ChangeLog:

* lto-partition.cc: Define INCLUDE_VECTOR to avoid running into
poisoned identifiers.

---
 gcc/lto/lto-partition.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/lto/lto-partition.cc b/gcc/lto/lto-partition.cc
index 44b457d0b2a..2238650fa0e 100644
--- a/gcc/lto/lto-partition.cc
+++ b/gcc/lto/lto-partition.cc
@@ -18,6 +18,7 @@ along with GCC; see the file COPYING3.  If not see
 .  */
 
 #include "config.h"
+#define INCLUDE_VECTOR
 #include "system.h"
 #include "coretypes.h"
 #include "target.h"
@@ -38,7 +39,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "lto-partition.h"
 
 #include 
-#include 
 
 vec ltrans_partitions;
 
-- 
2.44.0




[PATCH] c++: Make *_cast<*> parsing more robust to errors [PR108438]

2024-06-07 Thread Simon Martin
We ICE upon the following when trying to emit a -Wlogical-not-parentheses
warning:

=== cut here ===
template  T foo (T arg, T& ref, T* ptr) {
  int a = 1;
  return static_cast(a);
}
=== cut here ===

This patch makes *_cast<*> parsing more robust by skipping to the closing '>'
upon error in the target type.

Successfully tested on x86_64-pc-linux-gnu.

(Note that I have a patch pending review that also adds g++.dg/parse/crash74.C;
I will obviously handle the name conflict at commit time)

PR c++/108438

gcc/cp/ChangeLog:

* parser.cc (cp_parser_postfix_expression): Skip to the closing '>'
upon error parsing the target type of *_cast<*> expressions.

gcc/testsuite/ChangeLog:

* g++.dg/parse/crash74.C: New test.

---
 gcc/cp/parser.cc | 3 ++-
 gcc/testsuite/g++.dg/parse/crash74.C | 9 +
 2 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/parse/crash74.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index bc4a2359153..3516c2aa38b 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -7569,7 +7569,8 @@ cp_parser_postfix_expression (cp_parser *parser, bool 
address_p, bool cast_p,
  NULL);
parser->in_type_id_in_expr_p = saved_in_type_id_in_expr_p;
/* Look for the closing `>'.  */
-   cp_parser_require (parser, CPP_GREATER, RT_GREATER);
+   if (!cp_parser_require (parser, CPP_GREATER, RT_GREATER))
+ cp_parser_skip_to_end_of_template_parameter_list (parser);
/* Restore the old message.  */
parser->type_definition_forbidden_message = saved_message;
 
diff --git a/gcc/testsuite/g++.dg/parse/crash74.C 
b/gcc/testsuite/g++.dg/parse/crash74.C
new file mode 100644
index 000..81a16e35b14
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/crash74.C
@@ -0,0 +1,9 @@
+// PR c++/108438
+// { dg-options "-Wlogical-not-parentheses" }
+
+template 
+T foo (T arg, T& ref, T* ptr)
+{
+  int a = 1;
+  return static_cast(a); // { dg-error "expected" }
+}
-- 
2.44.0




Re: [PATCH] c++: Handle erroneous DECL_LOCAL_DECL_ALIAS in duplicate_decls [PR107575]

2024-06-05 Thread Simon Martin
On 5 Jun 2024, at 10:34, Jakub Jelinek wrote:

> On Wed, Jun 05, 2024 at 08:13:14AM +0000, Simon Martin wrote:
>> --- a/gcc/cp/decl.cc
>> +++ b/gcc/cp/decl.cc
>> @@ -2792,10 +2792,13 @@ duplicate_decls (tree newdecl, tree olddecl, 
>> bool hiding, bool was_hidden)
>>retrofit_lang_decl (newdecl);
>>tree alias = DECL_LOCAL_DECL_ALIAS (newdecl)
>>  = DECL_LOCAL_DECL_ALIAS (olddecl);
>> -  DECL_ATTRIBUTES (alias)
>> -= (*targetm.merge_decl_attributes) (alias, newdecl);
>> -  if (TREE_CODE (newdecl) == FUNCTION_DECL)
>> -merge_attribute_bits (newdecl, alias);
>> +  if (alias != error_mark_node)
>> +{
>> +  DECL_ATTRIBUTES (alias) =
>> +(*targetm.merge_decl_attributes) (alias, newdecl);
>
> Formatting nit, = should be on the next line, not at the end of a 
> line.
> See https://gcc.gnu.org/codingconventions.html and 
> https://gcc.gnu.org/codingconventions.html
Indeed, thanks. This is fixed in the attached updated patch.

Simon
>
>   Jakub
From e75602d3ce998307749e5022d989b564a6d19703 Mon Sep 17 00:00:00 2001
From: Simon Martin 
Date: Tue, 4 Jun 2024 21:20:23 +0200
Subject: [PATCH] c++: Handle erroneous DECL_LOCAL_DECL_ALIAS in duplicate_decls 
[PR107575]

We currently ICE upon the following because we don't properly handle local
functions with an error_mark_node as DECL_LOCAL_DECL_ALIAS in duplicate_decls.

=== cut here ===
void f (void) {
  virtual int f (void) const;
  virtual int f (void);
}
=== cut here ===

This patch fixes this by checking for error_mark_node.

Successfully tested on x86_64-pc-linux-gnu.

PR c++/107575

gcc/cp/ChangeLog:

* decl.cc (duplicate_decls): Check for error_mark_node
DECL_LOCAL_DECL_ALIAS.

gcc/testsuite/ChangeLog:

* g++.dg/parse/crash74.C: New test.

---
 gcc/cp/decl.cc   | 11 +++
 gcc/testsuite/g++.dg/parse/crash74.C | 11 +++
 2 files changed, 18 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/parse/crash74.C

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index d481e1ec074..03deb1493a4 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -2792,10 +2792,13 @@ duplicate_decls (tree newdecl, tree olddecl, bool 
hiding, bool was_hidden)
  retrofit_lang_decl (newdecl);
  tree alias = DECL_LOCAL_DECL_ALIAS (newdecl)
= DECL_LOCAL_DECL_ALIAS (olddecl);
- DECL_ATTRIBUTES (alias)
-   = (*targetm.merge_decl_attributes) (alias, newdecl);
- if (TREE_CODE (newdecl) == FUNCTION_DECL)
-   merge_attribute_bits (newdecl, alias);
+ if (alias != error_mark_node)
+   {
+ DECL_ATTRIBUTES (alias)
+   = (*targetm.merge_decl_attributes) (alias, newdecl);
+ if (TREE_CODE (newdecl) == FUNCTION_DECL)
+   merge_attribute_bits (newdecl, alias);
+   }
}
 }
 
diff --git a/gcc/testsuite/g++.dg/parse/crash74.C 
b/gcc/testsuite/g++.dg/parse/crash74.C
new file mode 100644
index 000..a7ba5094be6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/crash74.C
@@ -0,0 +1,11 @@
+// PR c++/107575
+
+void f (void) {
+  virtual int f (void) const; // { dg-line line_4 }
+  virtual int f (void); // { dg-line line_5 }
+}
+
+// { dg-error "outside class declaration" {} { target *-*-* } line_4 }
+// { dg-error "cannot have cv-qualifier" {} { target *-*-* } line_4 }
+// { dg-error "ambiguating new declaration of" {} { target *-*-* } line_4 }
+// { dg-error "outside class declaration" {} { target *-*-* } line_5 }
-- 
2.44.0



Re: [PATCH] c++: Handle erroneous DECL_LOCAL_DECL_ALIAS in duplicate_decls [PR107575]

2024-06-05 Thread Simon Martin
Hi,

There was a formatting error, corrected in the updated attached patch 
:-/

On 5 Jun 2024, at 10:13, Simon Martin wrote:

> We currently ICE upon the following because we don't properly handle 
> local
> functions with an error_mark_node as DECL_LOCAL_DECL_ALIAS in 
> duplicate_decls.
>
> === cut here ===
> void f (void) {
>   virtual int f (void) const;
>   virtual int f (void);
> }
> === cut here ===
>
> This patch fixes this by checking for error_mark_node.
>
> Successfully tested on x86_64-pc-linux-gnu.
>
>   PR c++/107575
>
> gcc/cp/ChangeLog:
>
>   * decl.cc (duplicate_decls): Check for error_mark_node
>   DECL_LOCAL_DECL_ALIAS.
>
> gcc/testsuite/ChangeLog:
>
>   * g++.dg/parse/crash74.C: New test.
>
> ---
>  gcc/cp/decl.cc   | 11 +++
>  gcc/testsuite/g++.dg/parse/crash74.C | 11 +++
>  2 files changed, 18 insertions(+), 4 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/parse/crash74.C
>
> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> index d481e1ec074..2ae46143d70 100644
> --- a/gcc/cp/decl.cc
> +++ b/gcc/cp/decl.cc
> @@ -2792,10 +2792,13 @@ duplicate_decls (tree newdecl, tree olddecl, 
> bool hiding, bool was_hidden)
> retrofit_lang_decl (newdecl);
> tree alias = DECL_LOCAL_DECL_ALIAS (newdecl)
>   = DECL_LOCAL_DECL_ALIAS (olddecl);
> -   DECL_ATTRIBUTES (alias)
> - = (*targetm.merge_decl_attributes) (alias, newdecl);
> -   if (TREE_CODE (newdecl) == FUNCTION_DECL)
> - merge_attribute_bits (newdecl, alias);
> +   if (alias != error_mark_node)
> + {
> +   DECL_ATTRIBUTES (alias) =
The = sign should have been on the next line; this is the case in the 
updated patch.

> + (*targetm.merge_decl_attributes) (alias, newdecl);
> +   if (TREE_CODE (newdecl) == FUNCTION_DECL)
> + merge_attribute_bits (newdecl, alias);
> + }
>   }
>  }
>
> diff --git a/gcc/testsuite/g++.dg/parse/crash74.C 
> b/gcc/testsuite/g++.dg/parse/crash74.C
> new file mode 100644
> index 000..a7ba5094be6
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/parse/crash74.C
> @@ -0,0 +1,11 @@
> +// PR c++/107575
> +
> +void f (void) {
> +  virtual int f (void) const; // { dg-line line_4 }
> +  virtual int f (void); // { dg-line line_5 }
> +}
> +
> +// { dg-error "outside class declaration" {} { target *-*-* } line_4 
> }
> +// { dg-error "cannot have cv-qualifier" {} { target *-*-* } line_4 }
> +// { dg-error "ambiguating new declaration of" {} { target *-*-* } 
> line_4 }
> +// { dg-error "outside class declaration" {} { target *-*-* } line_5 
> }
> -- 
> 2.44.0
From e75602d3ce998307749e5022d989b564a6d19703 Mon Sep 17 00:00:00 2001
From: Simon Martin 
Date: Tue, 4 Jun 2024 21:20:23 +0200
Subject: [PATCH] c++: Handle erroneous DECL_LOCAL_DECL_ALIAS in duplicate_decls 
[PR107575]

We currently ICE upon the following because we don't properly handle local
functions with an error_mark_node as DECL_LOCAL_DECL_ALIAS in duplicate_decls.

=== cut here ===
void f (void) {
  virtual int f (void) const;
  virtual int f (void);
}
=== cut here ===

This patch fixes this by checking for error_mark_node.

Successfully tested on x86_64-pc-linux-gnu.

PR c++/107575

gcc/cp/ChangeLog:

* decl.cc (duplicate_decls): Check for error_mark_node
DECL_LOCAL_DECL_ALIAS.

gcc/testsuite/ChangeLog:

* g++.dg/parse/crash74.C: New test.

---
 gcc/cp/decl.cc   | 11 +++
 gcc/testsuite/g++.dg/parse/crash74.C | 11 +++
 2 files changed, 18 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/parse/crash74.C

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index d481e1ec074..03deb1493a4 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -2792,10 +2792,13 @@ duplicate_decls (tree newdecl, tree olddecl, bool 
hiding, bool was_hidden)
  retrofit_lang_decl (newdecl);
  tree alias = DECL_LOCAL_DECL_ALIAS (newdecl)
= DECL_LOCAL_DECL_ALIAS (olddecl);
- DECL_ATTRIBUTES (alias)
-   = (*targetm.merge_decl_attributes) (alias, newdecl);
- if (TREE_CODE (newdecl) == FUNCTION_DECL)
-   merge_attribute_bits (newdecl, alias);
+ if (alias != error_mark_node)
+   {
+ DECL_ATTRIBUTES (alias)
+   = (*targetm.merge_decl_attributes) (alias, newdecl);
+ if (TREE_CODE (newdecl) == FUNCTION_DECL)
+   merge_attribute_bits (newdecl, alias);
+   }
}
 }
 
diff --git a/gcc/testsuite/g++.dg/parse/crash74.C 
b/gcc/testsuite/g++.dg/parse/crash74.C
new file mode 100644
index 000..a7ba5094be6
--- /dev/null
+++ b/gcc/testsuite

[PATCH] c++: Handle erroneous DECL_LOCAL_DECL_ALIAS in duplicate_decls [PR107575]

2024-06-05 Thread Simon Martin
We currently ICE upon the following because we don't properly handle local
functions with an error_mark_node as DECL_LOCAL_DECL_ALIAS in duplicate_decls.

=== cut here ===
void f (void) {
  virtual int f (void) const;
  virtual int f (void);
}
=== cut here ===

This patch fixes this by checking for error_mark_node.

Successfully tested on x86_64-pc-linux-gnu.

PR c++/107575

gcc/cp/ChangeLog:

* decl.cc (duplicate_decls): Check for error_mark_node
DECL_LOCAL_DECL_ALIAS.

gcc/testsuite/ChangeLog:

* g++.dg/parse/crash74.C: New test.

---
 gcc/cp/decl.cc   | 11 +++
 gcc/testsuite/g++.dg/parse/crash74.C | 11 +++
 2 files changed, 18 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/parse/crash74.C

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index d481e1ec074..2ae46143d70 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -2792,10 +2792,13 @@ duplicate_decls (tree newdecl, tree olddecl, bool 
hiding, bool was_hidden)
  retrofit_lang_decl (newdecl);
  tree alias = DECL_LOCAL_DECL_ALIAS (newdecl)
= DECL_LOCAL_DECL_ALIAS (olddecl);
- DECL_ATTRIBUTES (alias)
-   = (*targetm.merge_decl_attributes) (alias, newdecl);
- if (TREE_CODE (newdecl) == FUNCTION_DECL)
-   merge_attribute_bits (newdecl, alias);
+ if (alias != error_mark_node)
+   {
+ DECL_ATTRIBUTES (alias) =
+   (*targetm.merge_decl_attributes) (alias, newdecl);
+ if (TREE_CODE (newdecl) == FUNCTION_DECL)
+   merge_attribute_bits (newdecl, alias);
+   }
}
 }
 
diff --git a/gcc/testsuite/g++.dg/parse/crash74.C 
b/gcc/testsuite/g++.dg/parse/crash74.C
new file mode 100644
index 000..a7ba5094be6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/crash74.C
@@ -0,0 +1,11 @@
+// PR c++/107575
+
+void f (void) {
+  virtual int f (void) const; // { dg-line line_4 }
+  virtual int f (void); // { dg-line line_5 }
+}
+
+// { dg-error "outside class declaration" {} { target *-*-* } line_4 }
+// { dg-error "cannot have cv-qualifier" {} { target *-*-* } line_4 }
+// { dg-error "ambiguating new declaration of" {} { target *-*-* } line_4 }
+// { dg-error "outside class declaration" {} { target *-*-* } line_5 }
-- 
2.44.0




Re: [PATCH] PR c++/103338 - Add testcase for issue fixed by recent commit

2024-06-04 Thread Simon Martin
Hi Jason,

On 4 Jun 2024, at 18:12, Jason Merrill wrote:

> On 6/4/24 11:54, Simon Martin wrote:
>> The case in that PR used to ICE until commit f04dc89.
>
> Interesting, I don't remember expecting that patch to change behavior 
> at all.
This is the patch that git bisect identified. I have to admit that I did 
not look further.

> BTW, it looks like your recent commits and emails have had 
> non-conventional subject lines; see 
> https://gcc.gnu.org/contribute.html#patches for more guidance.
>
Thanks for the pointer and apologies for not providing great subject 
lines; I’ll fix this moving forward (starting with that patch).

> For instance, the subject for this patch could be
>
> c++: add testcase for PR103338
>
> OK with that adjustment.
Thanks again.
>
>> This patch simply adds
>> the case to the testsuite.
>>
>> Successfully tested on x86_64-pc-linux-gnu.
>>
>>  PR c++/1033388
>>
>> gcc/testsuite/ChangeLog:
>>
>>  * g++.dg/parse/crash73.C: New test.
>>
>> ---
>>   gcc/testsuite/g++.dg/parse/crash73.C | 19 +++
>>   1 file changed, 19 insertions(+)
>>   create mode 100644 gcc/testsuite/g++.dg/parse/crash73.C
>>
>> diff --git a/gcc/testsuite/g++.dg/parse/crash73.C 
>> b/gcc/testsuite/g++.dg/parse/crash73.C
>> new file mode 100644
>> index 000..5923b98b719
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.dg/parse/crash73.C
>> @@ -0,0 +1,19 @@
>> +// PR c++/1033388
>> +// { dg-do compile { target c++11 } }
>> +
>> +template
>> +struct zip_view {
>> +  struct Iterator;
>> +};
>> +
>> +template
>> +struct zip_transform_view;
>> +
>> +template
>> +struct zip_view::Iterator { // { dg-error "no class 
>> template" }
>> +  template
>> +  template
>> +  friend class zip_transform_view::Iterator;
>> +};
>> +
>> +zip_view<>::Iterator iter;



[PATCH] PR c++/103338 - Add testcase for issue fixed by recent commit

2024-06-04 Thread Simon Martin
The case in that PR used to ICE until commit f04dc89. This patch simply adds
the case to the testsuite.

Successfully tested on x86_64-pc-linux-gnu.

PR c++/1033388

gcc/testsuite/ChangeLog:

* g++.dg/parse/crash73.C: New test.

---
 gcc/testsuite/g++.dg/parse/crash73.C | 19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/parse/crash73.C

diff --git a/gcc/testsuite/g++.dg/parse/crash73.C 
b/gcc/testsuite/g++.dg/parse/crash73.C
new file mode 100644
index 000..5923b98b719
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/crash73.C
@@ -0,0 +1,19 @@
+// PR c++/1033388
+// { dg-do compile { target c++11 } }
+
+template
+struct zip_view {
+  struct Iterator;
+};
+
+template
+struct zip_transform_view;
+
+template
+struct zip_view::Iterator { // { dg-error "no class template" }
+  template
+  template
+  friend class zip_transform_view::Iterator;
+};
+
+zip_view<>::Iterator iter;
-- 
2.44.0




[PATCH] Add missing space after seen_error in gcc/cp/pt.cc

2024-06-04 Thread Simon Martin
I realized that I committed a change with a missing space after seen_error.
This fixes it, as well as another occurrence in the same file.

Apologies for the mistake - I'll commit this as obvious.

gcc/cp/ChangeLog:

* pt.cc (tsubst_expr): Add missing space after seen_error.
(dependent_type_p): Likewise.

---
 gcc/cp/pt.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index edb94a000ea..8cbcf7cdf7a 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -20918,7 +20918,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t 
complain, tree in_decl)
   be using lambdas anyway, so it's ok to be
   stricter.  Be strict with C++20 template-id ADL too.
   And be strict if we're already failing anyway.  */
-   bool strict = in_lambda || template_id_p || seen_error();
+   bool strict = in_lambda || template_id_p || seen_error ();
bool diag = true;
if (strict)
  error_at (cp_expr_loc_or_input_loc (t),
@@ -28020,7 +28020,7 @@ dependent_type_p (tree type)
 providing us with a dependent type.  */
   gcc_assert (type);
   gcc_assert (TREE_CODE (type) != TEMPLATE_TYPE_PARM || is_auto (type)
- || seen_error());
+ || seen_error ());
   return false;
 }
 
-- 
2.44.0




Re: [PATCH] Fix PR c++/111106: missing ; causes internal compiler error

2024-06-04 Thread Simon Martin
Hi Jason,

Thanks for the review.

On 31 May 2024, at 22:45, Jason Merrill wrote:

> On 5/30/24 07:31, Simon Martin wrote:
>> We currently fail upon the following because an assert in 
>> dependent_type_p
>> fails for f's parameter
>>
>> === cut here ===
>> consteval int id (int i) { return i; }
>> constexpr int
>> f (auto i) requires requires { id (i) } { return i; }
>> void g () { f (42); }
>> === cut here ===
>>
>> This patch fixes this by handling synthesized parameters for 
>> abbreviated
>> function templates in that assert.
>
> I don't see why implicit template parameters should be handled 
> differently from explicit ones here.
>
> This seems more like an error-recovery issue, and I'd be open to 
> adding || seen_error() to that assert like in various others.
>
Makes sense; this is what the attached updated patch (successfully 
tested on x86_64-pc-linux-gnu) does.

Is it better and OK for trunk?

>> Successfully tested on x86_64-pc-linux-gnu.
>>
>>  PR c++/06
>>
>> gcc/cp/ChangeLog:
>>
>>  * pt.cc (dependent_type_p): Relax assert to handle synthesized 
>> template
>>  parameters when !processing_template_decl.
>>
>> gcc/testsuite/ChangeLog:
>>
>>  * g++.dg/cpp2a/consteval37.C: New test.
>>
>> ---
>>   gcc/cp/pt.cc |  6 +-
>>   gcc/testsuite/g++.dg/cpp2a/consteval37.C | 19 +++
>>   2 files changed, 24 insertions(+), 1 deletion(-)
>>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/consteval37.C
>>
>> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
>> index dfce1b3c359..a50d5cfd5a2 100644
>> --- a/gcc/cp/pt.cc
>> +++ b/gcc/cp/pt.cc
>> @@ -28019,7 +28019,11 @@ dependent_type_p (tree type)
>> /* If we are not processing a template, then nobody should be
>>   providing us with a dependent type.  */
>> gcc_assert (type);
>> -  gcc_assert (TREE_CODE (type) != TEMPLATE_TYPE_PARM || is_auto 
>> (type));
>> +  gcc_assert (TREE_CODE (type) != TEMPLATE_TYPE_PARM || is_auto 
>> (type)
>> +  || (/* Synthesized template parameter */
>> +  DECL_TEMPLATE_PARM_P (TEMPLATE_TYPE_DECL (type)) &&
>> +  (DECL_IMPLICIT_TEMPLATE_PARM_P
>> +   (TEMPLATE_TYPE_DECL (type);
>> return false;
>>   }
>>  diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval37.C 
>> b/gcc/testsuite/g++.dg/cpp2a/consteval37.C
>> new file mode 100644
>> index 000..ea2641fc204
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.dg/cpp2a/consteval37.C
>> @@ -0,0 +1,19 @@
>> +// PR c++/06
>> +// { dg-do compile { target c++20 } }
>> +
>> +consteval int id (int i) { return i; }
>> +
>> +constexpr int f (auto i) // { dg-line line_1 }
>> +  requires requires { id (i) } // { dg-error "expected|invalid use" 
>> }
>> +{
>> +  return i;
>> +}
>> +
>> +void g () {
>> +  f (42); // { dg-error "parameter 1" }
>> +}
>> +
>> +// { dg-error "constraints on a non-templated" {} { target *-*-* } 
>> line_1 }
>> +// { dg-error "has incomplete type" {} { target *-*-* } line_1 }
>> +// { dg-error "invalid type for" {} { target *-*-* } line_1 }
>> +// { dg-note "declared here" {} { target *-*-* } line_1 }
>
> These errors are wrong, so should not be tested for;  only the syntax 
> error about the missing semicolon should have a dg-error.  You can use 
> dg-excess-errors to cover the rest.
>
Addressed in the updated patch. Thanks!

> Jason
From ec9be7818bc9f7c46e9a1fbbb8b0c9ac030fa63d Mon Sep 17 00:00:00 2001
From: Simon Martin 
Date: Fri, 24 May 2024 17:00:17 +0200
Subject: [PATCH] Fix PR c++/06: missing ; causes internal compiler error

We currently fail upon the following because an assert in dependent_type_p
fails for f's parameter

=== cut here ===
consteval int id (int i) { return i; }
constexpr int
f (auto i) requires requires { id (i) } { return i; }
void g () { f (42); }
=== cut here ===

This patch fixes this by relaxing the assert to pass during error recovery.

Successfully tested on x86_64-pc-linux-gnu.

PR c++/06

gcc/cp/ChangeLog:

* pt.cc (dependent_type_p): Don't fail assert during error recovery.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/consteval37.C: New test.

---
 gcc/cp/pt.cc |  3 ++-
 gcc/testsuite/g++.dg/cpp2a/consteval37.C | 16 
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2

[PATCH] Fix PR c++/109958: ICE taking the address of bound static member function brought into derived class by using-declaration

2024-05-31 Thread Simon Martin
From: Simon Martin 

We currently ICE upon the following because we don't properly handle the
overload created for B::f through the using statement.

=== cut here ===
struct B { static int f(); };
struct D : B { using B::f; };
void f(D d) {  }
=== cut here ===

This patch makes build_class_member_access_expr and cp_build_addr_expr_1 handle
such overloads, and fixes the PR.

Successfully tested on x86_64-pc-linux-gnu.

PR c++/109958

gcc/cp/ChangeLog:

* typeck.cc (build_class_member_access_expr): Handle single OVERLOADs.
(cp_build_addr_expr_1): Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/overload/using6.C: New test.

---
 gcc/cp/typeck.cc   | 5 +
 gcc/testsuite/g++.dg/overload/using6.C | 5 +
 2 files changed, 10 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/overload/using6.C

diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
index 1b7a31d32f3..5970ac3d398 100644
--- a/gcc/cp/typeck.cc
+++ b/gcc/cp/typeck.cc
@@ -3025,6 +3025,8 @@ build_class_member_access_expr (cp_expr object, tree 
member,
 know the type of the expression.  Otherwise, we must wait
 until overload resolution has been performed.  */
   functions = BASELINK_FUNCTIONS (member);
+  if (TREE_CODE (functions) == OVERLOAD && OVL_SINGLE_P (functions))
+   functions = OVL_FIRST (functions);
   if (TREE_CODE (functions) == FUNCTION_DECL
  && DECL_STATIC_FUNCTION_P (functions))
type = TREE_TYPE (functions);
@@ -7333,6 +7335,9 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, 
tsubst_flags_t complain)
 {
   tree fn = BASELINK_FUNCTIONS (TREE_OPERAND (arg, 1));
 
+  if (TREE_CODE (fn) == OVERLOAD && OVL_SINGLE_P (fn))
+   fn = OVL_FIRST (fn);
+
   /* We can only get here with a single static member
 function.  */
   gcc_assert (TREE_CODE (fn) == FUNCTION_DECL
diff --git a/gcc/testsuite/g++.dg/overload/using6.C 
b/gcc/testsuite/g++.dg/overload/using6.C
new file mode 100644
index 000..4f89f68a30f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/overload/using6.C
@@ -0,0 +1,5 @@
+// PR c++/109958
+
+struct B { static int f(); };
+struct D : B { using B::f; };
+void f(D d) {  }
-- 
2.44.0




[PATCH] Fix PR c++/111106: missing ; causes internal compiler error

2024-05-30 Thread Simon Martin
We currently fail upon the following because an assert in dependent_type_p
fails for f's parameter

=== cut here ===
consteval int id (int i) { return i; }
constexpr int
f (auto i) requires requires { id (i) } { return i; }
void g () { f (42); }
=== cut here ===

This patch fixes this by handling synthesized parameters for abbreviated
function templates in that assert.

Successfully tested on x86_64-pc-linux-gnu.

PR c++/06

gcc/cp/ChangeLog:

* pt.cc (dependent_type_p): Relax assert to handle synthesized template
parameters when !processing_template_decl.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/consteval37.C: New test.

---
 gcc/cp/pt.cc |  6 +-
 gcc/testsuite/g++.dg/cpp2a/consteval37.C | 19 +++
 2 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/consteval37.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index dfce1b3c359..a50d5cfd5a2 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -28019,7 +28019,11 @@ dependent_type_p (tree type)
   /* If we are not processing a template, then nobody should be
 providing us with a dependent type.  */
   gcc_assert (type);
-  gcc_assert (TREE_CODE (type) != TEMPLATE_TYPE_PARM || is_auto (type));
+  gcc_assert (TREE_CODE (type) != TEMPLATE_TYPE_PARM || is_auto (type)
+ || (/* Synthesized template parameter */
+ DECL_TEMPLATE_PARM_P (TEMPLATE_TYPE_DECL (type)) &&
+ (DECL_IMPLICIT_TEMPLATE_PARM_P
+  (TEMPLATE_TYPE_DECL (type);
   return false;
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval37.C 
b/gcc/testsuite/g++.dg/cpp2a/consteval37.C
new file mode 100644
index 000..ea2641fc204
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/consteval37.C
@@ -0,0 +1,19 @@
+// PR c++/06
+// { dg-do compile { target c++20 } }
+
+consteval int id (int i) { return i; }
+
+constexpr int f (auto i) // { dg-line line_1 }
+  requires requires { id (i) } // { dg-error "expected|invalid use" }
+{
+  return i;
+}
+
+void g () {
+  f (42); // { dg-error "parameter 1" }
+}
+
+// { dg-error "constraints on a non-templated" {} { target *-*-* } line_1 }
+// { dg-error "has incomplete type" {} { target *-*-* } line_1 }
+// { dg-error "invalid type for" {} { target *-*-* } line_1 }
+// { dg-note "declared here" {} { target *-*-* } line_1 }
-- 
2.44.0




[PATCH] Add testcase for PR c++/105229: ICE in lookup_template_class_1

2024-05-24 Thread Simon Martin
Hi,

The test case in PR c++/105229 has been fixed since 11.4 (via PR 
c++/106024) - the attached patch simply adds the case to the test suite.

Successfully tested on x86_64-pc-linux-gnu. OK for trunk?

Thanks! Simon


 PR c++/105229

gcc/testsuite/ChangeLog:

 * g++.dg/parse/crash72.C: New test.

---
  gcc/testsuite/g++.dg/parse/crash72.C | 12 
  1 file changed, 12 insertions(+)
  create mode 100644 gcc/testsuite/g++.dg/parse/crash72.C

diff --git a/gcc/testsuite/g++.dg/parse/crash72.C 
b/gcc/testsuite/g++.dg/parse/crash72.C
new file mode 100644
index 000..df469e20f28
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/crash72.C
@@ -0,0 +1,12 @@
+// PR c++/105229
+// { dg-do compile { target c++20 } }
+// { dg-additional-options "-Wno-missing-template-keyword" }
+
+template  void bar ()
+{
+  []  {}.operator () <> (); // { dg-error "expected 
primary-expression" }
+}
+void foo ()
+{
+  bar ();
+}
--
2.44.0


Re: [PATCH] Fix PR c++/105760: ICE in build_deduction_guide for invalid template

2024-05-14 Thread Simon Martin

On 6 May 2024, at 18:28, Jason Merrill wrote:


On 5/6/24 09:20, Simon Martin wrote:

Hi,

We currently ICE upon the following invalid snippet because we fail 
to properly handle tsubst_arg_types returning error_mark_node in 
build_deduction_guide.


== cut ==
template
struct A { A(Ts...); };
A a;
== cut ==

This patch fixes this, and has been successfully tested on 
x86_64-pc-linux-gnu. OK for trunk?


OK, thanks.
Sorry for the delay replying, and thanks for the review. Could someone 
please commit the patch on my behalf since my sourceware account is not 
active anymore?


Thanks!



Thanks!

-- Simon

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a78d9d546d6..9acef73e7ac 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2024-05-06  Simon Martin  
+
+   PR c++/105760
+   * pt.c (build_deduction_guide): Check for 
error_mark_node

+   result from tsubst_arg_types.
+
  2024-05-03  Jason Merrill  

     PR c++/114935
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index d68d688016d..da5d9b8a665 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -30018,6 +30018,8 @@ build_deduction_guide (tree type, tree ctor, 
tree outer_args, tsubst_flags_t com
  references to members of an unknown 
specialization.  */

   cp_evaluated ev;
   fparms = tsubst_arg_types (fparms, targs, 
NULL_TREE, complain, ctor);

+ if (fparms == error_mark_node)
+   ok = false;
   fargs = tsubst (fargs, targs, complain, ctor);
   if (ci)
     {
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 03c88bbed07..8c606a8fb4f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2024-05-06  Simon Martin  
+
+   PR c++/105760
+   * g++.dg/parse/error66.C: New test.
+
  2024-05-05  Harald Anlauf  

     PR fortran/114827
diff --git a/gcc/testsuite/g++.dg/parse/error66.C 
b/gcc/testsuite/g++.dg/parse/error66.C

new file mode 100644
index 000..82f4b8b8a53
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/error66.C
@@ -0,0 +1,6 @@
+// PR c++/105760
+// { dg-do compile { target c++17 } }
+
+template // { dg-error "must be at the end of 
the template parameter list" }

+struct A { A(Ts...); };
+A a;



[PATCH] Fix PR c++/105760: ICE in build_deduction_guide for invalid template

2024-05-06 Thread Simon Martin

Hi,

We currently ICE upon the following invalid snippet because we fail to 
properly handle tsubst_arg_types returning error_mark_node in 
build_deduction_guide.


== cut ==
template
struct A { A(Ts...); };
A a;
== cut ==

This patch fixes this, and has been successfully tested on 
x86_64-pc-linux-gnu. OK for trunk?


Thanks!

-- Simon

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a78d9d546d6..9acef73e7ac 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2024-05-06  Simon Martin  
+
+   PR c++/105760
+   * pt.c (build_deduction_guide): Check for error_mark_node
+   result from tsubst_arg_types.
+
 2024-05-03  Jason Merrill  

PR c++/114935
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index d68d688016d..da5d9b8a665 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -30018,6 +30018,8 @@ build_deduction_guide (tree type, tree ctor, 
tree outer_args, tsubst_flags_t com

 references to members of an unknown specialization.  */
  cp_evaluated ev;
  fparms = tsubst_arg_types (fparms, targs, NULL_TREE, 
complain, ctor);

+ if (fparms == error_mark_node)
+   ok = false;
  fargs = tsubst (fargs, targs, complain, ctor);
  if (ci)
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 03c88bbed07..8c606a8fb4f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2024-05-06  Simon Martin  
+
+   PR c++/105760
+   * g++.dg/parse/error66.C: New test.
+
 2024-05-05  Harald Anlauf  

PR fortran/114827
diff --git a/gcc/testsuite/g++.dg/parse/error66.C 
b/gcc/testsuite/g++.dg/parse/error66.C

new file mode 100644
index 000..82f4b8b8a53
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/error66.C
@@ -0,0 +1,6 @@
+// PR c++/105760
+// { dg-do compile { target c++17 } }
+
+template // { dg-error "must be at the end of the 
template parameter list" }

+struct A { A(Ts...); };
+A a;


[PATCH] Fix PR c/35445: ICE with conflicting declarations

2011-05-01 Thread Simon Martin

Hello,

The following invalid snippet triggers an ICE since 4.0.1:


extern int i;
extern int i;
int i[] = { 0 };


The problem is that 'finish_decl' ends up calling 'composite_type' with 
incompatible types when updating the type of the declaration of 'i' 
already encountered.


The attached patch fixes this by only calling 'composite_type' if 
'comptypes' returned a non-zero value, as stated in this function's 
documentation.


I've successfully bootstrapped and tested it on 
x86_64-apple-darwin10.6.0. Is it OK for trunk?


Best regards,
  Simon



2011-05-01  Simon Martin  simar...@users.sourceforge.net

PR c/35445
* c-decl.c (finish_decl): Only create a composite if the types are
compatible.


Index: gcc/c-decl.c
===
--- gcc/c-decl.c(revision 173206)
+++ gcc/c-decl.c(working copy)
@@ -4246,7 +4246,7 @@
b_ext = b_ext-shadowed;
  if (b_ext)
{
- if (b_ext-u.type)
+ if (b_ext-u.type  comptypes (b_ext-u.type, type))
b_ext-u.type = composite_type (b_ext-u.type, type);
  else
b_ext-u.type = type;


2011-05-01  Simon Martin  simar...@users.sourceforge.net

PR c/35445
* gcc.dg/pr35445.c: New test.


/* PR c/35445 */
/* { dg-do compile } */

extern int i;
extern int i; /* { dg-message was here } */
int i[] = { 0 }; /* { dg-error conflicting types } */