* [Bug c++/97399] g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles
2020-10-13 9:58 [Bug c++/97399] New: g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles renlin at gcc dot gnu.org
@ 2020-10-13 9:58 ` renlin at gcc dot gnu.org
2020-10-13 11:02 ` [Bug c++/97399] [9/10/11 Regression] " rguenth at gcc dot gnu.org
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: renlin at gcc dot gnu.org @ 2020-10-13 9:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97399
--- Comment #1 from Renlin Li <renlin at gcc dot gnu.org> ---
Created attachment 49363
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49363&action=edit
test case 2
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97399] [9/10/11 Regression] g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles
2020-10-13 9:58 [Bug c++/97399] New: g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles renlin at gcc dot gnu.org
2020-10-13 9:58 ` [Bug c++/97399] " renlin at gcc dot gnu.org
@ 2020-10-13 11:02 ` rguenth at gcc dot gnu.org
2020-10-13 14:10 ` marxin at gcc dot gnu.org
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-10-13 11:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97399
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |7.5.0
Keywords| |ice-on-valid-code,
| |rejects-valid
Known to fail| |10.2.1
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Summary|g++ 9.3 cannot compile |[9/10/11 Regression] g++
|SFINAE code with separated |9.3 cannot compile SFINAE
|declaration and definition, |code with separated
|g++ 7.3 compiles |declaration and definition,
| |g++ 7.3 compiles
Last reconfirmed| |2020-10-13
Target Milestone|--- |9.4
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 ICEs:
> g++-10 t.C -S -std=c++11
t.C: In substitution of 'template<class E> static constexpr
enable_if_t<((tmp*)this)->is_integral<E>(), bool> tmp::func(E, E) [with E =
int]':
t.C:40:30: required from here
t.C:19:43: internal compiler error: in tsubst_copy, at cp/pt.c:16383
19 | -> enable_if_t<tmp::is_integral<E>(), bool>;
| ~~~~~~~~~~~~~~~~~~~^~
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.opensuse.org/> for instructions.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97399] [9/10/11 Regression] g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles
2020-10-13 9:58 [Bug c++/97399] New: g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles renlin at gcc dot gnu.org
2020-10-13 9:58 ` [Bug c++/97399] " renlin at gcc dot gnu.org
2020-10-13 11:02 ` [Bug c++/97399] [9/10/11 Regression] " rguenth at gcc dot gnu.org
@ 2020-10-13 14:10 ` marxin at gcc dot gnu.org
2021-01-14 9:25 ` rguenth at gcc dot gnu.org
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-10-13 14:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97399
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |aoliva at gcc dot gnu.org,
| |marxin at gcc dot gnu.org
--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
Reduced test-case:
$ cat pr97399.ii
template <int __v> struct integral_constant {
static constexpr int value = __v;
};
template <bool, class> using enable_if_t = int;
struct tmp {
template <class> static constexpr auto is_integral() -> bool;
template <class E>
static auto func(E, E) -> enable_if_t<tmp::is_integral<E>(), bool>;
};
template <class> constexpr auto tmp::is_integral() -> bool {
return integral_constant<false>::value;
}
int main() { tmp::func(1, 0); }
Started with r9-5972-g10839133ce6c196c.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97399] [9/10/11 Regression] g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles
2020-10-13 9:58 [Bug c++/97399] New: g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles renlin at gcc dot gnu.org
` (2 preceding siblings ...)
2020-10-13 14:10 ` marxin at gcc dot gnu.org
@ 2021-01-14 9:25 ` rguenth at gcc dot gnu.org
2021-01-20 20:00 ` ppalka at gcc dot gnu.org
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-01-14 9:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97399
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97399] [9/10/11 Regression] g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles
2020-10-13 9:58 [Bug c++/97399] New: g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles renlin at gcc dot gnu.org
` (3 preceding siblings ...)
2021-01-14 9:25 ` rguenth at gcc dot gnu.org
@ 2021-01-20 20:00 ` ppalka at gcc dot gnu.org
2021-01-23 5:25 ` cvs-commit at gcc dot gnu.org
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-01-20 20:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97399
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |ppalka at gcc dot gnu.org
CC| |ppalka at gcc dot gnu.org
--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
The alias template in the reduced testcase is a red herring, the ICE can be
reproduced without it:
template <bool> struct enable_if_t {};
struct tmp {
template <class> static constexpr bool is_integral();
template <class E>
static auto func(E, E) -> enable_if_t<tmp::is_integral<E>()>;
};
template <class> constexpr bool tmp::is_integral() { return true; }
int main() { tmp::func(1, 0); }
Looks like the problematic hunk from r9-5972 is
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2096,7 +2096,8 @@ finish_qualified_id_expr (tree qualifying_class,
{
/* See if any of the functions are non-static members. */
/* If so, the expression may be relative to 'this'. */
- if (!shared_member_p (expr)
+ if ((type_dependent_expression_p (expr)
+ || !shared_member_p (expr))
&& current_class_ptr
&& DERIVED_FROM_P (qualifying_class,
current_nonlambda_class_type ()))
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97399] [9/10/11 Regression] g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles
2020-10-13 9:58 [Bug c++/97399] New: g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles renlin at gcc dot gnu.org
` (4 preceding siblings ...)
2021-01-20 20:00 ` ppalka at gcc dot gnu.org
@ 2021-01-23 5:25 ` cvs-commit at gcc dot gnu.org
2021-01-23 5:25 ` [Bug c++/97399] [9/10 " ppalka at gcc dot gnu.org
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-01-23 5:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97399
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:a8cef3cba6945730c69e15dcdad726e74b50fe58
commit r11-6878-ga8cef3cba6945730c69e15dcdad726e74b50fe58
Author: Patrick Palka <ppalka@redhat.com>
Date: Sat Jan 23 00:24:17 2021 -0500
c++: 'this' injection and static member functions [PR97399]
In the testcase pr97399.C below, finish_qualified_id_expr at parse time
adds an implicit 'this->' to the expression tmp::integral<T> (because
it's type-dependent, and also current_class_ptr is set at this point)
within the trailing return type. Later when substituting into this
trailing return type we crash because we can't resolve the 'this', since
tsubst_function_type does inject_this_parm only for non-static member
functions, which tmp::func is not.
This patch fixes this issue by removing the type-dependence check
in finish_qualified_id_expr added by r9-5972, and instead relaxes
shared_member_p to handle dependent USING_DECLs:
> I think I was wrong in my assertion around Alex's patch that
> shared_member_p should abort on a dependent USING_DECL; it now seems
> appropriate for it to return false if we don't know, we just need to
> adjust the comment to say that.
And when parsing a friend function declaration, we shouldn't be setting
current_class_ptr at all, so this patch additionally suppresses
inject_this_parm in this case.
Finally, the self-contained change to cp_parser_init_declarator is so
that we properly communicate static-ness to cp_parser_direct_declarator
when parsing a member function template. This lets us reject the
explicit use of 'this' in the testcase this2.C below.
gcc/cp/ChangeLog:
PR c++/97399
* cp-tree.h (shared_member_p): Adjust declaration.
* parser.c (cp_parser_init_declarator): If the storage class
specifier is sc_static, pass true for static_p to
cp_parser_declarator.
(cp_parser_direct_declarator): Don't do inject_this_parm when
the declarator is a friend.
* search.c (shared_member_p): Change return type to bool and
adjust function body accordingly. Return false for a dependent
USING_DECL instead of aborting.
* semantics.c (finish_qualified_id_expr): Rely on shared_member_p
even when type-dependent.
gcc/testsuite/ChangeLog:
PR c++/88548
PR c++/97399
* g++.dg/cpp0x/this2.C: New test.
* g++.dg/template/pr97399.C: New test.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97399] [9/10 Regression] g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles
2020-10-13 9:58 [Bug c++/97399] New: g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles renlin at gcc dot gnu.org
` (5 preceding siblings ...)
2021-01-23 5:25 ` cvs-commit at gcc dot gnu.org
@ 2021-01-23 5:25 ` ppalka at gcc dot gnu.org
2021-04-10 20:33 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-01-23 5:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97399
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[9/10/11 Regression] g++ |[9/10 Regression] g++ 9.3
|9.3 cannot compile SFINAE |cannot compile SFINAE code
|code with separated |with separated declaration
|declaration and definition, |and definition, g++ 7.3
|g++ 7.3 compiles |compiles
--- Comment #6 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 11 so far.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97399] [9/10 Regression] g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles
2020-10-13 9:58 [Bug c++/97399] New: g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles renlin at gcc dot gnu.org
` (6 preceding siblings ...)
2021-01-23 5:25 ` [Bug c++/97399] [9/10 " ppalka at gcc dot gnu.org
@ 2021-04-10 20:33 ` cvs-commit at gcc dot gnu.org
2021-06-01 8:18 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-10 20:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97399
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:
https://gcc.gnu.org/g:82198676c80764ca7cf05f891afaee83b9179dd1
commit r11-8118-g82198676c80764ca7cf05f891afaee83b9179dd1
Author: Jason Merrill <jason@redhat.com>
Date: Sat Apr 10 10:55:58 2021 -0400
c++: ICE with invalid use of 'this' with static memfn [PR98800]
Here instantiation of the fake 'this' parameter we used when parsing the
trailing return type of func() was failing because there is no actual
'this'
parameter in the instantiation. For PR97399 I told Patrick to do the
'this'
injection even for statics, but now I think I was wrong; the out-of-class
definition case I was concerned about does not break with this patch. And
we don't set current_class_ptr in the body of a static member function.
And the OMP code should continue to parse 'this' and complain about it
rather than give a syntax error.
gcc/cp/ChangeLog:
PR c++/98800
PR c++/97399
* parser.c (cp_parser_direct_declarator): Don't
inject_this_parameter if static_p.
(cp_parser_omp_var_list_no_open): Parse 'this' even if
current_class_ptr isn't set for a better diagnostic.
gcc/testsuite/ChangeLog:
PR c++/98800
* g++.dg/gomp/this-1.C: Adjust diagnostic.
* g++.dg/cpp0x/constexpr-this1.C: New test.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97399] [9/10 Regression] g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles
2020-10-13 9:58 [Bug c++/97399] New: g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles renlin at gcc dot gnu.org
` (7 preceding siblings ...)
2021-04-10 20:33 ` cvs-commit at gcc dot gnu.org
@ 2021-06-01 8:18 ` rguenth at gcc dot gnu.org
2022-05-27 9:43 ` [Bug c++/97399] [10 " rguenth at gcc dot gnu.org
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-06-01 8:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97399
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|9.4 |9.5
--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9.4 is being released, retargeting bugs to GCC 9.5.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97399] [10 Regression] g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles
2020-10-13 9:58 [Bug c++/97399] New: g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles renlin at gcc dot gnu.org
` (8 preceding siblings ...)
2021-06-01 8:18 ` rguenth at gcc dot gnu.org
@ 2022-05-27 9:43 ` rguenth at gcc dot gnu.org
2022-06-28 10:42 ` jakub at gcc dot gnu.org
2023-07-07 9:08 ` rguenth at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-27 9:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97399
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|9.5 |10.4
--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9 branch is being closed
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97399] [10 Regression] g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles
2020-10-13 9:58 [Bug c++/97399] New: g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles renlin at gcc dot gnu.org
` (9 preceding siblings ...)
2022-05-27 9:43 ` [Bug c++/97399] [10 " rguenth at gcc dot gnu.org
@ 2022-06-28 10:42 ` jakub at gcc dot gnu.org
2023-07-07 9:08 ` rguenth at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97399
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|10.4 |10.5
--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/97399] [10 Regression] g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles
2020-10-13 9:58 [Bug c++/97399] New: g++ 9.3 cannot compile SFINAE code with separated declaration and definition, g++ 7.3 compiles renlin at gcc dot gnu.org
` (10 preceding siblings ...)
2022-06-28 10:42 ` jakub at gcc dot gnu.org
@ 2023-07-07 9:08 ` rguenth at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 9:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97399
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |10.5.0
Known to work| |11.1.0
Status|ASSIGNED |RESOLVED
Target Milestone|10.5 |11.0
Resolution|--- |FIXED
--- Comment #11 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed for GCC 11.
^ permalink raw reply [flat|nested] 13+ messages in thread