public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115676] New: gcc allows invalid calling to implicitly-deleted default constructor of a template derived class in template function
@ 2024-06-27 9:14 rush102333 at gmail dot com
2024-06-27 19:51 ` [Bug c++/115676] [c++11-C++14] gcc allows invalid calling to implicitly-deleted default constructor of a template derived class (non-depdenent) " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: rush102333 at gmail dot com @ 2024-06-27 9:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115676
Bug ID: 115676
Summary: gcc allows invalid calling to implicitly-deleted
default constructor of a template derived class in
template function
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: rush102333 at gmail dot com
Target Milestone: ---
The following invalid code is accepted by gcc-13.2.0 and gcc-trunk:
~~~~~~~~~~~~~~~~~~~~~~
struct empty{
};
template <int size>
struct A
: public empty
{
const int is_valid;
};
template <class T>
void check_a()
{
const A<0> a {};
}
~~~~~~~~~~~~~~~~~~~~~~
It can be seen that the template class "A" is non-trivial because it has an
empty base class. Thus, the default constructor of "A" should be implicitly
deleted, and the initialization statement "const A<0> a{}" should be invalid.
But when the initialization happens in a template function, GCC seems to ignore
the error. Changing "check_a" to a non-template function can make the compiler
reject the code by giving the following error message:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>: In function 'void check_a()':
<source>:14:17: error: use of deleted function 'A<0>::A()'
14 | const A<0> a {};
| ^
<source>:5:8: note: 'A<0>::A()' is implicitly deleted because the default
definition would be ill-formed:
5 | struct A
| ^
<source>: At global scope:
<source>:5:8: error: uninitialized const member in 'struct A<0>'
<source>:8:15: note: 'const int A<0>::is_valid' should be initialized
8 | const int is_valid;
| ^~~~~~~~
<source>: In function 'void check_a()':
<source>:14:17: note: use '-fdiagnostics-all-candidates' to display considered
candidates
14 | const A<0> a {};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Please check https://godbolt.org/z/nGxPdn9jf
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/115676] [c++11-C++14] gcc allows invalid calling to implicitly-deleted default constructor of a template derived class (non-depdenent) in template function
2024-06-27 9:14 [Bug c++/115676] New: gcc allows invalid calling to implicitly-deleted default constructor of a template derived class in template function rush102333 at gmail dot com
@ 2024-06-27 19:51 ` pinskia at gcc dot gnu.org
2024-06-27 19:56 ` [Bug c++/115676] [c++11-C++14] gcc allows invalid calling to implicitly-deleted default constructor of a template derived class (non-dependent) " pinskia at gcc dot gnu.org
2024-06-28 2:02 ` xry111 at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-27 19:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115676
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|gcc allows invalid calling |[c++11-C++14] gcc allows
|to implicitly-deleted |invalid calling to
|default constructor of a |implicitly-deleted default
|template derived class in |constructor of a template
|template function |derived class
| |(non-depdenent) in template
| |function
CC| |pinskia at gcc dot gnu.org
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually I think this is just QoI case. IIRC the compiler does not require
error out if inside a template only if it is instantiated.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/115676] [c++11-C++14] gcc allows invalid calling to implicitly-deleted default constructor of a template derived class (non-dependent) in template function
2024-06-27 9:14 [Bug c++/115676] New: gcc allows invalid calling to implicitly-deleted default constructor of a template derived class in template function rush102333 at gmail dot com
2024-06-27 19:51 ` [Bug c++/115676] [c++11-C++14] gcc allows invalid calling to implicitly-deleted default constructor of a template derived class (non-depdenent) " pinskia at gcc dot gnu.org
@ 2024-06-27 19:56 ` pinskia at gcc dot gnu.org
2024-06-28 2:02 ` xry111 at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-27 19:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115676
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Yes see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55361#c5 for that ...
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/115676] [c++11-C++14] gcc allows invalid calling to implicitly-deleted default constructor of a template derived class (non-dependent) in template function
2024-06-27 9:14 [Bug c++/115676] New: gcc allows invalid calling to implicitly-deleted default constructor of a template derived class in template function rush102333 at gmail dot com
2024-06-27 19:51 ` [Bug c++/115676] [c++11-C++14] gcc allows invalid calling to implicitly-deleted default constructor of a template derived class (non-depdenent) " pinskia at gcc dot gnu.org
2024-06-27 19:56 ` [Bug c++/115676] [c++11-C++14] gcc allows invalid calling to implicitly-deleted default constructor of a template derived class (non-dependent) " pinskia at gcc dot gnu.org
@ 2024-06-28 2:02 ` xry111 at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: xry111 at gcc dot gnu.org @ 2024-06-28 2:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115676
Xi Ruoyao <xry111 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |xry111 at gcc dot gnu.org
--- Comment #3 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
Clang and MSVC give no diagnostic as well.
So like PR55361, "unless this is recategorised as a diagnostic enhancement
request this is clearly invalid, the compiler is not required to give an error
for this code."
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-06-28 2:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-27 9:14 [Bug c++/115676] New: gcc allows invalid calling to implicitly-deleted default constructor of a template derived class in template function rush102333 at gmail dot com
2024-06-27 19:51 ` [Bug c++/115676] [c++11-C++14] gcc allows invalid calling to implicitly-deleted default constructor of a template derived class (non-depdenent) " pinskia at gcc dot gnu.org
2024-06-27 19:56 ` [Bug c++/115676] [c++11-C++14] gcc allows invalid calling to implicitly-deleted default constructor of a template derived class (non-dependent) " pinskia at gcc dot gnu.org
2024-06-28 2:02 ` xry111 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).