* [Bug c++/107939] [11/12/13 Regression] Rejects use of `extern const` variable in a template
2022-11-30 19:32 [Bug c++/107939] New: Rejects use of `extern const` variable in a template johelegp at gmail dot com
@ 2022-11-30 19:35 ` pinskia at gcc dot gnu.org
2022-11-30 19:36 ` johelegp at gmail dot com
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-30 19:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107939
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Keywords| |needs-bisection
Target Milestone|--- |11.4
Summary|Rejects use of `extern |[11/12/13 Regression]
|const` variable in a |Rejects use of `extern
|template |const` variable in a
| |template
Last reconfirmed| |2022-11-30
Ever confirmed|0 |1
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Replacing auto with int (and adding a message to static_assert), gets you a
valid C++14 testcase:
```
struct Q {
struct P {
const Q* p;
};
int n;
constexpr P operator()(int) const { return {this}; }
};
extern const Q q;
#if 1
template<int> constexpr auto p = q(0);
static_assert(p<0>.p == &q, "");
#else
constexpr auto p = q(0);
static_assert(p.p == &q, "");
#endif
constexpr Q q = {};
```
This worked with GCC 10.4.0.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/107939] [11/12/13 Regression] Rejects use of `extern const` variable in a template
2022-11-30 19:32 [Bug c++/107939] New: Rejects use of `extern const` variable in a template johelegp at gmail dot com
2022-11-30 19:35 ` [Bug c++/107939] [11/12/13 Regression] " pinskia at gcc dot gnu.org
@ 2022-11-30 19:36 ` johelegp at gmail dot com
2022-12-01 8:04 ` rguenth at gcc dot gnu.org
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: johelegp at gmail dot com @ 2022-11-30 19:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107939
--- Comment #2 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
Making the expression using the `extern const` variable more complex or
indirect makes it work. With an IILE, for example:
https://compiler-explorer.com/z/EjYYvPvqT.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/107939] [11/12/13 Regression] Rejects use of `extern const` variable in a template
2022-11-30 19:32 [Bug c++/107939] New: Rejects use of `extern const` variable in a template johelegp at gmail dot com
2022-11-30 19:35 ` [Bug c++/107939] [11/12/13 Regression] " pinskia at gcc dot gnu.org
2022-11-30 19:36 ` johelegp at gmail dot com
@ 2022-12-01 8:04 ` rguenth at gcc dot gnu.org
2022-12-02 14:19 ` [Bug c++/107939] [11/12/13 Regression] Rejects use of `extern const` variable in a template since r11-557 jakub at gcc dot gnu.org
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-12-01 8:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107939
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/107939] [11/12/13 Regression] Rejects use of `extern const` variable in a template since r11-557
2022-11-30 19:32 [Bug c++/107939] New: Rejects use of `extern const` variable in a template johelegp at gmail dot com
` (2 preceding siblings ...)
2022-12-01 8:04 ` rguenth at gcc dot gnu.org
@ 2022-12-02 14:19 ` jakub at gcc dot gnu.org
2023-03-02 22:48 ` mpolacek at gcc dot gnu.org
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-12-02 14:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107939
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org,
| |jason at gcc dot gnu.org
Keywords|needs-bisection |
Summary|[11/12/13 Regression] |[11/12/13 Regression]
|Rejects use of `extern |Rejects use of `extern
|const` variable in a |const` variable in a
|template |template since r11-557
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This is rejected since r11-557-gbeb019d346b903c16b9fd349937de444b6a8b6c0
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/107939] [11/12/13 Regression] Rejects use of `extern const` variable in a template since r11-557
2022-11-30 19:32 [Bug c++/107939] New: Rejects use of `extern const` variable in a template johelegp at gmail dot com
` (3 preceding siblings ...)
2022-12-02 14:19 ` [Bug c++/107939] [11/12/13 Regression] Rejects use of `extern const` variable in a template since r11-557 jakub at gcc dot gnu.org
@ 2023-03-02 22:48 ` mpolacek at gcc dot gnu.org
2023-03-03 0:02 ` mpolacek at gcc dot gnu.org
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-02 22:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107939
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
A similar example
extern const int z;
template<int> constexpr auto p = z;
works, because require_constant_expression is OK with 'z' here. The difference
between 'z' here and 'q' in the previous test is
INTEGRAL_OR_ENUMERATION_TYPE_P, which makes decl_maybe_constant_var_p return
different answers:
else if (CP_TYPE_CONST_NON_VOLATILE_P (type)
&& INTEGRAL_OR_ENUMERATION_TYPE_P (type))
/* And const integers. */;
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/107939] [11/12/13 Regression] Rejects use of `extern const` variable in a template since r11-557
2022-11-30 19:32 [Bug c++/107939] New: Rejects use of `extern const` variable in a template johelegp at gmail dot com
` (4 preceding siblings ...)
2023-03-02 22:48 ` mpolacek at gcc dot gnu.org
@ 2023-03-03 0:02 ` mpolacek at gcc dot gnu.org
2023-03-03 16:35 ` mpolacek at gcc dot gnu.org
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-03 0:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107939
--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I think p_c_e just needs to handle constexpr functors in templates. I'll poke
more tomorrow.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/107939] [11/12/13 Regression] Rejects use of `extern const` variable in a template since r11-557
2022-11-30 19:32 [Bug c++/107939] New: Rejects use of `extern const` variable in a template johelegp at gmail dot com
` (5 preceding siblings ...)
2023-03-03 0:02 ` mpolacek at gcc dot gnu.org
@ 2023-03-03 16:35 ` mpolacek at gcc dot gnu.org
2023-03-07 15:13 ` cvs-commit at gcc dot gnu.org
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-03 16:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107939
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/107939] [11/12/13 Regression] Rejects use of `extern const` variable in a template since r11-557
2022-11-30 19:32 [Bug c++/107939] New: Rejects use of `extern const` variable in a template johelegp at gmail dot com
` (6 preceding siblings ...)
2023-03-03 16:35 ` mpolacek at gcc dot gnu.org
@ 2023-03-07 15:13 ` cvs-commit at gcc dot gnu.org
2023-03-07 15:16 ` [Bug c++/107939] [11/12 " mpolacek at gcc dot gnu.org
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-07 15:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107939
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:e09bc034d1b4d692b409fa5af52ae34480a6f4dc
commit r13-6525-ge09bc034d1b4d692b409fa5af52ae34480a6f4dc
Author: Marek Polacek <polacek@redhat.com>
Date: Fri Mar 3 11:24:24 2023 -0500
c++: error with constexpr operator() [PR107939]
Similarly to PR107938, this also started with r11-557, whereby
cp_finish_decl
can call check_initializer even in a template for a constexpr initializer.
Here we are rejecting
extern const Q q;
template<int>
constexpr auto p = q(0);
even though q has a constexpr operator(). It's deemed non-const by
decl_maybe_constant_var_p because even though 'q' is const it is not
of integral/enum type.
If fun is not a function pointer, we don't know if we're using it as an
lvalue or rvalue, so with this patch we pass 'any' for want_rval. With
that, p_c_e/VAR_DECL doesn't flat out reject the underlying VAR_DECL.
PR c++/107939
gcc/cp/ChangeLog:
* constexpr.cc (potential_constant_expression_1) <case CALL_EXPR>:
Pass
'any' when recursing on a VAR_DECL and not a pointer to function.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/var-templ74.C: Remove dg-error.
* g++.dg/cpp1y/var-templ77.C: New test.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/107939] [11/12 Regression] Rejects use of `extern const` variable in a template since r11-557
2022-11-30 19:32 [Bug c++/107939] New: Rejects use of `extern const` variable in a template johelegp at gmail dot com
` (7 preceding siblings ...)
2023-03-07 15:13 ` cvs-commit at gcc dot gnu.org
@ 2023-03-07 15:16 ` mpolacek at gcc dot gnu.org
2023-03-07 15:25 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-07 15:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107939
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[11/12/13 Regression] |[11/12 Regression] Rejects
|Rejects use of `extern |use of `extern const`
|const` variable in a |variable in a template
|template since r11-557 |since r11-557
--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/107939] [11/12 Regression] Rejects use of `extern const` variable in a template since r11-557
2022-11-30 19:32 [Bug c++/107939] New: Rejects use of `extern const` variable in a template johelegp at gmail dot com
` (8 preceding siblings ...)
2023-03-07 15:16 ` [Bug c++/107939] [11/12 " mpolacek at gcc dot gnu.org
@ 2023-03-07 15:25 ` cvs-commit at gcc dot gnu.org
2023-03-07 15:25 ` [Bug c++/107939] [11 " mpolacek at gcc dot gnu.org
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-07 15:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107939
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:19ed6bf44c3fec882cf4c825f3ffa4f2ecdc78e6
commit r12-9232-g19ed6bf44c3fec882cf4c825f3ffa4f2ecdc78e6
Author: Marek Polacek <polacek@redhat.com>
Date: Fri Mar 3 11:24:24 2023 -0500
c++: error with constexpr operator() [PR107939]
Similarly to PR107938, this also started with r11-557, whereby
cp_finish_decl
can call check_initializer even in a template for a constexpr initializer.
Here we are rejecting
extern const Q q;
template<int>
constexpr auto p = q(0);
even though q has a constexpr operator(). It's deemed non-const by
decl_maybe_constant_var_p because even though 'q' is const it is not
of integral/enum type.
If fun is not a function pointer, we don't know if we're using it as an
lvalue or rvalue, so with this patch we pass 'any' for want_rval. With
that, p_c_e/VAR_DECL doesn't flat out reject the underlying VAR_DECL.
PR c++/107939
gcc/cp/ChangeLog:
* constexpr.cc (potential_constant_expression_1) <case CALL_EXPR>:
Pass
'any' when recursing on a VAR_DECL and not a pointer to function.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/var-templ74.C: Remove dg-error.
* g++.dg/cpp1y/var-templ77.C: New test.
(cherry picked from commit e09bc034d1b4d692b409fa5af52ae34480a6f4dc)
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/107939] [11 Regression] Rejects use of `extern const` variable in a template since r11-557
2022-11-30 19:32 [Bug c++/107939] New: Rejects use of `extern const` variable in a template johelegp at gmail dot com
` (9 preceding siblings ...)
2023-03-07 15:25 ` cvs-commit at gcc dot gnu.org
@ 2023-03-07 15:25 ` mpolacek at gcc dot gnu.org
2023-11-16 14:32 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2023-03-07 15:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107939
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
Summary|[11/12 Regression] Rejects |[11 Regression] Rejects use
|use of `extern const` |of `extern const` variable
|variable in a template |in a template since r11-557
|since r11-557 |
--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/107939] [11 Regression] Rejects use of `extern const` variable in a template since r11-557
2022-11-30 19:32 [Bug c++/107939] New: Rejects use of `extern const` variable in a template johelegp at gmail dot com
` (10 preceding siblings ...)
2023-03-07 15:25 ` [Bug c++/107939] [11 " mpolacek at gcc dot gnu.org
@ 2023-11-16 14:32 ` cvs-commit at gcc dot gnu.org
2023-11-24 16:56 ` cvs-commit at gcc dot gnu.org
2023-11-27 22:02 ` cvs-commit at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-16 14:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107939
--- Comment #10 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:0077c0fb19981c108a01cd15af9b2d6d478c183b
commit r14-5531-g0077c0fb19981c108a01cd15af9b2d6d478c183b
Author: Patrick Palka <ppalka@redhat.com>
Date: Thu Nov 16 09:32:07 2023 -0500
c++: constantness of call to function pointer [PR111703]
potential_constant_expression for CALL_EXPR tests FUNCTION_POINTER_TYPE_P
on the callee rather than on the type of the callee, which means we
always pass want_rval=any when recursing and so may fail to identify a
non-constant function pointer callee as such. Fixing this turns out to
further work around PR111703.
PR c++/111703
PR c++/107939
gcc/cp/ChangeLog:
* constexpr.cc (potential_constant_expression_1) <case CALL_EXPR>:
Fix FUNCTION_POINTER_TYPE_P test.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-fn8.C: Extend test.
* g++.dg/diagnostic/constexpr4.C: New test.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/107939] [11 Regression] Rejects use of `extern const` variable in a template since r11-557
2022-11-30 19:32 [Bug c++/107939] New: Rejects use of `extern const` variable in a template johelegp at gmail dot com
` (11 preceding siblings ...)
2023-11-16 14:32 ` cvs-commit at gcc dot gnu.org
@ 2023-11-24 16:56 ` cvs-commit at gcc dot gnu.org
2023-11-27 22:02 ` cvs-commit at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-24 16:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107939
--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:cc4cbf38e842cf023e2bdc63a51ef836d7726d8e
commit r13-8098-gcc4cbf38e842cf023e2bdc63a51ef836d7726d8e
Author: Patrick Palka <ppalka@redhat.com>
Date: Thu Nov 16 09:32:07 2023 -0500
c++: constantness of call to function pointer [PR111703]
potential_constant_expression for CALL_EXPR tests FUNCTION_POINTER_TYPE_P
on the callee rather than on the type of the callee, which means we
always pass want_rval=any when recursing and so may fail to identify a
non-constant function pointer callee as such. Fixing this turns out to
further work around PR111703.
PR c++/111703
PR c++/107939
gcc/cp/ChangeLog:
* constexpr.cc (potential_constant_expression_1) <case CALL_EXPR>:
Fix FUNCTION_POINTER_TYPE_P test.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-fn8.C: Extend test.
* g++.dg/diagnostic/constexpr4.C: New test.
(cherry picked from commit 0077c0fb19981c108a01cd15af9b2d6d478c183b)
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/107939] [11 Regression] Rejects use of `extern const` variable in a template since r11-557
2022-11-30 19:32 [Bug c++/107939] New: Rejects use of `extern const` variable in a template johelegp at gmail dot com
` (12 preceding siblings ...)
2023-11-24 16:56 ` cvs-commit at gcc dot gnu.org
@ 2023-11-27 22:02 ` cvs-commit at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-27 22:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107939
--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:c9cb7e3d75d494a6591887a99d0d3f7f7a307b2e
commit r12-10017-gc9cb7e3d75d494a6591887a99d0d3f7f7a307b2e
Author: Patrick Palka <ppalka@redhat.com>
Date: Thu Nov 16 09:32:07 2023 -0500
c++: constantness of call to function pointer [PR111703]
potential_constant_expression for CALL_EXPR tests FUNCTION_POINTER_TYPE_P
on the callee rather than on the type of the callee, which means we
always pass want_rval=any when recursing and so may fail to identify a
non-constant function pointer callee as such. Fixing this turns out to
further work around PR111703.
PR c++/111703
PR c++/107939
gcc/cp/ChangeLog:
* constexpr.cc (potential_constant_expression_1) <case CALL_EXPR>:
Fix FUNCTION_POINTER_TYPE_P test.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-fn8.C: Extend test.
* g++.dg/diagnostic/constexpr4.C: New test.
(cherry picked from commit 0077c0fb19981c108a01cd15af9b2d6d478c183b)
^ permalink raw reply [flat|nested] 15+ messages in thread