public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102305] New: intrinsic __is_constrctible is wrong for templated abstract classes
@ 2021-09-13  9:54 andre.schackier at gmail dot com
  2021-09-13 10:16 ` [Bug c++/102305] " redi at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: andre.schackier at gmail dot com @ 2021-09-13  9:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102305

            Bug ID: 102305
           Summary: intrinsic __is_constrctible is wrong for templated
                    abstract classes
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andre.schackier at gmail dot com
  Target Milestone: ---

The compiler intrinsic function "__is_constructible" used to implement the
standard type traits falsy returns true for templated abstract classes. 

Minimal reproducable test case: (by Jonathan Wakely)

template <typename> struct AbstractTemplate {
  virtual ~AbstractTemplate() = 0;
};
static_assert(!__is_constructible(AbstractTemplate<int>), "");

Original godbolt link showcasing the problem with
std::is_default_constructible, which since version 9.2 uses __is_constructible 
https://godbolt.org/z/rq5GGd4rd

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/102305] intrinsic __is_constrctible is wrong for templated abstract classes
  2021-09-13  9:54 [Bug c++/102305] New: intrinsic __is_constrctible is wrong for templated abstract classes andre.schackier at gmail dot com
@ 2021-09-13 10:16 ` redi at gcc dot gnu.org
  2021-09-13 11:30 ` jakub at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-13 10:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102305

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-09-13
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/102305] intrinsic __is_constrctible is wrong for templated abstract classes
  2021-09-13  9:54 [Bug c++/102305] New: intrinsic __is_constrctible is wrong for templated abstract classes andre.schackier at gmail dot com
  2021-09-13 10:16 ` [Bug c++/102305] " redi at gcc dot gnu.org
@ 2021-09-13 11:30 ` jakub at gcc dot gnu.org
  2021-09-13 12:35 ` [Bug c++/102305] intrinsic __is_constructible " redi at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-09-13 11:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102305

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 51447
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51447&action=edit
gcc12-pr102305.patch

Untested fix.
is_xible_helper checks ABSTRACT_CLASS_TYPE_P (to) and returns error_mark_node
if it is true, but when to is yet uninstantiated class template, it is false
and the template is instantiated only later on when trying to make the dummy
object.
With this patch we instantiate it before checking for abstract classes, but
will keep rejecting it or dealing with arrays of unknown bound till the spots
that were checking for that before.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/102305] intrinsic __is_constructible is wrong for templated abstract classes
  2021-09-13  9:54 [Bug c++/102305] New: intrinsic __is_constrctible is wrong for templated abstract classes andre.schackier at gmail dot com
  2021-09-13 10:16 ` [Bug c++/102305] " redi at gcc dot gnu.org
  2021-09-13 11:30 ` jakub at gcc dot gnu.org
@ 2021-09-13 12:35 ` redi at gcc dot gnu.org
  2021-09-14 14:56 ` cvs-commit at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-13 12:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102305

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Thanks, Jakub!

Although this is a component=c++ bug, it also results in a libstdc++
regression, because we've been giving the wrong answer since starting to use
the intrinsic (e.g. std::is_default_constructible started to use it in GCC
9.2).

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/102305] intrinsic __is_constructible is wrong for templated abstract classes
  2021-09-13  9:54 [Bug c++/102305] New: intrinsic __is_constrctible is wrong for templated abstract classes andre.schackier at gmail dot com
                   ` (2 preceding siblings ...)
  2021-09-13 12:35 ` [Bug c++/102305] intrinsic __is_constructible " redi at gcc dot gnu.org
@ 2021-09-14 14:56 ` cvs-commit at gcc dot gnu.org
  2021-09-14 14:58 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-14 14:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102305

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:f008fd3a480e3718436156697ebe7eeb47841457

commit r12-3525-gf008fd3a480e3718436156697ebe7eeb47841457
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Sep 14 16:55:04 2021 +0200

    c++: Fix __is_*constructible/assignable for templates [PR102305]

    is_xible_helper returns error_mark_node (i.e. false from the traits)
    for abstract classes by testing ABSTRACT_CLASS_TYPE_P (to) early.
    Unfortunately, as the testcase shows, that doesn't work on class templates
    that haven't been instantiated yet, ABSTRACT_CLASS_TYPE_P for them is false
    until it is instantiated, which is done when the routine later constructs
    a dummy object with that type.

    The following patch fixes this by calling complete_type first, so that
    ABSTRACT_CLASS_TYPE_P test will work properly, while keeping the handling
    of arrays with unknown bounds, or incomplete types where it is done
    currently.

    2021-09-14  Jakub Jelinek  <jakub@redhat.com>

            PR c++/102305
            * method.c (is_xible_helper): Call complete_type on to.

            * g++.dg/cpp0x/pr102305.C: New test.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/102305] intrinsic __is_constructible is wrong for templated abstract classes
  2021-09-13  9:54 [Bug c++/102305] New: intrinsic __is_constrctible is wrong for templated abstract classes andre.schackier at gmail dot com
                   ` (3 preceding siblings ...)
  2021-09-14 14:56 ` cvs-commit at gcc dot gnu.org
@ 2021-09-14 14:58 ` jakub at gcc dot gnu.org
  2021-09-14 15:05 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-09-14 14:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102305

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 12.0 so far.
Do we want to backport it?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/102305] intrinsic __is_constructible is wrong for templated abstract classes
  2021-09-13  9:54 [Bug c++/102305] New: intrinsic __is_constrctible is wrong for templated abstract classes andre.schackier at gmail dot com
                   ` (4 preceding siblings ...)
  2021-09-14 14:58 ` jakub at gcc dot gnu.org
@ 2021-09-14 15:05 ` jakub at gcc dot gnu.org
  2021-09-14 15:14 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-09-14 15:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102305

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
On one side, some code could be relying on bug compatibility and so it would be
undesirable to change it on release branches, on the other side the current
behavior there is just weird,
#include <type_traits>

template <typename> struct AbstractTemplate {
  virtual ~AbstractTemplate() = 0;
};

#ifdef D
struct S : AbstractTemplate<int> {};
#endif
bool a = std::is_default_constructible<AbstractTemplate<int> >::value;

a is true if D is not defined and false if D is defined.  And one can't really
construct those abstract template classes...

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/102305] intrinsic __is_constructible is wrong for templated abstract classes
  2021-09-13  9:54 [Bug c++/102305] New: intrinsic __is_constrctible is wrong for templated abstract classes andre.schackier at gmail dot com
                   ` (5 preceding siblings ...)
  2021-09-14 15:05 ` jakub at gcc dot gnu.org
@ 2021-09-14 15:14 ` redi at gcc dot gnu.org
  2021-09-15 23:05 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2021-09-14 15:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102305

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It should be backported IMHO.

I don't see how anybody can be relying on is_default_constructible being wrong,
that doesn't make much sense. You check that trait in SFINAE contexts to see if
you can construct the type, but because the answer is wrong any code that tries
to construct it will get a compiler error.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/102305] intrinsic __is_constructible is wrong for templated abstract classes
  2021-09-13  9:54 [Bug c++/102305] New: intrinsic __is_constrctible is wrong for templated abstract classes andre.schackier at gmail dot com
                   ` (6 preceding siblings ...)
  2021-09-14 15:14 ` redi at gcc dot gnu.org
@ 2021-09-15 23:05 ` cvs-commit at gcc dot gnu.org
  2021-09-16  8:49 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-09-15 23:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102305

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:6f61195e0433f907e5aa1a16f02d4106503d3351

commit r11-8997-g6f61195e0433f907e5aa1a16f02d4106503d3351
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Sep 14 16:55:04 2021 +0200

    c++: Fix __is_*constructible/assignable for templates [PR102305]

    is_xible_helper returns error_mark_node (i.e. false from the traits)
    for abstract classes by testing ABSTRACT_CLASS_TYPE_P (to) early.
    Unfortunately, as the testcase shows, that doesn't work on class templates
    that haven't been instantiated yet, ABSTRACT_CLASS_TYPE_P for them is false
    until it is instantiated, which is done when the routine later constructs
    a dummy object with that type.

    The following patch fixes this by calling complete_type first, so that
    ABSTRACT_CLASS_TYPE_P test will work properly, while keeping the handling
    of arrays with unknown bounds, or incomplete types where it is done
    currently.

    2021-09-14  Jakub Jelinek  <jakub@redhat.com>

            PR c++/102305
            * method.c (is_xible_helper): Call complete_type on to.

            * g++.dg/cpp0x/pr102305.C: New test.

    (cherry picked from commit f008fd3a480e3718436156697ebe7eeb47841457)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/102305] intrinsic __is_constructible is wrong for templated abstract classes
  2021-09-13  9:54 [Bug c++/102305] New: intrinsic __is_constrctible is wrong for templated abstract classes andre.schackier at gmail dot com
                   ` (7 preceding siblings ...)
  2021-09-15 23:05 ` cvs-commit at gcc dot gnu.org
@ 2021-09-16  8:49 ` jakub at gcc dot gnu.org
  2022-05-10  8:20 ` [Bug c++/102305] [9/10 regression] " cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-09-16  8:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102305

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 11.3+ now too.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/102305] [9/10 regression] intrinsic __is_constructible is wrong for templated abstract classes
  2021-09-13  9:54 [Bug c++/102305] New: intrinsic __is_constrctible is wrong for templated abstract classes andre.schackier at gmail dot com
                   ` (8 preceding siblings ...)
  2021-09-16  8:49 ` jakub at gcc dot gnu.org
@ 2022-05-10  8:20 ` cvs-commit at gcc dot gnu.org
  2022-05-11  6:22 ` cvs-commit at gcc dot gnu.org
  2022-05-11  6:36 ` jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-10  8:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102305

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:269c6ed92a7dcfdacfa4a7ade2dc0616928b9b9b

commit r10-10642-g269c6ed92a7dcfdacfa4a7ade2dc0616928b9b9b
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Sep 14 16:55:04 2021 +0200

    c++: Fix __is_*constructible/assignable for templates [PR102305]

    is_xible_helper returns error_mark_node (i.e. false from the traits)
    for abstract classes by testing ABSTRACT_CLASS_TYPE_P (to) early.
    Unfortunately, as the testcase shows, that doesn't work on class templates
    that haven't been instantiated yet, ABSTRACT_CLASS_TYPE_P for them is false
    until it is instantiated, which is done when the routine later constructs
    a dummy object with that type.

    The following patch fixes this by calling complete_type first, so that
    ABSTRACT_CLASS_TYPE_P test will work properly, while keeping the handling
    of arrays with unknown bounds, or incomplete types where it is done
    currently.

    2021-09-14  Jakub Jelinek  <jakub@redhat.com>

            PR c++/102305
            * method.c (is_xible_helper): Call complete_type on to.

            * g++.dg/cpp0x/pr102305.C: New test.

    (cherry picked from commit f008fd3a480e3718436156697ebe7eeb47841457)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/102305] [9/10 regression] intrinsic __is_constructible is wrong for templated abstract classes
  2021-09-13  9:54 [Bug c++/102305] New: intrinsic __is_constrctible is wrong for templated abstract classes andre.schackier at gmail dot com
                   ` (9 preceding siblings ...)
  2022-05-10  8:20 ` [Bug c++/102305] [9/10 regression] " cvs-commit at gcc dot gnu.org
@ 2022-05-11  6:22 ` cvs-commit at gcc dot gnu.org
  2022-05-11  6:36 ` jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-11  6:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102305

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:edb57ecb1bcdcfef4ebc0ee78976d5718fcb00b2

commit r9-10099-gedb57ecb1bcdcfef4ebc0ee78976d5718fcb00b2
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Sep 14 16:55:04 2021 +0200

    c++: Fix __is_*constructible/assignable for templates [PR102305]

    is_xible_helper returns error_mark_node (i.e. false from the traits)
    for abstract classes by testing ABSTRACT_CLASS_TYPE_P (to) early.
    Unfortunately, as the testcase shows, that doesn't work on class templates
    that haven't been instantiated yet, ABSTRACT_CLASS_TYPE_P for them is false
    until it is instantiated, which is done when the routine later constructs
    a dummy object with that type.

    The following patch fixes this by calling complete_type first, so that
    ABSTRACT_CLASS_TYPE_P test will work properly, while keeping the handling
    of arrays with unknown bounds, or incomplete types where it is done
    currently.

    2021-09-14  Jakub Jelinek  <jakub@redhat.com>

            PR c++/102305
            * method.c (is_xible_helper): Call complete_type on to.

            * g++.dg/cpp0x/pr102305.C: New test.

    (cherry picked from commit f008fd3a480e3718436156697ebe7eeb47841457)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/102305] [9/10 regression] intrinsic __is_constructible is wrong for templated abstract classes
  2021-09-13  9:54 [Bug c++/102305] New: intrinsic __is_constrctible is wrong for templated abstract classes andre.schackier at gmail dot com
                   ` (10 preceding siblings ...)
  2022-05-11  6:22 ` cvs-commit at gcc dot gnu.org
@ 2022-05-11  6:36 ` jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-05-11  6:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102305

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-05-11  6:36 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-13  9:54 [Bug c++/102305] New: intrinsic __is_constrctible is wrong for templated abstract classes andre.schackier at gmail dot com
2021-09-13 10:16 ` [Bug c++/102305] " redi at gcc dot gnu.org
2021-09-13 11:30 ` jakub at gcc dot gnu.org
2021-09-13 12:35 ` [Bug c++/102305] intrinsic __is_constructible " redi at gcc dot gnu.org
2021-09-14 14:56 ` cvs-commit at gcc dot gnu.org
2021-09-14 14:58 ` jakub at gcc dot gnu.org
2021-09-14 15:05 ` jakub at gcc dot gnu.org
2021-09-14 15:14 ` redi at gcc dot gnu.org
2021-09-15 23:05 ` cvs-commit at gcc dot gnu.org
2021-09-16  8:49 ` jakub at gcc dot gnu.org
2022-05-10  8:20 ` [Bug c++/102305] [9/10 regression] " cvs-commit at gcc dot gnu.org
2022-05-11  6:22 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:36 ` jakub 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).