diff mbox series

c++: Add test for DR 1423, Convertibility of nullptr to bool.

Message ID 20200224180956.402391-1-polacek@redhat.com
State New
Headers show
Series c++: Add test for DR 1423, Convertibility of nullptr to bool. | expand

Commit Message

Marek Polacek Feb. 24, 2020, 6:09 p.m. UTC
DR 1423, which supersedes DR 654, says that you can't copy-init
a bool from a std::nullptr_t:

  bool b = nullptr;  // error

Conversely, it works with direct-initialization which is more
permissive than copy-initialization.

No code changes necessary since we handle it right.

Tested on x86_64-linux, ok for trunk?

2020-02-24  Marek Polacek  <polacek@redhat.com>

	DR 1423, Convertibility of nullptr to bool.
	* g++.dg/DRs/dr1423.C: New test.
---
 gcc/testsuite/g++.dg/DRs/dr1423.C | 7 +++++++
 1 file changed, 7 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/DRs/dr1423.C


base-commit: a4dbb9b25a60143c699de55cd6226cebeb3b3c3e

Comments

Jason Merrill Feb. 26, 2020, 4:58 a.m. UTC | #1
On 2/24/20 1:09 PM, Marek Polacek wrote:
> DR 1423, which supersedes DR 654, says that you can't copy-init
> a bool from a std::nullptr_t:
> 
>    bool b = nullptr;  // error
> 
> Conversely, it works with direct-initialization which is more
> permissive than copy-initialization.
> 
> No code changes necessary since we handle it right.
> 
> Tested on x86_64-linux, ok for trunk?

OK.

> 2020-02-24  Marek Polacek  <polacek@redhat.com>
> 
> 	DR 1423, Convertibility of nullptr to bool.
> 	* g++.dg/DRs/dr1423.C: New test.
> ---
>   gcc/testsuite/g++.dg/DRs/dr1423.C | 7 +++++++
>   1 file changed, 7 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/DRs/dr1423.C
> 
> diff --git a/gcc/testsuite/g++.dg/DRs/dr1423.C b/gcc/testsuite/g++.dg/DRs/dr1423.C
> new file mode 100644
> index 00000000000..d82baae9985
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/DRs/dr1423.C
> @@ -0,0 +1,7 @@
> +// DR 1423 - Convertibility of nullptr to bool.
> +// { dg-do compile { target c++11 } }
> +
> +bool b = nullptr; // { dg-error "converting to .bool. from .std::nullptr_t. requires direct-initialization" }
> +bool b2(nullptr);
> +bool b3{nullptr};
> +bool b4 = { nullptr }; // { dg-error "converting to .bool. from .std::nullptr_t. requires direct-initialization" }
> 
> base-commit: a4dbb9b25a60143c699de55cd6226cebeb3b3c3e
>
diff mbox series

Patch

diff --git a/gcc/testsuite/g++.dg/DRs/dr1423.C b/gcc/testsuite/g++.dg/DRs/dr1423.C
new file mode 100644
index 00000000000..d82baae9985
--- /dev/null
+++ b/gcc/testsuite/g++.dg/DRs/dr1423.C
@@ -0,0 +1,7 @@ 
+// DR 1423 - Convertibility of nullptr to bool.
+// { dg-do compile { target c++11 } }
+
+bool b = nullptr; // { dg-error "converting to .bool. from .std::nullptr_t. requires direct-initialization" }
+bool b2(nullptr);
+bool b3{nullptr};
+bool b4 = { nullptr }; // { dg-error "converting to .bool. from .std::nullptr_t. requires direct-initialization" }