public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112594] New: Non-type template parameter created with converting constructor sometimes has original type
@ 2023-11-17 17:36 mital at mitalashok dot co.uk
2023-11-20 5:05 ` [Bug c++/112594] " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: mital at mitalashok dot co.uk @ 2023-11-17 17:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112594
Bug ID: 112594
Summary: Non-type template parameter created with converting
constructor sometimes has original type
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mital at mitalashok dot co.uk
Target Milestone: ---
The following code complains that `N` (which was declared `n N`) is `3` (of
type `int`) instead of `n(3)`:
<https://godbolt.org/z/rv3777Ycv>
template<typename T>
concept C = true;
struct n {
constexpr n(int) {}
static int i;
};
template<n N>
using get_n_i_type = decltype(N.i);
template<int X>
int f() {
using iii = get_n_i_type<X>;
#if 1 // Change to 0 and this compiles
static_assert(C<iii>);
#endif
return iii{};
}
template int f<3>();
Compiler error given:
<source>: In instantiation of 'int f() [with int X = 3]':
<source>:21:19: required from here
21 | template int f<3>();
| ^
<source>:10:33: error: request for member 'i' in '3', which is of non-class
type 'int'
10 | using get_n_i_type = decltype(N.i);
| ~~^
This compiles fine if Clang and MSVC or if you remove the static_assert or
change `template<int X>` to `template<auto X>`.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/112594] Non-type template parameter created with converting constructor sometimes has original type
2023-11-17 17:36 [Bug c++/112594] New: Non-type template parameter created with converting constructor sometimes has original type mital at mitalashok dot co.uk
@ 2023-11-20 5:05 ` pinskia at gcc dot gnu.org
2023-11-20 5:09 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-20 5:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112594
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2023-11-20
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
This fails in a similar way so it is not related to i being static here:
```
template<typename T>
concept C = true;
struct n {
constexpr n(int a) : i(a) {}
int i;
};
template<n N>
using get_n_i_type = decltype(N.i);
template<int X>
int f() {
using iii = get_n_i_type<X>;
#if 1 // Change to 0 and this compiles
static_assert(C<iii>);
#endif
return iii{};
}
template int f<3>();
```
I will file another related bug seperately which seems like a regression on the
trunk.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/112594] Non-type template parameter created with converting constructor sometimes has original type
2023-11-17 17:36 [Bug c++/112594] New: Non-type template parameter created with converting constructor sometimes has original type mital at mitalashok dot co.uk
2023-11-20 5:05 ` [Bug c++/112594] " pinskia at gcc dot gnu.org
@ 2023-11-20 5:09 ` pinskia at gcc dot gnu.org
2024-01-19 18:35 ` cvs-commit at gcc dot gnu.org
2024-01-19 18:37 ` jason at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-20 5:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112594
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
>
> I will file another related bug seperately which seems like a regression on
> the trunk.
Filed PR 112632 for that case, basically using `inline constexpr` rather than
`conccept` used to work in GCC 13 but fails on the trunk ...
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/112594] Non-type template parameter created with converting constructor sometimes has original type
2023-11-17 17:36 [Bug c++/112594] New: Non-type template parameter created with converting constructor sometimes has original type mital at mitalashok dot co.uk
2023-11-20 5:05 ` [Bug c++/112594] " pinskia at gcc dot gnu.org
2023-11-20 5:09 ` pinskia at gcc dot gnu.org
@ 2024-01-19 18:35 ` cvs-commit at gcc dot gnu.org
2024-01-19 18:37 ` jason at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-19 18:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112594
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:
https://gcc.gnu.org/g:f1e5bf0d83ee4da81b6317c6d7f1278fe7eaa5a0
commit r14-8291-gf1e5bf0d83ee4da81b6317c6d7f1278fe7eaa5a0
Author: Jason Merrill <jason@redhat.com>
Date: Wed Jan 17 17:29:33 2024 -0500
c++: alias template argument conversion [PR112632]
We've had a problem with lost conversions to template parameter types for a
while now; looking at this PR, it occurred to me that the problem is really
with alias (and concept) templates, since we do substitution of dependent
arguments into them in a way that we don't for other templates. And fixing
that specific problem is a lot simpler than adding IMPLICIT_CONV_EXPR
around
all dependent template arguments the way I gave up on for 111357.
The other part of the fix was changing tsubst_expr to actually call
convert_nontype_argument instead of assuming it will eventually happen.
I waffled about stripping the forced conversion when !force_conv
vs. skipping them in iterative_hash_template_arg and
template_args_equal (like we already do for some other conversions) and
decided to go with the former, but that isn't a strong preference if it
turns out to be somehow problematic.
PR c++/112632
PR c++/112594
PR c++/111357
PR c++/104594
PR c++/67898
gcc/cp/ChangeLog:
* cp-tree.h (IMPLICIT_CONV_EXPR_FORCED): New.
* pt.cc (expand_integer_pack): Remove 111357 workaround.
(maybe_convert_nontype_argument): Add force parm.
(convert_template_argument): Handle alias template args
specially.
(tsubst_expr): Don't ignore IMPLICIT_CONV_EXPR_NONTYPE_ARG.
* error.cc (dump_expr) [CASE_CONVERT]: Handle null optype.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/alias-decl-nontype1.C: New test.
* g++.dg/cpp2a/concepts-narrowing1.C: New test.
* g++.dg/cpp2a/nontype-class63.C: New test.
* g++.dg/cpp2a/nontype-class63a.C: New test.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/112594] Non-type template parameter created with converting constructor sometimes has original type
2023-11-17 17:36 [Bug c++/112594] New: Non-type template parameter created with converting constructor sometimes has original type mital at mitalashok dot co.uk
` (2 preceding siblings ...)
2024-01-19 18:35 ` cvs-commit at gcc dot gnu.org
@ 2024-01-19 18:37 ` jason at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2024-01-19 18:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112594
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
CC| |jason at gcc dot gnu.org
Target Milestone|--- |14.0
--- Comment #4 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 14.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-01-19 18:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-17 17:36 [Bug c++/112594] New: Non-type template parameter created with converting constructor sometimes has original type mital at mitalashok dot co.uk
2023-11-20 5:05 ` [Bug c++/112594] " pinskia at gcc dot gnu.org
2023-11-20 5:09 ` pinskia at gcc dot gnu.org
2024-01-19 18:35 ` cvs-commit at gcc dot gnu.org
2024-01-19 18:37 ` jason 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).