public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104041] New: static_assert failure triggered by non-selected template specialization
@ 2022-01-15 8:54 bugzilla at cems dot de
2022-01-15 9:03 ` [Bug c++/104041] " pinskia at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: bugzilla at cems dot de @ 2022-01-15 8:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104041
Bug ID: 104041
Summary: static_assert failure triggered by non-selected
template specialization
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: bugzilla at cems dot de
Target Milestone: ---
A static_assert failure can be triggered even by a template specialization that
is not selected.
The following code selects the specialization C<int> if allowed to compile, but
compilation fails if there is a failing static_assert in the generic template
C<T>, despite it not being selected.
#include <iostream>
template <typename T> struct C
{ C(T) {
#ifdef DEBUG
static_assert(false, "C<T> selected");
#endif
std::cout << "C<T> selected"; }
};
template <> struct C<int>
{ C(int) { std::cout << "C<int> selected"; }
};
int main()
{ C c(1);
}
/*
with macro DEBUG defined, compilation error with diagnostic:
error: static assertion failed: C<T> selected
without macro DEBUG defined, compiles and runs with output:
C<int> selected
*/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/104041] static_assert failure triggered by non-selected template specialization
2022-01-15 8:54 [Bug c++/104041] New: static_assert failure triggered by non-selected template specialization bugzilla at cems dot de
@ 2022-01-15 9:03 ` pinskia at gcc dot gnu.org
2022-01-15 9:19 ` bugzilla at cems dot de
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-15 9:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104041
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Since the value that is done in the static_assert is not value dependent, it is
rejected at the definition time of C<T>::C<T>.
This is correct.
Can you use either do the following instead:
template <typename T> struct C
{
C(T) = delete;
};
Which requires a specialization for C<T>::C<T> so it will not be a deleted
constructor.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/104041] static_assert failure triggered by non-selected template specialization
2022-01-15 8:54 [Bug c++/104041] New: static_assert failure triggered by non-selected template specialization bugzilla at cems dot de
2022-01-15 9:03 ` [Bug c++/104041] " pinskia at gcc dot gnu.org
@ 2022-01-15 9:19 ` bugzilla at cems dot de
2022-01-15 9:20 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: bugzilla at cems dot de @ 2022-01-15 9:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104041
bugzilla at cems dot de changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|INVALID |FIXED
--- Comment #2 from bugzilla at cems dot de ---
(In reply to Andrew Pinski from comment #1)
> Since the value that is done in the static_assert is not value dependent, it
> is rejected at the definition time of C<T>::C<T>.
>
> This is correct.
So if I replace the condition in the static_assert by something which is value
dependent,it will not be triggered in an unselected specialization even if the
condition is always false, e.g.:
static_assert(sizeof(T) < 0, "C<T> selected");
OK, thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/104041] static_assert failure triggered by non-selected template specialization
2022-01-15 8:54 [Bug c++/104041] New: static_assert failure triggered by non-selected template specialization bugzilla at cems dot de
2022-01-15 9:03 ` [Bug c++/104041] " pinskia at gcc dot gnu.org
2022-01-15 9:19 ` bugzilla at cems dot de
@ 2022-01-15 9:20 ` pinskia at gcc dot gnu.org
2022-01-15 12:24 ` redi at gcc dot gnu.org
2023-02-18 21:19 ` cvs-commit at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-15 9:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104041
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|FIXED |INVALID
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/104041] static_assert failure triggered by non-selected template specialization
2022-01-15 8:54 [Bug c++/104041] New: static_assert failure triggered by non-selected template specialization bugzilla at cems dot de
` (2 preceding siblings ...)
2022-01-15 9:20 ` pinskia at gcc dot gnu.org
@ 2022-01-15 12:24 ` redi at gcc dot gnu.org
2023-02-18 21:19 ` cvs-commit at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2022-01-15 12:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104041
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Please don't change the resolution to FIXED. There was no GCC bug, and so
nothing was fixed. The correct resolution is INVALID.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/104041] static_assert failure triggered by non-selected template specialization
2022-01-15 8:54 [Bug c++/104041] New: static_assert failure triggered by non-selected template specialization bugzilla at cems dot de
` (3 preceding siblings ...)
2022-01-15 12:24 ` redi at gcc dot gnu.org
@ 2023-02-18 21:19 ` cvs-commit at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-18 21:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104041
--- Comment #4 from CVS 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:9944ca17c0766623bce260684edc614def7ea761
commit r13-6133-g9944ca17c0766623bce260684edc614def7ea761
Author: Jason Merrill <jason@redhat.com>
Date: Fri Feb 10 16:16:45 2023 -0800
c++: static_assert (false) in template [DR2518]
For a long time, people have expected to be able to write
static_assert (false) in a template and only have it diagnosed if the
template is instantiated, but we (and other implementations) gave an error
about the uninstantiated template because the standard says that if no
valid
instantiation of the template is possible, the program is ill-formed, no
diagnostic required, and we try to diagnose IFNDR things when feasible.
At the meeting last week we were looking at CWG2518, which wanted to
specify
that an implementation must not accept a program containing a failing
#error
or static_assert. We also looked at P2593, which proposed allowing
static_assert in an uninstantiated template. We ended up combining these
two in order to avoid requiring implementations to reject programs with
static_assert (false) in uninstantiated templates.
The committee accepted this as a DR, so I'm making the change to all
standard modes. This behavior was also conformant previously, since no
diagnostic was required in this case.
We continue to diagnose non-constant or otherwise ill-formed conditions, so
no changes to existing tests were needed.
DR 2518
PR c++/52809
PR c++/53638
PR c++/87389
PR c++/89741
PR c++/92099
PR c++/104041
PR c++/104691
gcc/cp/ChangeLog:
* semantics.cc (finish_static_assert): Don't diagnose in
template context.
gcc/testsuite/ChangeLog:
* g++.dg/DRs/dr2518.C: New test.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-02-18 21:19 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-15 8:54 [Bug c++/104041] New: static_assert failure triggered by non-selected template specialization bugzilla at cems dot de
2022-01-15 9:03 ` [Bug c++/104041] " pinskia at gcc dot gnu.org
2022-01-15 9:19 ` bugzilla at cems dot de
2022-01-15 9:20 ` pinskia at gcc dot gnu.org
2022-01-15 12:24 ` redi at gcc dot gnu.org
2023-02-18 21:19 ` cvs-commit 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).