Bug 81468 - [DR1177] is_constructible gives the wrong answer for time_point construction
Summary: [DR1177] is_constructible gives the wrong answer for time_point construction
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: 5.5
Assignee: Jonathan Wakely
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-17 17:48 UTC by Howard Hinnant
Modified: 2017-09-18 20:01 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 5.4.0, 6.4.0, 7.2.0
Last reconfirmed: 2017-07-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Howard Hinnant 2017-07-17 17:48:59 UTC
This should compile, but does not:

#include <chrono>
#include <type_traits>

template <class Duration>
    using sys_time = std::chrono::time_point<std::chrono::system_clock, Duration>;

int
main()
{
    using namespace std;
    using namespace std::chrono;
    static_assert(!is_constructible<sys_time<seconds>, sys_time<milliseconds>>{}, "");
//    sys_time<seconds> s{sys_time<milliseconds>{123ms}};
}
Comment 1 Daniel Krügler 2017-07-17 19:13:46 UTC
It seems that the implementation simply forgot to constrain overload resolution, since this is the complete definition of the affected constructor:

template<typename _Dur2>
  constexpr time_point(const time_point<clock, _Dur2>& __t)
  : __d(__t.time_since_epoch())
  { }

The constraints were added by LWG 1177,

http://cplusplus.github.io/LWG/lwg-defects.html#1177
Comment 2 Daniel Krügler 2017-07-21 17:50:36 UTC
Shouldn't add a DR-1177 tag? (I forgot the exact construction pattern for this) This may also help to validate that all other wording changes by this issue had been implemented.
Comment 3 Jonathan Wakely 2017-07-22 14:04:13 UTC
Done. I think adding a DR number to the title is more useful when we suspend a bug while the issue is still open, but there's certainly no harm adding it.
Comment 4 Jonathan Wakely 2017-09-13 14:08:16 UTC
Author: redi
Date: Wed Sep 13 14:07:44 2017
New Revision: 252085

URL: https://gcc.gnu.org/viewcvs?rev=252085&root=gcc&view=rev
Log:
PR libstdc++/81468 constrain std::chrono::time_point constructor

	PR libstdc++/81468
	* include/std/chrono (__enable_if_is_duration)
	(__disable_if_is_duration): New alias templates to simplify SFINAE.
	(duration_cast, floor, ceil): Use __enable_if_is_duration.
	(duration::__is_float, duration::__is_harmonic): New alias templates
	to simplify SFINAE.
	(duration::duration(const _Rep2&)): Use _Require, __is_float and
	__is_harmonic.
	(duration::duration(const duration<_Rep2, _Period2>&)): Likewise.
	(__common_rep_type): Remove, replace with ...
	(__common_rep_t): New alias template.
	(operator*, operator/, operator%): Use __common_rep_t and
	__disable_if_is_duration.
	(time_point::time_point(const time_point<clock, _Dur2>&)): Add missing
	constraint from LWG DR 1177.
	* testsuite/20_util/duration/cons/dr1177.cc: New.
	* testsuite/20_util/duration/literals/range.cc: Update dg-error line.
	* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Likewise.
	* testsuite/20_util/duration/requirements/typedefs_neg2.cc: Likewise.
	* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Likewise.
	* testsuite/20_util/time_point/cons/81468.cc: New.

Added:
    trunk/libstdc++-v3/testsuite/20_util/duration/cons/dr1177.cc
    trunk/libstdc++-v3/testsuite/20_util/time_point/cons/81468.cc
      - copied, changed from r252076, trunk/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/std/chrono
    trunk/libstdc++-v3/testsuite/20_util/duration/literals/range.cc
    trunk/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg1.cc
    trunk/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg2.cc
    trunk/libstdc++-v3/testsuite/20_util/duration/requirements/typedefs_neg3.cc
Comment 5 Jonathan Wakely 2017-09-13 15:20:53 UTC
Author: redi
Date: Wed Sep 13 15:20:21 2017
New Revision: 252090

URL: https://gcc.gnu.org/viewcvs?rev=252090&root=gcc&view=rev
Log:
PR libstdc++/81468 constrain std::chrono::time_point constructor

	PR libstdc++/81468
	* include/std/chrono (time_point(const time_point<_Dur2>&)): Add
	missing constraint from LWG DR 1177.
	* testsuite/20_util/duration/cons/dr1177.cc: New.
	* testsuite/20_util/time_point/cons/81468.cc: New.
	* testsuite/20_util/duration/literals/range.cc: Update dg-error line.

Added:
    branches/gcc-7-branch/libstdc++-v3/testsuite/20_util/duration/cons/dr1177.cc
    branches/gcc-7-branch/libstdc++-v3/testsuite/20_util/time_point/cons/81468.cc
      - copied, changed from r252071, branches/gcc-7-branch/libstdc++-v3/testsuite/20_util/duration/literals/range.cc
Modified:
    branches/gcc-7-branch/libstdc++-v3/ChangeLog
    branches/gcc-7-branch/libstdc++-v3/include/std/chrono
    branches/gcc-7-branch/libstdc++-v3/testsuite/20_util/duration/literals/range.cc
Comment 6 Jonathan Wakely 2017-09-13 15:21:06 UTC
Author: redi
Date: Wed Sep 13 15:20:34 2017
New Revision: 252091

URL: https://gcc.gnu.org/viewcvs?rev=252091&root=gcc&view=rev
Log:
PR libstdc++/81468 constrain std::chrono::time_point constructor

	PR libstdc++/81468
	* include/std/chrono (time_point(const time_point<_Dur2>&)): Add
	missing constraint from LWG DR 1177.
	* testsuite/20_util/duration/cons/dr1177.cc: New.
	* testsuite/20_util/time_point/cons/81468.cc: New.
	* testsuite/20_util/duration/literals/range.cc: Update dg-error line.

Added:
    branches/gcc-6-branch/libstdc++-v3/testsuite/20_util/duration/cons/dr1177.cc
    branches/gcc-6-branch/libstdc++-v3/testsuite/20_util/time_point/cons/81468.cc
      - copied, changed from r252072, branches/gcc-6-branch/libstdc++-v3/testsuite/20_util/duration/literals/range.cc
Modified:
    branches/gcc-6-branch/libstdc++-v3/ChangeLog
    branches/gcc-6-branch/libstdc++-v3/include/std/chrono
    branches/gcc-6-branch/libstdc++-v3/testsuite/20_util/duration/literals/range.cc
Comment 7 Jonathan Wakely 2017-09-13 15:28:44 UTC
Author: redi
Date: Wed Sep 13 15:28:12 2017
New Revision: 252092

URL: https://gcc.gnu.org/viewcvs?rev=252092&root=gcc&view=rev
Log:
PR libstdc++/81468 constrain std::chrono::time_point constructor

	PR libstdc++/81468
	* include/std/chrono (time_point(const time_point<_Dur2>&)): Add
	missing constraint from LWG DR 1177.
	* testsuite/20_util/duration/cons/dr1177.cc: New.
	* testsuite/20_util/time_point/cons/81468.cc: New.
	* testsuite/20_util/duration/literals/range.cc: Update dg-error line.

Added:
    branches/gcc-5-branch/libstdc++-v3/testsuite/20_util/duration/cons/dr1177.cc
    branches/gcc-5-branch/libstdc++-v3/testsuite/20_util/time_point/cons/81468.cc
      - copied, changed from r252073, branches/gcc-5-branch/libstdc++-v3/testsuite/20_util/duration/literals/range.cc
Modified:
    branches/gcc-5-branch/libstdc++-v3/ChangeLog
    branches/gcc-5-branch/libstdc++-v3/include/std/chrono
    branches/gcc-5-branch/libstdc++-v3/testsuite/20_util/duration/literals/range.cc
Comment 8 Jonathan Wakely 2017-09-13 15:36:08 UTC
Fixed for 5.5, 6.5 and 7.3 (all active branches).
Comment 9 Jonathan Wakely 2017-09-18 20:01:04 UTC
Author: redi
Date: Mon Sep 18 20:00:32 2017
New Revision: 252950

URL: https://gcc.gnu.org/viewcvs?rev=252950&root=gcc&view=rev
Log:
PR libstdc++/81468 fix test for duration conversions

	PR libstdc++/81468
	* testsuite/20_util/duration/cons/dr1177.cc: Fix incorrect test and
	improve static assertion messages.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/testsuite/20_util/duration/cons/dr1177.cc