[Bug libstdc++/89942] New: std::function __is_location_invariant breaks ABI compatibility

2019-04-03 Thread kan.liu.229 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89942

Bug ID: 89942
   Summary: std::function __is_location_invariant breaks ABI
compatibility
   Product: gcc
   Version: 5.4.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: kan.liu.229 at gmail dot com
  Target Milestone: ---

Created attachment 46079
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46079=edit
possible fix

in gcc 5.4.0

 template
struct __is_location_invariant
: is_trivially_copyable<_Tp>::type
{ };

__is_location_invariant is evaluated to be true for the closure type (lambda
expression)

in gcc 4.9.2

  template
struct __is_location_invariant
: integral_constant::value
   || is_member_pointer<_Tp>::value)>
{ };

which is evaluated to be false.

This may break ABI compatibility when pass function object between libs
compiled by 4.9.2 / 5.4.0 gcc.

The attachment is a possible fix.

[Bug libstdc++/61217] New: pop_heap can't guarantee At most 2 * log(last - first) comparisons

2014-05-18 Thread kan.liu.229 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61217

Bug ID: 61217
   Summary: pop_heap can't guarantee At most 2 * log(last - first)
comparisons
   Product: gcc
   Version: 4.9.0
Status: UNCONFIRMED
  Severity: minor
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: kan.liu.229 at gmail dot com

pop_heap uses __adjust_heap to percolate down the hole. 

Inside __adjust_heap, it uses __value stores the value where was in position
__result(__last). After percolating down the hole, it uses __push_heap to push
back the __value. Process of percolatiing down takes 2 * logN comparasion, and
__push_heap takes another 2 * logN, 4 * logN in total, which excceed the
requirement 2 * log(last - first) comparisons of standard.


[Bug libstdc++/61166] overflow when parse number in std::duration operator

2014-05-16 Thread kan.liu.229 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61166

--- Comment #12 from Kan Liu kan.liu.229 at gmail dot com ---
(In reply to Jonathan Wakely from comment #11)
 (In reply to Kan Liu from comment #10)
  _Select_type already does the overflow check, so *template implemented
  operators* is still redundant I think.
 
 You can't use _Select_type on a literal operator that is not a template.
 
  Since the standard units (std::hours,
  milliseconds ...) requires the duration::rep to be *int64_t*,
 
 No it doesn't, only chrono::nanoseconds is required to have a 64-bit
 representation. chrono::hours and chrono::minutes are allowed to have fewer
 than 32 bits (at least 23 bits and at least 29 bits respectively).
 
  there's no
  need to do too much check.
 
 Not all values of uint64_t fit in int64_t

Wow... I see


[Bug libstdc++/61166] overflow when parse number in std::duration operator

2014-05-15 Thread kan.liu.229 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61166

--- Comment #10 from Kan Liu kan.liu.229 at gmail dot com ---
(In reply to Jonathan Wakely from comment #9)
 I can see one good reason to implement those operators as templates: it
 allows us to check if the literal value overflows the duration::rep type,
 which is required by the standard but impossible to implement without using
 templates.

_Select_type already does the overflow check, so *template implemented
operators* is still redundant I think. Since the standard units (std::hours,
milliseconds ...) requires the duration::rep to be *int64_t*, there's no need
to do too much check.


[Bug libstdc++/61166] overflow when parse number in std::duration operator

2014-05-14 Thread kan.liu.229 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61166

--- Comment #7 from Kan Liu kan.liu.229 at gmail dot com ---
(In reply to emsr from comment #6)
 Something like parse_number was in the original doc as an implementation
 example.  The idea was to select the smallest integral type that could
 accommodate the number string with.  This is done with _Select_int. 
 _Select_type picks the most space-efficient duration ratio type using
 _Select_int.

Yeah, but it only helps saving space when compiling time for now. For now
implementation, _Select_type takes the default chrono::hour (and other time
units), which uses *int64_t* as its underlying representation. So, it doesn't
save space I think.

Take *ms* as example
Implementation now:

template char... _Digits
  constexpr typename
  __select_type::_Select_type__select_int::_Select_int_Digits...::value,
 chrono::milliseconds::type
  operatorms()
  {
return __select_type::_Select_type
  __select_int::_Select_int_Digits...::value,
  chrono::milliseconds::value;
  }

space-efficient version (maybe), get the type from _Select_int:

template char... _Digits
constexpr typename
chrono::durationdecltype(__select_int::_Select_int_Digits...::value), milli
operator_ms()
{
typedef typename __select_int::_Select_int_Digits... __selected;
typedef typename chrono::durationdecltype(__selected::value), milli
__duration_type;
return __duration_type {__selected::value};
}


[Bug libstdc++/61166] New: overflow when parse number in std::duration operator

2014-05-13 Thread kan.liu.229 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61166

Bug ID: 61166
   Summary: overflow when parse number in std::duration operator
   Product: gcc
   Version: 4.9.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: kan.liu.229 at gmail dot com

overflow may occur when using a number whose size exceeds sizeof(unsigned) in
chrono_literals. Because the parse classes in include/bits/parse_number.h just
use *unsigned* for member type. However, it should accept *unsigned long long*
I think. This issue also exists in trunk I think.

#include chrono

using namespace std;
using namespace std::chrono;

int main() {
// std::numeric_limitsunsigned::max() == 4294967295
cout  429496729510  endl;
cout  (429496729510h).count()  endl;
return 0;
}

And the result is

429496729510 
926648584


[Bug libstdc++/61166] overflow when parse number in std::duration operator

2014-05-13 Thread kan.liu.229 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61166

--- Comment #3 from Kan Liu kan.liu.229 at gmail dot com ---
(In reply to emsr from comment #2)
 Created attachment 32789 [details]
 Patch to parse_nmber to make it unsigned long long all over.
 
 Works on x86_64-linux.

Yeah, it works. Thank you!


[Bug libstdc++/61166] overflow when parse number in std::duration operator

2014-05-13 Thread kan.liu.229 at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61166

--- Comment #4 from Kan Liu kan.liu.229 at gmail dot com ---
btw, is it really necessary to use functionality in parse_number.h to parse
manually? What *parse_number* has done is no more than the general
*operator(unsigned long long)*, and it just enables *0b* and *0B* prefix for
the numbers. I think *operator(unsigned long long)* is quite enough for this.