public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/101236] New: [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’
@ 2021-06-28  8:17 marxin at gcc dot gnu.org
  2021-06-28  8:18 ` [Bug libstdc++/101236] [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ since r12-1778-g17bc3848e065c0980523e1a1592f2f03b24b4f1c marxin at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-06-28  8:17 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101236
           Summary: [12 Regression] bits/unique_ptr.h:658:48: error:
                    invalid use of incomplete type ‘class llvm::APFloat’
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
                CC: jwakely at redhat dot com
  Target Milestone: ---

Created attachment 51068
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51068&action=edit
test-case

Happens when one builds something that uses libLLVM:

$ g++ AggregateToScalar.ii -c
In file included from /home/marxin/bin/gcc2/include/c++/12.0.0/memory:76,
                 from /usr/include/llvm/ADT/SmallVector.h:30,
                 from /usr/include/llvm/ADT/ArrayRef.h:14,
                 from /usr/include/llvm/ADT/DenseMapInfo.h:18,
                 from /usr/include/llvm/ADT/DenseMap.h:16,
                 from
/home/marxin/Programming/cvise/clang_delta/AggregateToScalar.h:16,
                 from
/home/marxin/Programming/cvise/clang_delta/AggregateToScalar.cpp:15:
/home/marxin/bin/gcc2/include/c++/12.0.0/bits/unique_ptr.h: In instantiation of
‘typename std::add_lvalue_reference<_Tp>::type std::unique_ptr<_Tp [],
_Dp>::operator[](std::size_t) const [with _Tp = llvm::APFloat; _Dp =
std::default_delete<llvm::APFloat []>; typename
std::add_lvalue_reference<_Tp>::type = llvm::APFloat&; std::size_t = long
unsigned int]’:
/usr/include/llvm/ADT/APFloat.h:634:40:   required from here
/home/marxin/bin/gcc2/include/c++/12.0.0/bits/unique_ptr.h:658:48: error:
invalid use of incomplete type ‘class llvm::APFloat’
  658 |      
noexcept(noexcept(std::declval<pointer>()[std::declval<size_t&>()]))
      |                         ~~~~~~~~~~~~~~~~~~~~~~~^
In file included from /usr/include/clang/AST/APValue.h:17,
                 from /usr/include/clang/AST/Decl.h:16,
                 from /usr/include/clang/AST/Attr.h:18,
                 from /usr/include/clang/AST/RecursiveASTVisitor.h:16,
                 from
/home/marxin/Programming/cvise/clang_delta/AggregateToScalar.cpp:19:
/usr/include/llvm/ADT/APFixedPoint.h:25:7: note: forward declaration of ‘class
llvm::APFloat’
   25 | class APFloat;
      |       ^~~~~~~

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

* [Bug libstdc++/101236] [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ since r12-1778-g17bc3848e065c0980523e1a1592f2f03b24b4f1c
  2021-06-28  8:17 [Bug libstdc++/101236] New: [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ marxin at gcc dot gnu.org
@ 2021-06-28  8:18 ` marxin at gcc dot gnu.org
  2021-06-28  9:13 ` rguenth at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-06-28  8:18 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
            Summary|[12 Regression]             |[12 Regression]
                   |bits/unique_ptr.h:658:48:   |bits/unique_ptr.h:658:48:
                   |error: invalid use of       |error: invalid use of
                   |incomplete type ‘class      |incomplete type ‘class
                   |llvm::APFloat’              |llvm::APFloat’ since
                   |                            |r12-1778-g17bc3848e065c0980
                   |                            |523e1a1592f2f03b24b4f1c
   Last reconfirmed|                            |2021-06-28
     Ever confirmed|0                           |1

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r12-1778-g17bc3848e065c0980523e1a1592f2f03b24b4f1c.

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

* [Bug libstdc++/101236] [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ since r12-1778-g17bc3848e065c0980523e1a1592f2f03b24b4f1c
  2021-06-28  8:17 [Bug libstdc++/101236] New: [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ marxin at gcc dot gnu.org
  2021-06-28  8:18 ` [Bug libstdc++/101236] [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ since r12-1778-g17bc3848e065c0980523e1a1592f2f03b24b4f1c marxin at gcc dot gnu.org
@ 2021-06-28  9:13 ` rguenth at gcc dot gnu.org
  2021-06-28  9:41 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-06-28  9:13 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0

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

* [Bug libstdc++/101236] [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ since r12-1778-g17bc3848e065c0980523e1a1592f2f03b24b4f1c
  2021-06-28  8:17 [Bug libstdc++/101236] New: [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ marxin at gcc dot gnu.org
  2021-06-28  8:18 ` [Bug libstdc++/101236] [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ since r12-1778-g17bc3848e065c0980523e1a1592f2f03b24b4f1c marxin at gcc dot gnu.org
  2021-06-28  9:13 ` rguenth at gcc dot gnu.org
@ 2021-06-28  9:41 ` redi at gcc dot gnu.org
  2021-06-28 10:18 ` marxin at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2021-06-28  9:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|NEW                         |RESOLVED

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
You can use incomplete types with std::unique_ptr<T> but the array
specialization, std::unique_ptr<T[]>, requires T to be a complete type. See
[unique.ptr.runtime.general] p3 in the C++ standard. That requirement has been
there since std::unique_ptr<T[]> was added in C++11.


So the code is invalid. LLVM needs to ensure the type is complete, or not use
std::unique_ptr<T[]> there.

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

* [Bug libstdc++/101236] [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ since r12-1778-g17bc3848e065c0980523e1a1592f2f03b24b4f1c
  2021-06-28  8:17 [Bug libstdc++/101236] New: [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ marxin at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-06-28  9:41 ` redi at gcc dot gnu.org
@ 2021-06-28 10:18 ` marxin at gcc dot gnu.org
  2021-06-28 10:25 ` redi at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-06-28 10:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
All right, thanks Jonathan.
I've just created LLVM bug for it: https://bugs.llvm.org/show_bug.cgi?id=50921

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

* [Bug libstdc++/101236] [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ since r12-1778-g17bc3848e065c0980523e1a1592f2f03b24b4f1c
  2021-06-28  8:17 [Bug libstdc++/101236] New: [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ marxin at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-06-28 10:18 ` marxin at gcc dot gnu.org
@ 2021-06-28 10:25 ` redi at gcc dot gnu.org
  2021-06-28 11:51 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2021-06-28 10:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |101239

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I tried this workaround in unique_ptr so that the undefined LLVM code would
"work" as before:

--- a/libstdc++-v3/include/bits/unique_ptr.h
+++ b/libstdc++-v3/include/bits/unique_ptr.h
@@ -491,6 +491,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          = __and_< is_base_of<_Tp, _Up>,
                    __not_<is_same<__remove_cv<_Tp>, __remove_cv<_Up>>> >;

+      template<typename _Ptr>
+       static constexpr auto
+       _S_nothrow_deref(_Ptr __p = _Ptr(), size_t __n = 0)
+       -> decltype(noexcept(__p[__n]))
+       { return noexcept(__p[__n]); }
+
+      template<typename _Ptr>
+       static constexpr bool
+       _S_nothrow_deref(...)
+       { return noexcept(__p[__n]); }
+
     public:
       using pointer      = typename __uniq_ptr_impl<_Tp, _Dp>::pointer;
       using element_type  = _Tp;
@@ -654,8 +665,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION

       /// Access an element of owned array.
       typename std::add_lvalue_reference<element_type>::type
-      operator[](size_t __i) const
-      noexcept(noexcept(std::declval<pointer>()[std::declval<size_t&>()]))
+      operator[](size_t __i) const noexcept(_S_nothrow_deref<pointer>())
       {
        __glibcxx_assert(get() != pointer());
        return get()[__i];


But this gets an ICE, see PR 101239


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101239
[Bug 101239] "Internal compiler error: Error reporting routines re-entered." in
size_in_bytes_loc

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

* [Bug libstdc++/101236] [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ since r12-1778-g17bc3848e065c0980523e1a1592f2f03b24b4f1c
  2021-06-28  8:17 [Bug libstdc++/101236] New: [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ marxin at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2021-06-28 10:25 ` redi at gcc dot gnu.org
@ 2021-06-28 11:51 ` redi at gcc dot gnu.org
  2021-06-28 13:23 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2021-06-28 11:51 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
         Resolution|INVALID                     |---

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I have a working workaround. The LLVM code is undefined, but we can make it
work.

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

* [Bug libstdc++/101236] [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ since r12-1778-g17bc3848e065c0980523e1a1592f2f03b24b4f1c
  2021-06-28  8:17 [Bug libstdc++/101236] New: [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ marxin at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2021-06-28 11:51 ` redi at gcc dot gnu.org
@ 2021-06-28 13:23 ` cvs-commit at gcc dot gnu.org
  2021-06-28 13:27 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-28 13:23 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

commit r12-1844-gb7a89c041aa1d67654f1ba7b2839e221c3e14748
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Jun 28 12:59:19 2021 +0100

    libstdc++: Allow unique_ptr<Incomplete[]>::operator[] [PR 101236]

    PR libstdc++/101236 shows that LLVM depends on being able to use
    unique_ptr<T[]>::operator[] when T is incomplete. This is undefined, but
    previously worked with libstdc++. When I added the conditional noexcept
    to that operator we started to diagnose the incomplete type.

    This change restores support for that case, by making the noexcept
    condition check that the type is complete before checking whether
    indexing on the pointer can throw.  A workaround for PR c++/101239 is
    needed to avoid a bogus error where G++ fails to do SFINAE on the
    ill-formed p[n] expression and gets an ICE. Instead of checking that the
    p[n] expression is valid in the trailing-return-type, we only check that
    the element_type is complete.

    libstdc++-v3/ChangeLog:

            PR libstdc++/101236
            * include/bits/unique_ptr.h (unique_ptr<T[], D>::operator[]):
            Fail gracefully if element_type is incomplete.
            * testsuite/20_util/unique_ptr/cons/incomplete.cc: Clarify that
            the standard doesn't require this test to work for array types.
            * testsuite/20_util/unique_ptr/lwg2762.cc: Check that incomplete
            types can be used with array specialization.
            * testsuite/20_util/unique_ptr/101236.cc: New test.

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

* [Bug libstdc++/101236] [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ since r12-1778-g17bc3848e065c0980523e1a1592f2f03b24b4f1c
  2021-06-28  8:17 [Bug libstdc++/101236] New: [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ marxin at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2021-06-28 13:23 ` cvs-commit at gcc dot gnu.org
@ 2021-06-28 13:27 ` redi at gcc dot gnu.org
  2021-07-02 11:15 ` cvs-commit at gcc dot gnu.org
  2021-12-27 15:02 ` ppalka at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2021-06-28 13:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
           See Also|                            |https://bugs.llvm.org/show_
                   |                            |bug.cgi?id=50921
             Status|ASSIGNED                    |RESOLVED

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed to accept the bad code.

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

* [Bug libstdc++/101236] [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ since r12-1778-g17bc3848e065c0980523e1a1592f2f03b24b4f1c
  2021-06-28  8:17 [Bug libstdc++/101236] New: [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ marxin at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2021-06-28 13:27 ` redi at gcc dot gnu.org
@ 2021-07-02 11:15 ` cvs-commit at gcc dot gnu.org
  2021-12-27 15:02 ` ppalka at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-02 11:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

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

commit r12-1976-gbc8f0ed7042280282035168428f6afc839997cf0
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Jul 2 08:46:18 2021 +0100

    libstdc++: Revert changes to std::unique_ptr<T[]>::operator[] [PR 101271]

    This reverts the changes in r12-1778 which added a noexcept-specifier to
    std::unique_ptr<T[]>::operator[], and the changes in r12-1844 which
    tried to make it work with incomplete types (for PR 101236).

    The noexcept-specifier is not required by the standard, and is causing
    regressions, so just remove it.

    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

    libstdc++-v3/ChangeLog:

            PR libstdc++/101271
            * include/bits/unique_ptr.h (unique_ptr<T[],D>::operator[]):
            Remove noexcept-specifier.
            (unique_ptr<T[],D>::_S_nothrow_deref): Remove.
            * testsuite/20_util/unique_ptr/lwg2762.cc: Remove checks for
            operator[].

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

* [Bug libstdc++/101236] [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ since r12-1778-g17bc3848e065c0980523e1a1592f2f03b24b4f1c
  2021-06-28  8:17 [Bug libstdc++/101236] New: [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ marxin at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2021-07-02 11:15 ` cvs-commit at gcc dot gnu.org
@ 2021-12-27 15:02 ` ppalka at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-12-27 15:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101236
Bug 101236 depends on bug 101239, which changed state.

Bug 101239 Summary: "Internal compiler error: Error reporting routines re-entered." in size_in_bytes_loc
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101239

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

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

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

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-28  8:17 [Bug libstdc++/101236] New: [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ marxin at gcc dot gnu.org
2021-06-28  8:18 ` [Bug libstdc++/101236] [12 Regression] bits/unique_ptr.h:658:48: error: invalid use of incomplete type ‘class llvm::APFloat’ since r12-1778-g17bc3848e065c0980523e1a1592f2f03b24b4f1c marxin at gcc dot gnu.org
2021-06-28  9:13 ` rguenth at gcc dot gnu.org
2021-06-28  9:41 ` redi at gcc dot gnu.org
2021-06-28 10:18 ` marxin at gcc dot gnu.org
2021-06-28 10:25 ` redi at gcc dot gnu.org
2021-06-28 11:51 ` redi at gcc dot gnu.org
2021-06-28 13:23 ` cvs-commit at gcc dot gnu.org
2021-06-28 13:27 ` redi at gcc dot gnu.org
2021-07-02 11:15 ` cvs-commit at gcc dot gnu.org
2021-12-27 15:02 ` 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).