public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102229] New: 'decltype(auto)' cannot be cv-qualified
@ 2021-09-07 13:33 netcan1996 at gmail dot com
2021-09-07 14:36 ` [Bug c++/102229] " marxin at gcc dot gnu.org
` (13 more replies)
0 siblings, 14 replies; 15+ messages in thread
From: netcan1996 at gmail dot com @ 2021-09-07 13:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102229
Bug ID: 102229
Summary: 'decltype(auto)' cannot be cv-qualified
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: netcan1996 at gmail dot com
Target Milestone: ---
code: https://godbolt.org/z/h833W9v95
it begins at version 11.x.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/102229] 'decltype(auto)' cannot be cv-qualified
2021-09-07 13:33 [Bug c++/102229] New: 'decltype(auto)' cannot be cv-qualified netcan1996 at gmail dot com
@ 2021-09-07 14:36 ` marxin at gcc dot gnu.org
2021-09-07 14:37 ` [Bug c++/102229] [11/12 Regression] " rguenth at gcc dot gnu.org
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-09-07 14:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102229
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |marxin at gcc dot gnu.org
--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
struct Test {
static constexpr decltype(auto) v = "test";
};
int main(int argc, char** argv) {
return 0;
}
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/102229] [11/12 Regression] 'decltype(auto)' cannot be cv-qualified
2021-09-07 13:33 [Bug c++/102229] New: 'decltype(auto)' cannot be cv-qualified netcan1996 at gmail dot com
2021-09-07 14:36 ` [Bug c++/102229] " marxin at gcc dot gnu.org
@ 2021-09-07 14:37 ` rguenth at gcc dot gnu.org
2021-09-07 14:43 ` mpolacek at gcc dot gnu.org
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-09-07 14:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102229
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |10.3.0
Last reconfirmed| |2021-09-07
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Target Milestone|--- |11.3
Priority|P3 |P2
Known to fail| |11.1.0
Keywords| |rejects-valid
Summary|'decltype(auto)' cannot be |[11/12 Regression]
|cv-qualified |'decltype(auto)' cannot be
| |cv-qualified
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. clang accepts it as well.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/102229] [11/12 Regression] 'decltype(auto)' cannot be cv-qualified
2021-09-07 13:33 [Bug c++/102229] New: 'decltype(auto)' cannot be cv-qualified netcan1996 at gmail dot com
2021-09-07 14:36 ` [Bug c++/102229] " marxin at gcc dot gnu.org
2021-09-07 14:37 ` [Bug c++/102229] [11/12 Regression] " rguenth at gcc dot gnu.org
@ 2021-09-07 14:43 ` mpolacek at gcc dot gnu.org
2021-09-07 15:17 ` mpolacek at gcc dot gnu.org
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-09-07 14:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102229
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
CC| |mpolacek at gcc dot gnu.org
Status|NEW |RESOLVED
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This is desirable, added in my r11-2202 to fix bug 79815:
"If the placeholder is the decltype(auto) type-specifier, T shall be the
placeholder alone." but we weren't detecting "const decltype(auto)".
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/102229] [11/12 Regression] 'decltype(auto)' cannot be cv-qualified
2021-09-07 13:33 [Bug c++/102229] New: 'decltype(auto)' cannot be cv-qualified netcan1996 at gmail dot com
` (2 preceding siblings ...)
2021-09-07 14:43 ` mpolacek at gcc dot gnu.org
@ 2021-09-07 15:17 ` mpolacek at gcc dot gnu.org
2021-09-07 19:43 ` jason at gcc dot gnu.org
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-09-07 15:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102229
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|INVALID |---
Status|RESOLVED |NEW
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Maybe it's not desirable after all, it may be that type-specifiers are not
permitted but decl-specifiers are.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/102229] [11/12 Regression] 'decltype(auto)' cannot be cv-qualified
2021-09-07 13:33 [Bug c++/102229] New: 'decltype(auto)' cannot be cv-qualified netcan1996 at gmail dot com
` (3 preceding siblings ...)
2021-09-07 15:17 ` mpolacek at gcc dot gnu.org
@ 2021-09-07 19:43 ` jason at gcc dot gnu.org
2021-09-07 20:06 ` mpolacek at gcc dot gnu.org
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2021-09-07 19:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102229
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
The standard isn't very clear on this point; it seems like a core issue.
9.2.6/10: A constexpr specifier used in an object declaration declares the
object as const.
9.2.9.6.2/2.2: for a variable declared with a type that contains a placeholder
type, T is the declared type of the variable and E is the initializer.
/5: If the placeholder-type-specifier is of the form type-constraint opt
decltype(auto), T shall be the placeholder alone.
The question is whether constexpr adds const before deduction (so it's part of
"the declared type of the variable") or after. The latter interpretation seems
more useful, so let's go with that.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/102229] [11/12 Regression] 'decltype(auto)' cannot be cv-qualified
2021-09-07 13:33 [Bug c++/102229] New: 'decltype(auto)' cannot be cv-qualified netcan1996 at gmail dot com
` (4 preceding siblings ...)
2021-09-07 19:43 ` jason at gcc dot gnu.org
@ 2021-09-07 20:06 ` mpolacek at gcc dot gnu.org
2021-09-09 13:56 ` netcan1996 at gmail dot com
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-09-07 20:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102229
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Thanks. With the latter interpretation in mind, it seems my earlier fix should
be mitigated so that we allow
constexpr decltype(auto)
but not
constexpr const decltype(auto)
Yes?
Do you want me to raise this with the CWG?
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/102229] [11/12 Regression] 'decltype(auto)' cannot be cv-qualified
2021-09-07 13:33 [Bug c++/102229] New: 'decltype(auto)' cannot be cv-qualified netcan1996 at gmail dot com
` (5 preceding siblings ...)
2021-09-07 20:06 ` mpolacek at gcc dot gnu.org
@ 2021-09-09 13:56 ` netcan1996 at gmail dot com
2021-09-09 15:08 ` jason at gcc dot gnu.org
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: netcan1996 at gmail dot com @ 2021-09-09 13:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102229
--- Comment #7 from Net Can <netcan1996 at gmail dot com> ---
here is my use case:
https://github.com/netcan/config-loader/blob/master/include/config-loader/serialize/TypeSerializer.h
the key is
```c++
#define TYPE_SERIALIZER(_type, _typeName) \
struct TypeSerializer<PARE _type> \
{ static constexpr decltype(auto) name = _typeName; }
template<> TYPE_SERIALIZER((int8_t), "int8_t"); // (1)
template<typename T>
TYPE_SERIALIZER((std::vector<T>),
concat("vector<", TypeSerializer<T>::name, ">")); // (2)
```
in case (1), the `name` type is `const char(&)[N]`, but in case(2), the `name`
type is `array[N]`, so I use `decltype(auto)` rather `auto`, becase latter
loses char length info.
I tried `static decltype(auto)` not work because it is defined in class, and
requires `constexpr`.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/102229] [11/12 Regression] 'decltype(auto)' cannot be cv-qualified
2021-09-07 13:33 [Bug c++/102229] New: 'decltype(auto)' cannot be cv-qualified netcan1996 at gmail dot com
` (6 preceding siblings ...)
2021-09-09 13:56 ` netcan1996 at gmail dot com
@ 2021-09-09 15:08 ` jason at gcc dot gnu.org
2021-12-09 13:58 ` mpolacek at gcc dot gnu.org
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2021-09-09 15:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102229
--- Comment #8 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #6)
> Thanks. With the latter interpretation in mind, it seems my earlier fix
> should be mitigated so that we allow
>
> constexpr decltype(auto)
> but not
> constexpr const decltype(auto)
>
> Yes?
I think so, yes.
> Do you want me to raise this with the CWG?
Please.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/102229] [11/12 Regression] 'decltype(auto)' cannot be cv-qualified
2021-09-07 13:33 [Bug c++/102229] New: 'decltype(auto)' cannot be cv-qualified netcan1996 at gmail dot com
` (7 preceding siblings ...)
2021-09-09 15:08 ` jason at gcc dot gnu.org
@ 2021-12-09 13:58 ` mpolacek at gcc dot gnu.org
2021-12-09 18:34 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-12-09 13:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102229
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/102229] [11/12 Regression] 'decltype(auto)' cannot be cv-qualified
2021-09-07 13:33 [Bug c++/102229] New: 'decltype(auto)' cannot be cv-qualified netcan1996 at gmail dot com
` (8 preceding siblings ...)
2021-12-09 13:58 ` mpolacek at gcc dot gnu.org
@ 2021-12-09 18:34 ` mpolacek at gcc dot gnu.org
2021-12-15 22:48 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-12-09 18:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102229
--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This is supposed to be valid, so I'll try to come up with a fix soon.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/102229] [11/12 Regression] 'decltype(auto)' cannot be cv-qualified
2021-09-07 13:33 [Bug c++/102229] New: 'decltype(auto)' cannot be cv-qualified netcan1996 at gmail dot com
` (9 preceding siblings ...)
2021-12-09 18:34 ` mpolacek at gcc dot gnu.org
@ 2021-12-15 22:48 ` cvs-commit at gcc dot gnu.org
2021-12-15 22:52 ` [Bug c++/102229] [11 " mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-12-15 22:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102229
--- Comment #10 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:06d5dcef72542baf49ac245cfde2ad7ecef0916b
commit r12-6008-g06d5dcef72542baf49ac245cfde2ad7ecef0916b
Author: Marek Polacek <polacek@redhat.com>
Date: Fri Dec 10 15:38:35 2021 -0500
c++: Allow constexpr decltype(auto) [PR102229]
My r11-2202 was trying to enforce [dcl.type.auto.deduct]/4, which says
"If the placeholder-type-specifier is of the form type-constraint[opt]
decltype(auto), T shall be the placeholder alone." But this made us
reject 'constexpr decltype(auto)', which, after clarification from CWG,
should be valid. [dcl.type.auto.deduct]/4 is supposed to be a syntactic
constraint, not semantic, so it's OK that the constexpr marks the object
as const.
As a consequence, checking TYPE_QUALS in do_auto_deduction is too late,
and we have a FIXME there anyway. So in this patch I'm attempting to
detect 'const decltype(auto)' earlier. If I'm going to use TYPE_QUALS,
it needs to happen before we mark the object as const due to constexpr,
that is, before grokdeclarator's
/* A `constexpr' specifier used in an object declaration declares
the object as `const'. */
if (constexpr_p && innermost_code != cdk_function)
...
Constrained decltype(auto) was a little problem, hence the TYPENAME
check. But in a typename context you can't use decltype(auto) anyway,
I think.
PR c++/102229
gcc/cp/ChangeLog:
* decl.c (check_decltype_auto): New.
(grokdeclarator): Call it.
* pt.c (do_auto_deduction): Don't check decltype(auto) here.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/decltype-auto5.C: New test.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/102229] [11 Regression] 'decltype(auto)' cannot be cv-qualified
2021-09-07 13:33 [Bug c++/102229] New: 'decltype(auto)' cannot be cv-qualified netcan1996 at gmail dot com
` (10 preceding siblings ...)
2021-12-15 22:48 ` cvs-commit at gcc dot gnu.org
@ 2021-12-15 22:52 ` mpolacek at gcc dot gnu.org
2022-01-03 23:45 ` cvs-commit at gcc dot gnu.org
2022-01-03 23:45 ` mpolacek at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-12-15 22:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102229
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[11/12 Regression] |[11 Regression]
|'decltype(auto)' cannot be |'decltype(auto)' cannot be
|cv-qualified |cv-qualified
--- Comment #11 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++/102229] [11 Regression] 'decltype(auto)' cannot be cv-qualified
2021-09-07 13:33 [Bug c++/102229] New: 'decltype(auto)' cannot be cv-qualified netcan1996 at gmail dot com
` (11 preceding siblings ...)
2021-12-15 22:52 ` [Bug c++/102229] [11 " mpolacek at gcc dot gnu.org
@ 2022-01-03 23:45 ` cvs-commit at gcc dot gnu.org
2022-01-03 23:45 ` mpolacek at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-03 23:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102229
--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Marek Polacek
<mpolacek@gcc.gnu.org>:
https://gcc.gnu.org/g:24ee44c37a28eae80430a1ad86ffb0923446db2d
commit r11-9430-g24ee44c37a28eae80430a1ad86ffb0923446db2d
Author: Marek Polacek <polacek@redhat.com>
Date: Fri Dec 10 15:38:35 2021 -0500
c++: Allow constexpr decltype(auto) [PR102229]
My r11-2202 was trying to enforce [dcl.type.auto.deduct]/4, which says
"If the placeholder-type-specifier is of the form type-constraint[opt]
decltype(auto), T shall be the placeholder alone." But this made us
reject 'constexpr decltype(auto)', which, after clarification from CWG,
should be valid. [dcl.type.auto.deduct]/4 is supposed to be a syntactic
constraint, not semantic, so it's OK that the constexpr marks the object
as const.
As a consequence, checking TYPE_QUALS in do_auto_deduction is too late,
and we have a FIXME there anyway. So in this patch I'm attempting to
detect 'const decltype(auto)' earlier. If I'm going to use TYPE_QUALS,
it needs to happen before we mark the object as const due to constexpr,
that is, before grokdeclarator's
/* A `constexpr' specifier used in an object declaration declares
the object as `const'. */
if (constexpr_p && innermost_code != cdk_function)
...
Constrained decltype(auto) was a little problem, hence the TYPENAME
check. But in a typename context you can't use decltype(auto) anyway,
I think.
PR c++/102229
gcc/cp/ChangeLog:
* decl.c (check_decltype_auto): New.
(grokdeclarator): Call it.
* pt.c (do_auto_deduction): Don't check decltype(auto) here.
gcc/testsuite/ChangeLog:
* g++.dg/cpp1y/decltype-auto5.C: New test.
(cherry picked from commit 06d5dcef72542baf49ac245cfde2ad7ecef0916b)
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/102229] [11 Regression] 'decltype(auto)' cannot be cv-qualified
2021-09-07 13:33 [Bug c++/102229] New: 'decltype(auto)' cannot be cv-qualified netcan1996 at gmail dot com
` (12 preceding siblings ...)
2022-01-03 23:45 ` cvs-commit at gcc dot gnu.org
@ 2022-01-03 23:45 ` mpolacek at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-01-03 23:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102229
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #13 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2022-01-03 23:45 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-07 13:33 [Bug c++/102229] New: 'decltype(auto)' cannot be cv-qualified netcan1996 at gmail dot com
2021-09-07 14:36 ` [Bug c++/102229] " marxin at gcc dot gnu.org
2021-09-07 14:37 ` [Bug c++/102229] [11/12 Regression] " rguenth at gcc dot gnu.org
2021-09-07 14:43 ` mpolacek at gcc dot gnu.org
2021-09-07 15:17 ` mpolacek at gcc dot gnu.org
2021-09-07 19:43 ` jason at gcc dot gnu.org
2021-09-07 20:06 ` mpolacek at gcc dot gnu.org
2021-09-09 13:56 ` netcan1996 at gmail dot com
2021-09-09 15:08 ` jason at gcc dot gnu.org
2021-12-09 13:58 ` mpolacek at gcc dot gnu.org
2021-12-09 18:34 ` mpolacek at gcc dot gnu.org
2021-12-15 22:48 ` cvs-commit at gcc dot gnu.org
2021-12-15 22:52 ` [Bug c++/102229] [11 " mpolacek at gcc dot gnu.org
2022-01-03 23:45 ` cvs-commit at gcc dot gnu.org
2022-01-03 23:45 ` mpolacek at gcc dot gnu.org
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).