public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/101427] New: std::get should refuse to compile if type is provided and it is duplicated in std::tuple
@ 2021-07-12 8:22 federico.reghenzani at polimi dot it
2021-07-12 10:37 ` [Bug libstdc++/101427] [11/12 Regression] " redi at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: federico.reghenzani at polimi dot it @ 2021-07-12 8:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101427
Bug ID: 101427
Summary: std::get should refuse to compile if type is provided
and it is duplicated in std::tuple
Product: gcc
Version: 11.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: federico.reghenzani at polimi dot it
Target Milestone: ---
The following code should not compile:
----------------------------------------------------------
#include <tuple>
int main() {
std::tuple<int, int> my_record;
std::get<int>(my_record) = 10;
return 0;
}
----------------------------------------------------------
Because `std::get<int>` accesses the `int` element which is duplicated. This is
not allowed by the standard: http://eel.is/c++draft/tuple#elem-5
Instead, it compiles and modifies only the first element in GCC 11.1.0 (while
it doesn't compile in 10.x.x). A full example here:
https://godbolt.org/z/YzorM9P8K
Expected behavior
-----------------
It should not compile and generate a compilation error.
Actual behavior
---------------
It compiles and (seems to) modify the first item of the tuple.
GCC Information
---------------
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id
--enable-lto --enable-multilib --enable-plugin --enable-shared
--enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-libunwind-exceptions --disable-werror
gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.0 (GCC)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/101427] [11/12 Regression] std::get should refuse to compile if type is provided and it is duplicated in std::tuple
2021-07-12 8:22 [Bug libstdc++/101427] New: std::get should refuse to compile if type is provided and it is duplicated in std::tuple federico.reghenzani at polimi dot it
@ 2021-07-12 10:37 ` redi at gcc dot gnu.org
2021-07-15 13:14 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-07-12 10:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101427
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |10.3.0
Summary|std::get should refuse to |[11/12 Regression] std::get
|compile if type is provided |should refuse to compile if
|and it is duplicated in |type is provided and it is
|std::tuple |duplicated in std::tuple
Ever confirmed|0 |1
Last reconfirmed| |2021-07-12
Target Milestone|--- |11.2
Known to fail| |11.1.0, 12.0
Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/101427] [11/12 Regression] std::get should refuse to compile if type is provided and it is duplicated in std::tuple
2021-07-12 8:22 [Bug libstdc++/101427] New: std::get should refuse to compile if type is provided and it is duplicated in std::tuple federico.reghenzani at polimi dot it
2021-07-12 10:37 ` [Bug libstdc++/101427] [11/12 Regression] " redi at gcc dot gnu.org
@ 2021-07-15 13:14 ` redi at gcc dot gnu.org
2021-07-15 15:26 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-07-15 13:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101427
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The std::get<T> code stopped working as a result of r11-4693 which implemented
a core language change:
c++: DR2303, ambiguous base deduction [PR97453]
When there are two possible matches and one is a base of the other, choose
the derived class rather than fail.
We should have had a libstdc++ test verifying the expected error, so that we'd
have noticed the library regression.
I will push the fix soon.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/101427] [11/12 Regression] std::get should refuse to compile if type is provided and it is duplicated in std::tuple
2021-07-12 8:22 [Bug libstdc++/101427] New: std::get should refuse to compile if type is provided and it is duplicated in std::tuple federico.reghenzani at polimi dot it
2021-07-12 10:37 ` [Bug libstdc++/101427] [11/12 Regression] " redi at gcc dot gnu.org
2021-07-15 13:14 ` redi at gcc dot gnu.org
@ 2021-07-15 15:26 ` cvs-commit at gcc dot gnu.org
2021-07-15 15:32 ` [Bug libstdc++/101427] [11 " redi at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-15 15:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101427
--- Comment #2 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:17855eed7fc76b2cee7fbbc26f84d3c8b99be13c
commit r12-2327-g17855eed7fc76b2cee7fbbc26f84d3c8b99be13c
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Jul 14 20:14:14 2021 +0100
libstdc++: Fix std::get<T> for std::tuple [PR101427]
The std::get<T> functions relied on deduction failing if more than one
base class existed for the type T. However the implementation of Core
DR 2303 (in r11-4693) made deduction succeed (and select the
more-derived base class).
This rewrites the implementation of std::get<T> to explicitly check for
more than one occurrence of T in the tuple elements, making it
ill-formed again. Additionally, the large wall of overload resolution
errors described in PR c++/101460 is avoided by making std::get<T> use
__get_helper<I> directly instead of calling std::get<I>, and by adding a
deleted overload of __get_helper<N> for out-of-range N.
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:
PR libstdc++/101427
* include/std/tuple (tuple_element): Improve static_assert text.
(__get_helper): Add deleted overload.
(get<i>(tuple<T...>&&), get<i>(const tuple<T...>&&)): Use
__get_helper directly.
(__get_helper2): Remove.
(__find_uniq_type_in_pack): New constexpr helper function.
(get<T>): Use __find_uniq_type_in_pack and __get_helper instead
of __get_helper2.
* testsuite/20_util/tuple/element_access/get_neg.cc: Adjust
expected errors.
* testsuite/20_util/tuple/element_access/101427.cc: New test.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/101427] [11 Regression] std::get should refuse to compile if type is provided and it is duplicated in std::tuple
2021-07-12 8:22 [Bug libstdc++/101427] New: std::get should refuse to compile if type is provided and it is duplicated in std::tuple federico.reghenzani at polimi dot it
` (2 preceding siblings ...)
2021-07-15 15:26 ` cvs-commit at gcc dot gnu.org
@ 2021-07-15 15:32 ` redi at gcc dot gnu.org
2021-07-19 12:38 ` cvs-commit at gcc dot gnu.org
2021-07-19 13:09 ` redi at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-07-15 15:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101427
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[11/12 Regression] std::get |[11 Regression] std::get
|should refuse to compile if |should refuse to compile if
|type is provided and it is |type is provided and it is
|duplicated in std::tuple |duplicated in std::tuple
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk for now.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/101427] [11 Regression] std::get should refuse to compile if type is provided and it is duplicated in std::tuple
2021-07-12 8:22 [Bug libstdc++/101427] New: std::get should refuse to compile if type is provided and it is duplicated in std::tuple federico.reghenzani at polimi dot it
` (3 preceding siblings ...)
2021-07-15 15:32 ` [Bug libstdc++/101427] [11 " redi at gcc dot gnu.org
@ 2021-07-19 12:38 ` cvs-commit at gcc dot gnu.org
2021-07-19 13:09 ` redi at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-19 12:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101427
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:
https://gcc.gnu.org/g:6dc150d9a036cbbed3c4dac6df1ce895b899d423
commit r11-8777-g6dc150d9a036cbbed3c4dac6df1ce895b899d423
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Jul 14 20:14:14 2021 +0100
libstdc++: Fix std::get<T> for std::tuple [PR101427]
The std::get<T> functions relied on deduction failing if more than one
base class existed for the type T. However the implementation of Core
DR 2303 (in r11-4693) made deduction succeed (and select the
more-derived base class).
This rewrites the implementation of std::get<T> to explicitly check for
more than one occurrence of T in the tuple elements, making it
ill-formed again. Additionally, the large wall of overload resolution
errors described in PR c++/101460 is avoided by making std::get<T> use
__get_helper<I> directly instead of calling std::get<I>, and by adding a
deleted overload of __get_helper<N> for out-of-range N.
Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:
PR libstdc++/101427
* include/std/tuple (tuple_element): Improve static_assert text.
(__get_helper): Add deleted overload.
(get<i>(tuple<T...>&&), get<i>(const tuple<T...>&&)): Use
__get_helper directly.
(__get_helper2): Remove.
(__find_uniq_type_in_pack): New constexpr helper function.
(get<T>): Use __find_uniq_type_in_pack and __get_helper instead
of __get_helper2.
* testsuite/20_util/tuple/element_access/get_neg.cc: Adjust
expected errors.
* testsuite/20_util/tuple/element_access/101427.cc: New test.
(cherry picked from commit 17855eed7fc76b2cee7fbbc26f84d3c8b99be13c)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug libstdc++/101427] [11 Regression] std::get should refuse to compile if type is provided and it is duplicated in std::tuple
2021-07-12 8:22 [Bug libstdc++/101427] New: std::get should refuse to compile if type is provided and it is duplicated in std::tuple federico.reghenzani at polimi dot it
` (4 preceding siblings ...)
2021-07-19 12:38 ` cvs-commit at gcc dot gnu.org
@ 2021-07-19 13:09 ` redi at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-07-19 13:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101427
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 11.2, thanks for the report.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-07-19 13:09 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-12 8:22 [Bug libstdc++/101427] New: std::get should refuse to compile if type is provided and it is duplicated in std::tuple federico.reghenzani at polimi dot it
2021-07-12 10:37 ` [Bug libstdc++/101427] [11/12 Regression] " redi at gcc dot gnu.org
2021-07-15 13:14 ` redi at gcc dot gnu.org
2021-07-15 15:26 ` cvs-commit at gcc dot gnu.org
2021-07-15 15:32 ` [Bug libstdc++/101427] [11 " redi at gcc dot gnu.org
2021-07-19 12:38 ` cvs-commit at gcc dot gnu.org
2021-07-19 13:09 ` 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).