public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/113522] New: std::swap cannot be called with explicit template argument std::array<int,3>
@ 2024-01-20  9:22 fchelnokov at gmail dot com
  2024-01-20  9:27 ` [Bug libstdc++/113522] " redi at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: fchelnokov at gmail dot com @ 2024-01-20  9:22 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113522
           Summary: std::swap cannot be called with explicit template
                    argument std::array<int,3>
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

#include <array>
#include <utility>

int main() {
    std::array<int,3> a, b;
    std::swap< std::array<int,3> >( a, b ); 
}

is accepted by MSVC and Clang with libc++, but GCC with libstdc++ complains:

error: no matching function for call to 'swap<std::array<int, 3>
>(std::array<int, 3>&, std::array<int, 3>&)'

Online demo: https://godbolt.org/z/8xnd5PsfE

Related discussion: https://stackoverflow.com/q/77844837/7325599

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

* [Bug libstdc++/113522] std::swap cannot be called with explicit template argument std::array<int,3>
  2024-01-20  9:22 [Bug libstdc++/113522] New: std::swap cannot be called with explicit template argument std::array<int,3> fchelnokov at gmail dot com
@ 2024-01-20  9:27 ` redi at gcc dot gnu.org
  2024-01-20  9:34 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2024-01-20  9:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is silly code and there is no reason to support it.

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

* [Bug libstdc++/113522] std::swap cannot be called with explicit template argument std::array<int,3>
  2024-01-20  9:22 [Bug libstdc++/113522] New: std::swap cannot be called with explicit template argument std::array<int,3> fchelnokov at gmail dot com
  2024-01-20  9:27 ` [Bug libstdc++/113522] " redi at gcc dot gnu.org
@ 2024-01-20  9:34 ` pinskia at gcc dot gnu.org
  2024-01-20  9:35 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-20  9:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It was added in r7-5068-ga2863bde755d39 for LWG 2766 .

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

* [Bug libstdc++/113522] std::swap cannot be called with explicit template argument std::array<int,3>
  2024-01-20  9:22 [Bug libstdc++/113522] New: std::swap cannot be called with explicit template argument std::array<int,3> fchelnokov at gmail dot com
  2024-01-20  9:27 ` [Bug libstdc++/113522] " redi at gcc dot gnu.org
  2024-01-20  9:34 ` pinskia at gcc dot gnu.org
@ 2024-01-20  9:35 ` pinskia at gcc dot gnu.org
  2024-01-25  8:37 ` de34 at live dot cn
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-20  9:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
https://timsong-cpp.github.io/lwg-issues/2766

The LWG issue is still open ...

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

* [Bug libstdc++/113522] std::swap cannot be called with explicit template argument std::array<int,3>
  2024-01-20  9:22 [Bug libstdc++/113522] New: std::swap cannot be called with explicit template argument std::array<int,3> fchelnokov at gmail dot com
                   ` (2 preceding siblings ...)
  2024-01-20  9:35 ` pinskia at gcc dot gnu.org
@ 2024-01-25  8:37 ` de34 at live dot cn
  2024-01-25  9:38 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: de34 at live dot cn @ 2024-01-25  8:37 UTC (permalink / raw)
  To: gcc-bugs

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

Jiang An <de34 at live dot cn> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |de34 at live dot cn

--- Comment #4 from Jiang An <de34 at live dot cn> ---
std::swap is not supposed to be called with explicitly specified template
arguments.

If the template arguments are not explicitly specified for std::swap, the
correct overloads will be selected if you include currect headers, even when
not all standard headers that declare std::swap overloads are included (the
shape of overload set is unspecified in such cases).

However, if you explicitly specify template arguments, there may be unintended
(likely incorrect) overloads whose template arguments are no longer
underdeduced to be selected. And then undesired implicit conversion can be
trigged during overload resolution, which can make your program ill-formed.

(In reply to Jonathan Wakely from comment #1)
> This is silly code and there is no reason to support it.

Hmm... currently it's specified in [algorithms.requirements] that
> The well-formedness and behavior of a call to an algorithm with an explicitly-specified template argument list is unspecified, except where explicitly stated otherwise.

(Added by P0896R4 and amended by LWG3419.)

Should open an LWG issue to specify similar things for std::swap?

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

* [Bug libstdc++/113522] std::swap cannot be called with explicit template argument std::array<int,3>
  2024-01-20  9:22 [Bug libstdc++/113522] New: std::swap cannot be called with explicit template argument std::array<int,3> fchelnokov at gmail dot com
                   ` (3 preceding siblings ...)
  2024-01-25  8:37 ` de34 at live dot cn
@ 2024-01-25  9:38 ` redi at gcc dot gnu.org
  2024-01-25  9:44 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2024-01-25  9:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jiang An from comment #4)
> Hmm... currently it's specified in [algorithms.requirements] that
> > The well-formedness and behavior of a call to an algorithm with an explicitly-specified template argument list is unspecified, except where explicitly stated otherwise.
> 
> (Added by P0896R4 and amended by LWG3419.)
> 
> Should open an LWG issue to specify similar things for std::swap?

Yes please. I thought we already had it, but when I went looking I only found
that text in [algorithm.requirements].

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

* [Bug libstdc++/113522] std::swap cannot be called with explicit template argument std::array<int,3>
  2024-01-20  9:22 [Bug libstdc++/113522] New: std::swap cannot be called with explicit template argument std::array<int,3> fchelnokov at gmail dot com
                   ` (4 preceding siblings ...)
  2024-01-25  9:38 ` redi at gcc dot gnu.org
@ 2024-01-25  9:44 ` redi at gcc dot gnu.org
  2024-01-25  9:48 ` pinskia at gcc dot gnu.org
  2024-01-30 12:01 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2024-01-25  9:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I'd also like to ban it for std::make_pair, but that would break loads of very
silly code that does std::make_pair<T,U>(a,b) (c.f. Bug 92300 comment 3).

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

* [Bug libstdc++/113522] std::swap cannot be called with explicit template argument std::array<int,3>
  2024-01-20  9:22 [Bug libstdc++/113522] New: std::swap cannot be called with explicit template argument std::array<int,3> fchelnokov at gmail dot com
                   ` (5 preceding siblings ...)
  2024-01-25  9:44 ` redi at gcc dot gnu.org
@ 2024-01-25  9:48 ` pinskia at gcc dot gnu.org
  2024-01-30 12:01 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-25  9:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #6)
> I'd also like to ban it for std::make_pair, but that would break loads of
> very silly code that does std::make_pair<T,U>(a,b) (c.f. Bug 92300 comment
> 3).

Note GCC/go has that code too:

go/gofrontend/expressions.cc:    return std::make_pair<Call_expression*,
Temporary_statement*>(NULL, NULL);
go/gofrontend/expressions.cc:    return std::make_pair<Call_expression*,
Temporary_statement*>(NULL, NULL);
go/gofrontend/expressions.cc:  return std::make_pair<Call_expression*,
Temporary_statement*>(NULL, NULL);
go/gofrontend/import.cc:  this->type_offsets_.resize(maxp1,
std::make_pair<size_t, size_t>(0, 0));

:)

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

* [Bug libstdc++/113522] std::swap cannot be called with explicit template argument std::array<int,3>
  2024-01-20  9:22 [Bug libstdc++/113522] New: std::swap cannot be called with explicit template argument std::array<int,3> fchelnokov at gmail dot com
                   ` (6 preceding siblings ...)
  2024-01-25  9:48 ` pinskia at gcc dot gnu.org
@ 2024-01-30 12:01 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2024-01-30 12:01 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-01-30
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |SUSPENDED

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
https://cplusplus.github.io/LWG/issue4047

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

end of thread, other threads:[~2024-01-30 12:01 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-20  9:22 [Bug libstdc++/113522] New: std::swap cannot be called with explicit template argument std::array<int,3> fchelnokov at gmail dot com
2024-01-20  9:27 ` [Bug libstdc++/113522] " redi at gcc dot gnu.org
2024-01-20  9:34 ` pinskia at gcc dot gnu.org
2024-01-20  9:35 ` pinskia at gcc dot gnu.org
2024-01-25  8:37 ` de34 at live dot cn
2024-01-25  9:38 ` redi at gcc dot gnu.org
2024-01-25  9:44 ` redi at gcc dot gnu.org
2024-01-25  9:48 ` pinskia at gcc dot gnu.org
2024-01-30 12:01 ` redi 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).