public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103700] New: Incomplete type not causing constraints to fail
@ 2021-12-14  0:01 pinskia at gcc dot gnu.org
  2021-12-14  0:04 ` [Bug c++/103700] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-14  0:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103700
           Summary: Incomplete type not causing constraints to fail
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code, rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

>From PR 101239:
Take:
    auto f(auto a) requires requires { a+1; } { return a+1; }
    auto f(auto a) { return a; }
    struct Incomplete *p;
    auto b = f(p);

----- CUT ----
The pointer addition in the first declaration of f should cause the constraint
to fail but currently we get a hard error instead:
<source>: In substitution of 'template<class auto:1> auto f(auto:1) requires
requires{a + 1;} [with auto:1 = Incomplete*]':
<source>:5:15:   required from here
<source>:2:41: error: invalid use of incomplete type 'struct Incomplete'
    2 |     auto f(auto a) requires requires { a+1; } { return a+1; }
      |                                        ~^~
<source>:4:12: note: forward declaration of 'struct Incomplete'
    4 |     struct Incomplete *p;
      |            ^~~~~~~~~~

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

* [Bug c++/103700] Incomplete type not causing constraints to fail
  2021-12-14  0:01 [Bug c++/103700] New: Incomplete type not causing constraints to fail pinskia at gcc dot gnu.org
@ 2021-12-14  0:04 ` pinskia at gcc dot gnu.org
  2021-12-14  0:13 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-14  0:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is a C++14 testcase too:

template<class T>
    auto f(T a) -> decltype(a+1) { return a+1; }
template<class T>
    auto f(T a) {return a;}
struct Incomplete *p;
auto b = f(p);

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

* [Bug c++/103700] Incomplete type not causing constraints to fail
  2021-12-14  0:01 [Bug c++/103700] New: Incomplete type not causing constraints to fail pinskia at gcc dot gnu.org
  2021-12-14  0:04 ` [Bug c++/103700] " pinskia at gcc dot gnu.org
@ 2021-12-14  0:13 ` pinskia at gcc dot gnu.org
  2021-12-14  1:00 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-14  0:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
#0  cxx_incomplete_type_diagnostic (loc=2147483649, value=<tree 0x0>,
type=<record_type 0x7ffff73ab540 Incomplete>, diag_kind=DK_ERROR) at
/home/apinski/src/upstream-gcc/gcc/gcc/cp/typeck2.c:311
#1  0x0000000000f384bb in cxx_incomplete_type_error (loc=2147483649,
value=<tree 0x0>, type=<record_type 0x7ffff73ab540 Incomplete>) at
/home/apinski/src/upstream-gcc/gcc/gcc/cp/typeck2.c:458
#2  0x0000000001bee12d in size_in_bytes_loc (loc=2147483649, type=<record_type
0x7ffff73ab540 Incomplete>) at
/home/apinski/src/upstream-gcc/gcc/gcc/tree.c:3490
#3  0x0000000000f5cf26 in pointer_int_sum (loc=2147483649,
resultcode=PLUS_EXPR, ptrop=<view_convert_expr 0x7ffff73a3ba0>,
intop=<integer_cst 0x7ffff7264300>, complain=false) at
/home/apinski/src/upstream-gcc/gcc/gcc/c-family/c-common.c:3311
#4  0x0000000000f23079 in cp_pointer_int_sum (loc=2147483649,
resultcode=PLUS_EXPR, ptrop=<view_convert_expr 0x7ffff73a3ba0>,
intop=<integer_cst 0x7ffff7264300>, complain=128) at
/home/apinski/src/upstream-gcc/gcc/gcc/cp/typeck.c:6276

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

* [Bug c++/103700] Incomplete type not causing constraints to fail
  2021-12-14  0:01 [Bug c++/103700] New: Incomplete type not causing constraints to fail pinskia at gcc dot gnu.org
  2021-12-14  0:04 ` [Bug c++/103700] " pinskia at gcc dot gnu.org
  2021-12-14  0:13 ` pinskia at gcc dot gnu.org
@ 2021-12-14  1:00 ` pinskia at gcc dot gnu.org
  2021-12-22 16:51 ` ppalka at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-14  1:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think the right patch is to check to see if the pointed to type is complete
in pointer_int_sum before calling size_in_bytes_loc. But there is no function
call that is common between the C and C++ front-ends to check that.

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

* [Bug c++/103700] Incomplete type not causing constraints to fail
  2021-12-14  0:01 [Bug c++/103700] New: Incomplete type not causing constraints to fail pinskia at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-12-14  1:00 ` pinskia at gcc dot gnu.org
@ 2021-12-22 16:51 ` ppalka at gcc dot gnu.org
  2021-12-22 17:42 ` ppalka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-12-22 16:51 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-12-22
   Target Milestone|---                         |11.3
                 CC|                            |ppalka at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED

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

* [Bug c++/103700] Incomplete type not causing constraints to fail
  2021-12-14  0:01 [Bug c++/103700] New: Incomplete type not causing constraints to fail pinskia at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-12-22 16:51 ` ppalka at gcc dot gnu.org
@ 2021-12-22 17:42 ` ppalka at gcc dot gnu.org
  2021-12-22 21:17 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-12-22 17:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #3)
> I think the right patch is to check to see if the pointed to type is
> complete in pointer_int_sum before calling size_in_bytes_loc. But there is
> no function call that is common between the C and C++ front-ends to check
> that.

Hmm, can't we just check COMPLETE_TYPE_P in pointer_int_sum directly?  Patch to
that effect posted at
https://gcc.gnu.org/pipermail/gcc-patches/2021-December/587300.html.

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

* [Bug c++/103700] Incomplete type not causing constraints to fail
  2021-12-14  0:01 [Bug c++/103700] New: Incomplete type not causing constraints to fail pinskia at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2021-12-22 17:42 ` ppalka at gcc dot gnu.org
@ 2021-12-22 21:17 ` pinskia at gcc dot gnu.org
  2021-12-27 14:05 ` cvs-commit at gcc dot gnu.org
  2021-12-27 14:49 ` ppalka at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-22 21:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Patrick Palka from comment #4)
> Hmm, can't we just check COMPLETE_TYPE_P in pointer_int_sum directly?  Patch
> to that effect posted at
> https://gcc.gnu.org/pipermail/gcc-patches/2021-December/587300.html.

Yes that will work too. I was just quickly looking into how to fix it when I
write that comment really.

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

* [Bug c++/103700] Incomplete type not causing constraints to fail
  2021-12-14  0:01 [Bug c++/103700] New: Incomplete type not causing constraints to fail pinskia at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2021-12-22 21:17 ` pinskia at gcc dot gnu.org
@ 2021-12-27 14:05 ` cvs-commit at gcc dot gnu.org
  2021-12-27 14:49 ` ppalka at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-12-27 14:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:88cdcb5c18d73bfc9960d774c678f0e8103b8031

commit r12-6123-g88cdcb5c18d73bfc9960d774c678f0e8103b8031
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Dec 27 09:05:17 2021 -0500

    c++: hard error w/ ptr+N and incomplete type [PR103700]

    In pointer_int_sum when called from a SFINAE context, we need to avoid
    calling size_in_bytes_loc on an incomplete pointed-to type since this
    latter function isn't SFINAE-enabled and always emits an error on such
    input.

            PR c++/103700

    gcc/c-family/ChangeLog:

            * c-common.c (pointer_int_sum): When quiet, return
            error_mark_node for an incomplete pointed-to type and don't
            call size_in_bytes_loc.

    gcc/testsuite/ChangeLog:

            * g++.dg/template/sfinae32.C: New test.

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

* [Bug c++/103700] Incomplete type not causing constraints to fail
  2021-12-14  0:01 [Bug c++/103700] New: Incomplete type not causing constraints to fail pinskia at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2021-12-27 14:05 ` cvs-commit at gcc dot gnu.org
@ 2021-12-27 14:49 ` ppalka at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-12-27 14:49 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.3                        |12.0
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #7 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 12.  Not backporting to 11.3 since this isn't a regression and
can be worked around using sizeof I think.

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

end of thread, other threads:[~2021-12-27 14:49 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-14  0:01 [Bug c++/103700] New: Incomplete type not causing constraints to fail pinskia at gcc dot gnu.org
2021-12-14  0:04 ` [Bug c++/103700] " pinskia at gcc dot gnu.org
2021-12-14  0:13 ` pinskia at gcc dot gnu.org
2021-12-14  1:00 ` pinskia at gcc dot gnu.org
2021-12-22 16:51 ` ppalka at gcc dot gnu.org
2021-12-22 17:42 ` ppalka at gcc dot gnu.org
2021-12-22 21:17 ` pinskia at gcc dot gnu.org
2021-12-27 14:05 ` cvs-commit at gcc dot gnu.org
2021-12-27 14:49 ` ppalka 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).