[Bug libstdc++/48101] obscure error message with std::set

2022-03-10 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48101

--- Comment #13 from Jonathan Wakely  ---
Nice!

[Bug libstdc++/48101] obscure error message with std::set

2022-03-10 Thread ldionne.2 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48101

Louis Dionne  changed:

   What|Removed |Added

 CC||ldionne.2 at gmail dot com

--- Comment #12 from Louis Dionne  ---
FWIW, we now consider it a bug in libc++ that we accept std::allocator, and we're trying to remove that "extension".

[Bug libstdc++/48101] obscure error message with std::set

2019-05-07 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48101

--- Comment #11 from Jonathan Wakely  ---
Author: redi
Date: Tue May  7 15:46:05 2019
New Revision: 270960

URL: https://gcc.gnu.org/viewcvs?rev=270960&root=gcc&view=rev
Log:
PR libstdc++/85965 delay static assertions until types are complete

The static assertions added for PR libstdc++/48101 were at class scope
and so were evaluated too eagerly, when it might not be possible to
determine whether the function objects are invocable with the key types.
The problematic cases are where the key type is not known to be
convertible to the argument type(s) of the function object until later,
after a type has been completed. Specifically, if the key type is a
pointer to a derived class and the function object's argument type is a
pointer to a base class, then the derived-to-base conversion is only
valid once the derived type is complete.

By moving the static assertions to the destructor they will only be
evaluated when the destructor is instantiated, at which point whether
the key type can be passed to the function object should be knowable.
The ideal place to do the checks would be only when the function objects
are actually invoked, but that would mean adding the checks in numerous
places, so the destructor is used instead.

The tests need to be adjusted because the "required from here" line is
now the location of the destructor, not the point of instantiation in
the test file. For the map and multimap tests which check two
specializations, the dg-error matching the assertion text matches both
cases. Also check the diagnostic output for the template arguments, to
ensure both specializations trigger the assertion.

Backport from mainline
2019-03-26  Jonathan Wakely  

PR libstdc++/85965
* include/bits/hashtable.h (_Hashtable): Move static assertions to
destructor so they are not evaluated until the _Key type is complete.
* include/bits/stl_tree.h (_Rb_tree): Likewise.
* testsuite/23_containers/set/85965.cc: New test.
* testsuite/23_containers/unordered_set/85965.cc: New test.
* testsuite/23_containers/map/48101_neg.cc: Replace "here" errors
with regexp matching the corresponding _Rb_tree specialization.
* testsuite/23_containers/multimap/48101_neg.cc: Likewise.
* testsuite/23_containers/multiset/48101_neg.cc: Remove "here" error.
* testsuite/23_containers/set/48101_neg.cc: Likewise.
* testsuite/23_containers/unordered_map/48101_neg.cc: Likewise.
* testsuite/23_containers/unordered_multimap/48101_neg.cc: Likewise.
* testsuite/23_containers/unordered_multiset/48101_neg.cc: Likewise.
* testsuite/23_containers/unordered_set/48101_neg.cc: Likewise.

Added:
branches/gcc-8-branch/libstdc++-v3/testsuite/23_containers/set/85965.cc
  - copied, changed from r270959,
branches/gcc-8-branch/libstdc++-v3/testsuite/23_containers/map/48101_neg.cc
   
branches/gcc-8-branch/libstdc++-v3/testsuite/23_containers/unordered_set/85965.cc
  - copied, changed from r270959,
branches/gcc-8-branch/libstdc++-v3/testsuite/23_containers/map/48101_neg.cc
Modified:
branches/gcc-8-branch/libstdc++-v3/ChangeLog
branches/gcc-8-branch/libstdc++-v3/include/bits/hashtable.h
branches/gcc-8-branch/libstdc++-v3/include/bits/stl_tree.h
branches/gcc-8-branch/libstdc++-v3/testsuite/23_containers/map/48101_neg.cc
   
branches/gcc-8-branch/libstdc++-v3/testsuite/23_containers/multimap/48101_neg.cc
   
branches/gcc-8-branch/libstdc++-v3/testsuite/23_containers/multiset/48101_neg.cc
branches/gcc-8-branch/libstdc++-v3/testsuite/23_containers/set/48101_neg.cc
   
branches/gcc-8-branch/libstdc++-v3/testsuite/23_containers/unordered_map/48101_neg.cc
   
branches/gcc-8-branch/libstdc++-v3/testsuite/23_containers/unordered_multimap/48101_neg.cc
   
branches/gcc-8-branch/libstdc++-v3/testsuite/23_containers/unordered_multiset/48101_neg.cc
   
branches/gcc-8-branch/libstdc++-v3/testsuite/23_containers/unordered_set/48101_neg.cc

[Bug libstdc++/48101] obscure error message with std::set

2019-03-26 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48101

--- Comment #10 from Jonathan Wakely  ---
Author: redi
Date: Tue Mar 26 15:28:48 2019
New Revision: 269949

URL: https://gcc.gnu.org/viewcvs?rev=269949&root=gcc&view=rev
Log:
PR libstdc++/85965 delay static assertions until types are complete

The static assertions added for PR libstdc++/48101 were at class scope
and so were evaluated too eagerly, when it might not be possible to
determine whether the function objects are invocable with the key types.
The problematic cases are where the key type is not known to be
convertible to the argument type(s) of the function object until later,
after a type has been completed. Specifically, if the key type is a
pointer to a derived class and the function object's argument type is a
pointer to a base class, then the derived-to-base conversion is only
valid once the derived type is complete.

By moving the static assertions to the destructor they will only be
evaluated when the destructor is instantiated, at which point whether
the key type can be passed to the function object should be knowable.
The ideal place to do the checks would be only when the function objects
are actually invoked, but that would mean adding the checks in numerous
places, so the destructor is used instead.

The tests need to be adjusted because the "required from here" line is
now the location of the destructor, not the point of instantiation in
the test file. For the map and multimap tests which check two
specializations, the dg-error matching the assertion text matches both
cases. Also check the diagnostic output for the template arguments, to
ensure both specializations trigger the assertion.

PR libstdc++/85965
* include/bits/hashtable.h (_Hashtable): Move static assertions to
destructor so they are not evaluated until the _Key type is complete.
* include/bits/stl_tree.h (_Rb_tree): Likewise.
* testsuite/23_containers/set/85965.cc: New test.
* testsuite/23_containers/unordered_set/85965.cc: New test.
* testsuite/23_containers/map/48101_neg.cc: Replace "here" errors
with regexp matching the corresponding _Rb_tree specialization.
* testsuite/23_containers/multimap/48101_neg.cc: Likewise.
* testsuite/23_containers/multiset/48101_neg.cc: Remove "here" error.
* testsuite/23_containers/set/48101_neg.cc: Likewise.
* testsuite/23_containers/unordered_map/48101_neg.cc: Likewise.
* testsuite/23_containers/unordered_multimap/48101_neg.cc: Likewise.
* testsuite/23_containers/unordered_multiset/48101_neg.cc: Likewise.
* testsuite/23_containers/unordered_set/48101_neg.cc: Likewise.

Added:
trunk/libstdc++-v3/testsuite/23_containers/set/85965.cc
  - copied, changed from r269947,
trunk/libstdc++-v3/testsuite/23_containers/map/48101_neg.cc
trunk/libstdc++-v3/testsuite/23_containers/unordered_set/85965.cc
  - copied, changed from r269947,
trunk/libstdc++-v3/testsuite/23_containers/map/48101_neg.cc
Modified:
trunk/libstdc++-v3/ChangeLog
trunk/libstdc++-v3/include/bits/hashtable.h
trunk/libstdc++-v3/include/bits/stl_tree.h
trunk/libstdc++-v3/testsuite/23_containers/map/48101_neg.cc
trunk/libstdc++-v3/testsuite/23_containers/multimap/48101_neg.cc
trunk/libstdc++-v3/testsuite/23_containers/multiset/48101_neg.cc
trunk/libstdc++-v3/testsuite/23_containers/set/48101_neg.cc
trunk/libstdc++-v3/testsuite/23_containers/unordered_map/48101_neg.cc
trunk/libstdc++-v3/testsuite/23_containers/unordered_multimap/48101_neg.cc
trunk/libstdc++-v3/testsuite/23_containers/unordered_multiset/48101_neg.cc
trunk/libstdc++-v3/testsuite/23_containers/unordered_set/48101_neg.cc

[Bug libstdc++/48101] obscure error message with std::set

2017-11-21 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48101

Jonathan Wakely  changed:

   What|Removed |Added

   Keywords||diagnostic
 Status|NEW |RESOLVED
 Resolution|--- |FIXED
   Target Milestone|--- |8.0

--- Comment #9 from Jonathan Wakely  ---
Gaby's original testcase now prints simply:

In file included from /home/jwakely/gcc/8/include/c++/8.0.0/set:61:0,
 from const.cc:1:
/home/jwakely/gcc/8/include/c++/8.0.0/bits/stl_set.h: In instantiation of
‘class std::set’:
const.cc:4:23:   required from here
/home/jwakely/gcc/8/include/c++/8.0.0/bits/stl_set.h:108:7: error: static
assertion failed: std::set must have a non-const, non-volatile value_type
   static_assert(is_same::type, _Key>::value,
   ^

[Bug libstdc++/48101] obscure error message with std::set

2017-11-21 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48101

--- Comment #8 from Jonathan Wakely  ---
Author: redi
Date: Tue Nov 21 20:47:09 2017
New Revision: 255035

URL: https://gcc.gnu.org/viewcvs?rev=255035&root=gcc&view=rev
Log:
PR libstdc++/48101 improve errors for invalid container specializations

PR libstdc++/48101
* include/bits/allocator.h (allocator)
(allocator, allocator): Add partial
specializations.
* include/bits/forward_list.h (forward_list): Add static assertions.
* include/bits/hashtable.h (__cache_default): Use
__is_nothrow_invocable instead of __is_noexcept_hash.
(_Hashtable): Add static assertions.
* include/bits/hashtable_policy.h (__is_noexcept_hash): Remove.
* include/bits/stl_deque.h (deque): Add static assertions.
* include/bits/stl_function.h (_Identity): Add partial
specialization.
* include/bits/stl_list.h (list): Add static assertions.
* include/bits/stl_map.h (map): Likewise.
* include/bits/stl_multimap.h (multimap): Likewise.
* include/bits/stl_multiset.h (multiset): Likewise.
* include/bits/stl_set.h (set): Likewise.
* include/bits/stl_tree.h (_Rb_tree): Likewise.
* include/bits/stl_vector.h (vector): Likewise.
* include/bits/unordered_map.h (unordered_map, unordered_multimap):
Use typename instead of class in template-parameter-list and remove
spaces.
* include/bits/unordered_set.h (unordered_set, unordered_multiset):
Likewise.
* testsuite/23_containers/deque/48101-2_neg.cc: New test.
* testsuite/23_containers/deque/48101_neg.cc: New test.
* testsuite/23_containers/forward_list/48101-2_neg.cc: New test.
* testsuite/23_containers/forward_list/48101_neg.cc: New test.
* testsuite/23_containers/list/48101-2_neg.cc: New test.
* testsuite/23_containers/list/48101_neg.cc: New test.
* testsuite/23_containers/map/48101-2_neg.cc: New test.
* testsuite/23_containers/map/48101_neg.cc: New test.
* testsuite/23_containers/map/operations/31440.cc: Fix comparison
object to have const-qualified call operator.
* testsuite/23_containers/multimap/48101-2_neg.cc: New test.
* testsuite/23_containers/multimap/48101_neg.cc: New test.
* testsuite/23_containers/multiset/48101-2_neg.cc: New test.
* testsuite/23_containers/multiset/48101_neg.cc: New test.
* testsuite/23_containers/set/48101-2_neg.cc: New test.
* testsuite/23_containers/set/48101_neg.cc: New test.
* testsuite/23_containers/unordered_map/48101-2_neg.cc: New test.
* testsuite/23_containers/unordered_map/48101_neg.cc: New test.
* testsuite/23_containers/unordered_multimap/48101-2_neg.cc: New test.
* testsuite/23_containers/unordered_multimap/48101_neg.cc: New test.
* testsuite/23_containers/unordered_multiset/48101-2_neg.cc: New test.
* testsuite/23_containers/unordered_multiset/48101_neg.cc: New test.
* testsuite/23_containers/unordered_set/48101-2_neg.cc: New test.
* testsuite/23_containers/unordered_set/48101_neg.cc: New test.
* testsuite/23_containers/unordered_set/instantiation_neg.cc: Adjust
dg-error line number.
* testsuite/23_containers/vector/48101-2_neg.cc: New test.
* testsuite/23_containers/vector/48101_neg.cc: New test.

Added:
trunk/libstdc++-v3/testsuite/23_containers/deque/48101-2_neg.cc
  - copied, changed from r255023,
trunk/libstdc++-v3/testsuite/23_containers/map/operations/31440.cc
trunk/libstdc++-v3/testsuite/23_containers/deque/48101_neg.cc
  - copied, changed from r255023,
trunk/libstdc++-v3/testsuite/23_containers/unordered_set/instantiation_neg.cc
trunk/libstdc++-v3/testsuite/23_containers/forward_list/48101-2_neg.cc
  - copied, changed from r255023,
trunk/libstdc++-v3/testsuite/23_containers/map/operations/31440.cc
trunk/libstdc++-v3/testsuite/23_containers/forward_list/48101_neg.cc
  - copied, changed from r255023,
trunk/libstdc++-v3/testsuite/23_containers/unordered_set/instantiation_neg.cc
trunk/libstdc++-v3/testsuite/23_containers/list/48101-2_neg.cc
  - copied, changed from r255023,
trunk/libstdc++-v3/testsuite/23_containers/map/operations/31440.cc
trunk/libstdc++-v3/testsuite/23_containers/list/48101_neg.cc
  - copied, changed from r255023,
trunk/libstdc++-v3/testsuite/23_containers/unordered_set/instantiation_neg.cc
trunk/libstdc++-v3/testsuite/23_containers/map/48101-2_neg.cc
  - copied, changed from r255023,
trunk/libstdc++-v3/testsuite/23_containers/map/operations/31440.cc
trunk/libstdc++-v3/testsuite/23_containers/map/48101_neg.cc
  - copied, changed from r255023,
trunk/libstdc++-v3/testsuite/23_containers/map/operations/31440.cc
trunk/libstdc++-v3/testsuite/23_containers/multimap/48101-2_neg.cc
  - copied, changed from r255023,

[Bug libstdc++/48101] obscure error message with std::set

2017-11-20 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48101

--- Comment #7 from Jonathan Wakely  ---
Even if we allowed allocator you still can't use std::set
because the container code assumes a non-const value type in several places.

[Bug libstdc++/48101] obscure error message with std::set

2017-11-20 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48101

--- Comment #6 from Jonathan Wakely  ---
You can't allocate const memory, but in essence yes, that's the reason. The
standard says that an allocator's value type must be a non-const, non-volatile
object type, so std::allocator is undefined behaviour.

[Bug libstdc++/48101] obscure error message with std::set

2017-11-20 Thread gccbugs at jbapple dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48101

--- Comment #5 from gccbugs at jbapple dot com ---
What is the virtue of making std::allocator an error? Is this
required by the standard? Is it because calls to construct are writing to const
memory?

[Bug libstdc++/48101] obscure error message with std::set

2017-11-20 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48101

--- Comment #4 from Jonathan Wakely  ---
Which causes the code to be accepted. I'd rather do:

template class allocator;  // undefined

so there's an error.

[Bug libstdc++/48101] obscure error message with std::set

2017-11-18 Thread gccbugs at jbapple dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48101

gccbugs at jbapple dot com changed:

   What|Removed |Added

 CC||gccbugs at jbapple dot com

--- Comment #3 from gccbugs at jbapple dot com ---
libc++ handles this with a partial template specialization like

template
class allocator {
  ...

See
https://github.com/llvm-mirror/libcxx/blob/b4a34c08ac01146141a9940bcfb0a680d24dc092/include/memory#L1817

[Bug libstdc++/48101] obscure error message with std::set

2014-09-19 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48101

Jonathan Wakely  changed:

   What|Removed |Added

 CC||corey at octayn dot net

--- Comment #2 from Jonathan Wakely  ---
*** Bug 55963 has been marked as a duplicate of this bug. ***


[Bug libstdc++/48101] obscure error message with std::set

2014-09-19 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48101

Jonathan Wakely  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2014-09-19
 Ever confirmed|0   |1
   Severity|normal  |enhancement


[Bug libstdc++/48101] obscure error message with std::set

2011-03-13 Thread redi at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48101

--- Comment #1 from Jonathan Wakely  2011-03-13 
12:24:13 UTC ---
Do you have a suggestion for a better error?  We could use a static_assert in
std::allocator to reject const T

As far as I can see, the reason the code is invalid is exactly the reason
given: std::allocator can't be instantiated with const T.   I don't think it's
invalid to default construct a set::set with a const value_type, as long as
don't use std::allocator.