Bug 86398 - is_trivially_constructible always returns true even when is_constructible returns false
Summary: is_trivially_constructible always returns true even when is_constructible ret...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: 8.2
Assignee: ville
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2018-07-04 01:26 UTC by Arthur O'Dwyer
Modified: 2018-07-04 21:00 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 7.3.0
Known to fail: 8.1.0, 9.0
Last reconfirmed: 2018-07-04 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Arthur O'Dwyer 2018-07-04 01:26:32 UTC
This actually looks like a duplicate of PR80682, but that one was closed as "fixed" a while back, and the bug is still present.

// https://godbolt.org/g/SfcQiC
#include <type_traits>
int x[] = {
  std::is_trivially_constructible_v<int,void*>,
  std::is_constructible_v<int,void*>,
};
int main() {
    printf("%d %d\n", x[0], x[1]);
}

On Clang this prints "0 0" because `int` is not constructible from `void*`.
On GCC this prints "1 0": `int` is trivially constructible, yet not constructible, from `void*`.
Comment 1 Jonathan Wakely 2018-07-04 08:04:48 UTC
Presumably started with r248153
Comment 2 Jonathan Wakely 2018-07-04 08:17:38 UTC
(In reply to Arthur O'Dwyer from comment #0)
> This actually looks like a duplicate of PR80682, but that one was closed as
> "fixed" a while back, and the bug is still present.

Definitely not a dup. The testcase for PR 80682 no longer fails, and the testcase for  this one didn't fail until the fix for 80682 was committed. So it's caused by it, and so can't possibly be a dup.
Comment 3 Jonathan Wakely 2018-07-04 09:03:55 UTC
Author: redi
Date: Wed Jul  4 09:03:18 2018
New Revision: 262379

URL: https://gcc.gnu.org/viewcvs?rev=262379&root=gcc&view=rev
Log:
PR libstdc++/86398 fix std::is_trivially_constructible regression

The intrinsic doesn't check for allowed conversions between scalar
types, so restore the std::is_constructible check.

Also make some trivial whitespace changes.

	PR libstdc++/86398
	* include/std/type_traits (is_trivially_constructible): Check
	is_constructible before __is_trivially_constructible.
	* testsuite/20_util/is_trivially_constructible/value.cc: Add more
	tests, including negative cases.
	* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Use
	zero for dg-error lineno.
	* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
	Likewise.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/std/type_traits
    trunk/libstdc++-v3/testsuite/20_util/is_trivially_constructible/value.cc
    trunk/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
    trunk/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
Comment 4 Jonathan Wakely 2018-07-04 11:44:43 UTC
Author: redi
Date: Wed Jul  4 11:44:11 2018
New Revision: 262381

URL: https://gcc.gnu.org/viewcvs?rev=262381&root=gcc&view=rev
Log:
PR libstdc++/86398 fix std::is_trivially_constructible regression

The intrinsic doesn't check for allowed conversions between scalar
types, so restore the std::is_constructible check.

Also make some trivial whitespace changes.

	PR libstdc++/86398
	* include/std/type_traits (is_trivially_constructible): Check
	is_constructible before __is_trivially_constructible.
	* testsuite/20_util/is_trivially_constructible/value.cc: Add more
	tests, including negative cases.
	* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Use
	zero for dg-error lineno.
	* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
	Likewise.

Modified:
    branches/gcc-8-branch/libstdc++-v3/ChangeLog
    branches/gcc-8-branch/libstdc++-v3/include/std/type_traits
    branches/gcc-8-branch/libstdc++-v3/testsuite/20_util/is_trivially_constructible/value.cc
    branches/gcc-8-branch/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
    branches/gcc-8-branch/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
Comment 5 Jonathan Wakely 2018-07-04 11:48:08 UTC
The regression is fixed for 8.2 with a workaround in the library header.

Changing component back to c++ so Ville can fix the intrinisic.
Comment 6 ville 2018-07-04 19:22:15 UTC
Author: ville
Date: Wed Jul  4 19:21:38 2018
New Revision: 262420

URL: https://gcc.gnu.org/viewcvs?rev=262420&root=gcc&view=rev
Log:
PR c++/86398

gcc/cp/

PR c++/86398
* method.c (is_trivially_xible): Return false
if is_xible_helper returns a NULL_TREE.

testsuite/

PR c++/86398
* g++.dg/ext/is_trivially_constructible1.C: Add new tests.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/method.c
    trunk/gcc/testsuite/g++.dg/ext/is_trivially_constructible1.C
Comment 7 ville 2018-07-04 20:56:44 UTC
Author: ville
Date: Wed Jul  4 20:56:12 2018
New Revision: 262424

URL: https://gcc.gnu.org/viewcvs?rev=262424&root=gcc&view=rev
Log:
Backport from mainline

2018-07-04  Ville Voutilainen  <ville.voutilainen@gmail.com>

gcc/cp/

PR c++/86398
* method.c (is_trivially_xible): Return false
if is_xible_helper returns a NULL_TREE.

testsuite/

PR c++/86398
* g++.dg/ext/is_trivially_constructible1.C: Add new tests.

Modified:
    branches/gcc-8-branch/gcc/cp/ChangeLog
    branches/gcc-8-branch/gcc/cp/method.c
    branches/gcc-8-branch/gcc/testsuite/g++.dg/ext/is_trivially_constructible1.C
Comment 8 Ville Voutilainen 2018-07-04 21:00:00 UTC
Fixed.