[PATCH] D40144: Implement `std::launder`

2017-11-22 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists closed this revision.
mclow.lists added a comment.

landed as revision 318864


https://reviews.llvm.org/D40144



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40144: Implement `std::launder`

2017-11-21 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists updated this revision to Diff 123877.
mclow.lists added a comment.

`_VSTD::` qualify the call to `__launder`.
De-dup error messages in test.


https://reviews.llvm.org/D40144

Files:
  include/__config
  include/new
  
test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
  test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
  test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
  www/cxx1z_status.html

Index: www/cxx1z_status.html
===
--- www/cxx1z_status.html
+++ www/cxx1z_status.html
@@ -104,6 +104,7 @@
 	https://wg21.link/p0083r3";>p0083r3LWGSplicing Maps and SetsOulu
 	https://wg21.link/p0084r2";>p0084r2LWGEmplace Return TypeOuluComplete4.0
 	https://wg21.link/p0088r3";>p0088r3LWGVariant: a type-safe union for C++17OuluComplete4.0
+	https://wg21.link/p0137r1";>p0137r1CWGCore Issue 1776: Replacement of class objects containing reference membersOuluComplete6.0
 	https://wg21.link/p0163r0";>p0163r0LWGshared_ptr::weak_typeOuluComplete3.9
 	https://wg21.link/p0174r2";>p0174r2LWGDeprecating Vestigial Library Parts in C++17Oulu
 	https://wg21.link/p0175r1";>p0175r1LWGSynopses for the C libraryOulu
Index: test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
@@ -0,0 +1,34 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  constexpr T* launder(T* p) noexcept;
+// The program is ill-formed if T is a function type or cv void.
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+void foo() {}
+
+int main ()
+{
+void *p = nullptr;
+(void) std::launder((   void *) nullptr);
+(void) std::launder((const  void *) nullptr);
+(void) std::launder((  volatile void *) nullptr);
+(void) std::launder((const volatile void *) nullptr);  // expected-error-re@new:* 4 {{static_assert failed{{.*}} "can't launder cv-void"}}
+
+(void) std::launder(foo);  // expected-error-re@new:* 1 {{static_assert failed{{.*}} "can't launder functions"}}
+}
Index: test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
@@ -0,0 +1,35 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  constexpr T* launder(T* p) noexcept;
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+constexpr int gi = 5;
+constexpr float gf = 8.f;
+
+int main() {
+	static_assert(std::launder(&gi) == &gi, "" );
+	static_assert(std::launder(&gf) == &gf, "" );
+
+  	const int *i = &gi;
+  	const float *f = &gf;
+static_assert(std::is_same::value, "");
+static_assert(std::is_same::value, "");
+
+	assert(std::launder(i) == i);
+	assert(std::launder(f) == f);
+}
Index: test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
@@ -0,0 +1,27 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  constexpr T* launder(T* p) noexcept;
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+int main ()
+{
+int *p = nullptr;
+std::launder(p);  // expected-error {{ignoring 

[PATCH] D40144: Implement `std::launder`

2017-11-21 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added inline comments.



Comment at: 
test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp:16
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, 
clang-3.8
+

mclow.lists wrote:
> EricWF wrote:
> > Why is this test unsupported with older compilers? The version of 
> > `std::launder` in this patch should work regardless of compiler support for 
> > `__builtin_launder`.
> > 
> > Although, it's possible the compiler requirements were intended to avoid 
> > older clang versions without `[[nodiscard]]`. However, I don't think 
> > `clang-3.8` supports C++2a, so the condition seems redundant.
> > 
> We're testing the `[[nodiscard]]` bit here, not the `launder` bit. And that 
> didn't come in until clang 3.9
Perhaps we should fall back to `__attribute__((warn_unused_result))` when we 
don't have `[[nodiscard]]`? All supported Clang versions should provide that, 
as well as GCC 4.9 and newer.


https://reviews.llvm.org/D40144



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40144: Implement `std::launder`

2017-11-21 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added inline comments.



Comment at: 
test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp:16
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, 
clang-3.8
+

EricWF wrote:
> Why is this test unsupported with older compilers? The version of 
> `std::launder` in this patch should work regardless of compiler support for 
> `__builtin_launder`.
> 
> Although, it's possible the compiler requirements were intended to avoid 
> older clang versions without `[[nodiscard]]`. However, I don't think 
> `clang-3.8` supports C++2a, so the condition seems redundant.
> 
We're testing the `[[nodiscard]]` bit here, not the `launder` bit. And that 
didn't come in until clang 3.9


https://reviews.llvm.org/D40144



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40144: Implement `std::launder`

2017-11-21 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added inline comments.



Comment at: include/new:274
+{
+return __launder(__p);
+}

The call should probably be qualified to `_VSTD::__launder`.



Comment at: 
test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp:16
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, 
clang-3.8
+

Why is this test unsupported with older compilers? The version of 
`std::launder` in this patch should work regardless of compiler support for 
`__builtin_launder`.

Although, it's possible the compiler requirements were intended to avoid older 
clang versions without `[[nodiscard]]`. However, I don't think `clang-3.8` 
supports C++2a, so the condition seems redundant.




Comment at: 
test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp:28
+void *p = nullptr;
+(void) std::launder((   void *) nullptr);  // 
expected-error-re@new:* {{static_assert failed{{.*}} "can't launder cv-void"}}
+(void) std::launder((const  void *) nullptr);  // 
expected-error-re@new:* {{static_assert failed{{.*}} "can't launder cv-void"}}

Alternatively you could de-duplicate the four identical checks into the single 
check:

```
// expected-error-re@new:* 4 {{static_assert failed{{.*}} "can't launder 
cv-void"}}
```


https://reviews.llvm.org/D40144



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40144: Implement `std::launder`

2017-11-20 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists updated this revision to Diff 123663.
mclow.lists added a comment.

Un-c++17'ed the internal function `__launder`


https://reviews.llvm.org/D40144

Files:
  include/__config
  include/new
  
test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
  test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
  test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
  www/cxx1z_status.html

Index: www/cxx1z_status.html
===
--- www/cxx1z_status.html
+++ www/cxx1z_status.html
@@ -104,6 +104,7 @@
 	https://wg21.link/p0083r3";>p0083r3LWGSplicing Maps and SetsOulu
 	https://wg21.link/p0084r2";>p0084r2LWGEmplace Return TypeOuluComplete4.0
 	https://wg21.link/p0088r3";>p0088r3LWGVariant: a type-safe union for C++17OuluComplete4.0
+	https://wg21.link/p0137r1";>p0137r1CWGCore Issue 1776: Replacement of class objects containing reference membersOuluComplete6.0
 	https://wg21.link/p0163r0";>p0163r0LWGshared_ptr::weak_typeOuluComplete3.9
 	https://wg21.link/p0174r2";>p0174r2LWGDeprecating Vestigial Library Parts in C++17Oulu
 	https://wg21.link/p0175r1";>p0175r1LWGSynopses for the C libraryOulu
Index: test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
@@ -0,0 +1,34 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  constexpr T* launder(T* p) noexcept;
+// The program is ill-formed if T is a function type or cv void.
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+void foo() {}
+
+int main ()
+{
+void *p = nullptr;
+(void) std::launder((   void *) nullptr);  // expected-error-re@new:* {{static_assert failed{{.*}} "can't launder cv-void"}}
+(void) std::launder((const  void *) nullptr);  // expected-error-re@new:* {{static_assert failed{{.*}} "can't launder cv-void"}}
+(void) std::launder((  volatile void *) nullptr);  // expected-error-re@new:* {{static_assert failed{{.*}} "can't launder cv-void"}}
+(void) std::launder((const volatile void *) nullptr);  // expected-error-re@new:* {{static_assert failed{{.*}} "can't launder cv-void"}}
+
+(void) std::launder(foo);  // expected-error-re@new:* 1 {{static_assert failed{{.*}} "can't launder functions"}}
+}
Index: test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
@@ -0,0 +1,35 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  constexpr T* launder(T* p) noexcept;
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+constexpr int gi = 5;
+constexpr float gf = 8.f;
+
+int main() {
+	static_assert(std::launder(&gi) == &gi, "" );
+	static_assert(std::launder(&gf) == &gf, "" );
+
+  	const int *i = &gi;
+  	const float *f = &gf;
+static_assert(std::is_same::value, "");
+static_assert(std::is_same::value, "");
+
+	assert(std::launder(i) == i);
+	assert(std::launder(f) == f);
+}
Index: test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
@@ -0,0 +1,27 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  constexpr T* launder(T* p) noexcept;
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+// UNSU

[PATCH] D40144: Implement `std::launder`

2017-11-20 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added inline comments.



Comment at: include/new:260
+static_assert (!is_function<_Tp>::value, "can't launder functions" );
+static_assert (!is_same_v>, "can't launder cv-void" 
);
+#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER

tcanens wrote:
> Technically, the attempt is to launder //pointers to// //cv// 
> `void`/functions. :)
> 
> Also, since `__launder` is non-C++17-specific, I guess it can't use `_t` and 
> `_v` after all... - and I suppose it'll also need to parens-protect the 
> `is_same` check for the fallback `static_assert` macro?
Oh, *bother* (and yes, you're correct)


https://reviews.llvm.org/D40144



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40144: Implement `std::launder`

2017-11-20 Thread Tim Song via Phabricator via cfe-commits
tcanens added inline comments.



Comment at: include/new:260
+static_assert (!is_function<_Tp>::value, "can't launder functions" );
+static_assert (!is_same_v>, "can't launder cv-void" 
);
+#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER

Technically, the attempt is to launder //pointers to// //cv// `void`/functions. 
:)

Also, since `__launder` is non-C++17-specific, I guess it can't use `_t` and 
`_v` after all... - and I suppose it'll also need to parens-protect the 
`is_same` check for the fallback `static_assert` macro?


https://reviews.llvm.org/D40144



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40144: Implement `std::launder`

2017-11-20 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists updated this revision to Diff 123644.
mclow.lists added a comment.

Made an internal function `__launder` which is not c++17 specific.
Fixed some wording for the standard asserts.


https://reviews.llvm.org/D40144

Files:
  include/__config
  include/new
  
test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
  test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
  test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
  www/cxx1z_status.html

Index: www/cxx1z_status.html
===
--- www/cxx1z_status.html
+++ www/cxx1z_status.html
@@ -104,6 +104,7 @@
 	https://wg21.link/p0083r3";>p0083r3LWGSplicing Maps and SetsOulu
 	https://wg21.link/p0084r2";>p0084r2LWGEmplace Return TypeOuluComplete4.0
 	https://wg21.link/p0088r3";>p0088r3LWGVariant: a type-safe union for C++17OuluComplete4.0
+	https://wg21.link/p0137r1";>p0137r1CWGCore Issue 1776: Replacement of class objects containing reference membersOuluComplete6.0
 	https://wg21.link/p0163r0";>p0163r0LWGshared_ptr::weak_typeOuluComplete3.9
 	https://wg21.link/p0174r2";>p0174r2LWGDeprecating Vestigial Library Parts in C++17Oulu
 	https://wg21.link/p0175r1";>p0175r1LWGSynopses for the C libraryOulu
Index: test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
@@ -0,0 +1,34 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  constexpr T* launder(T* p) noexcept;
+// The program is ill-formed if T is a function type or cv void.
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+void foo() {}
+
+int main ()
+{
+void *p = nullptr;
+(void) std::launder((   void *) nullptr);  // expected-error-re@new:* {{static_assert failed{{.*}} "can't launder cv-void"}}
+(void) std::launder((const  void *) nullptr);  // expected-error-re@new:* {{static_assert failed{{.*}} "can't launder cv-void"}}
+(void) std::launder((  volatile void *) nullptr);  // expected-error-re@new:* {{static_assert failed{{.*}} "can't launder cv-void"}}
+(void) std::launder((const volatile void *) nullptr);  // expected-error-re@new:* {{static_assert failed{{.*}} "can't launder cv-void"}}
+
+(void) std::launder(foo);  // expected-error-re@new:* 1 {{static_assert failed{{.*}} "can't launder functions"}}
+}
Index: test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
@@ -0,0 +1,35 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  constexpr T* launder(T* p) noexcept;
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+constexpr int gi = 5;
+constexpr float gf = 8.f;
+
+int main() {
+	static_assert(std::launder(&gi) == &gi, "" );
+	static_assert(std::launder(&gf) == &gf, "" );
+
+  	const int *i = &gi;
+  	const float *f = &gf;
+static_assert(std::is_same::value, "");
+static_assert(std::is_same::value, "");
+
+	assert(std::launder(i) == i);
+	assert(std::launder(f) == f);
+}
Index: test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
@@ -0,0 +1,27 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  constexpr T* launder(T* p) noexc

[PATCH] D40144: Implement `std::launder`

2017-11-18 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

I've made an attempt to add `__builtin_launder` to clang in D40218 
.


https://reviews.llvm.org/D40144



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40144: Implement `std::launder`

2017-11-18 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

I think we may want a `__launder` function that we can use internally in all 
dialects.




Comment at: include/__config:458
+#if __has_builtin(__builtin_launder)
+#define_LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
+#endif

These macros should take the negative `_LIBCPP_HAS_NO_BUILTIN_LAUNDER` form to 
be consistent.



Comment at: include/new:260
+{
+static_assert (!is_function<_Tp>::value, "Can't launder functions" );
+static_assert (!is_same::type>::value, 
"Can't launder cv-void" );

Typically diagnostics don't start with capitals.

Small nit on the use of a contraction too.



Comment at: include/new:261
+static_assert (!is_function<_Tp>::value, "Can't launder functions" );
+static_assert (!is_same::type>::value, 
"Can't launder cv-void" );
+#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER

Since this is C++17 only, we can use the `trait_t` and `trait_v` versions to be 
less verbose. 


https://reviews.llvm.org/D40144



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40144: Implement `std::launder`

2017-11-17 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists updated this revision to Diff 123422.
mclow.lists marked an inline comment as done.
mclow.lists added a comment.

Move the `launder` function into the main libc++ namespace.
Call `__builtin_launder` when available.
Check to see when it's available (for gcc and clang)


https://reviews.llvm.org/D40144

Files:
  include/__config
  include/new
  
test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
  test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
  test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
  www/cxx1z_status.html

Index: www/cxx1z_status.html
===
--- www/cxx1z_status.html
+++ www/cxx1z_status.html
@@ -104,6 +104,7 @@
 	https://wg21.link/p0083r3";>p0083r3LWGSplicing Maps and SetsOulu
 	https://wg21.link/p0084r2";>p0084r2LWGEmplace Return TypeOuluComplete4.0
 	https://wg21.link/p0088r3";>p0088r3LWGVariant: a type-safe union for C++17OuluComplete4.0
+	https://wg21.link/p0137r1";>p0137r1CWGCore Issue 1776: Replacement of class objects containing reference membersOuluComplete6.0
 	https://wg21.link/p0163r0";>p0163r0LWGshared_ptr::weak_typeOuluComplete3.9
 	https://wg21.link/p0174r2";>p0174r2LWGDeprecating Vestigial Library Parts in C++17Oulu
 	https://wg21.link/p0175r1";>p0175r1LWGSynopses for the C libraryOulu
Index: test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
@@ -0,0 +1,34 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  constexpr T* launder(T* p) noexcept;
+// The program is ill-formed if T is a function type or cv void.
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+void foo() {}
+
+int main ()
+{
+void *p = nullptr;
+(void) std::launder((   void *) nullptr);  // expected-error-re@new:* {{static_assert failed{{.*}} "Can't launder cv-void"}}
+(void) std::launder((const  void *) nullptr);  // expected-error-re@new:* {{static_assert failed{{.*}} "Can't launder cv-void"}}
+(void) std::launder((  volatile void *) nullptr);  // expected-error-re@new:* {{static_assert failed{{.*}} "Can't launder cv-void"}}
+(void) std::launder((const volatile void *) nullptr);  // expected-error-re@new:* {{static_assert failed{{.*}} "Can't launder cv-void"}}
+
+(void) std::launder(foo);  // expected-error-re@new:* 1 {{static_assert failed{{.*}} "Can't launder functions"}}
+}
Index: test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
@@ -0,0 +1,35 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  constexpr T* launder(T* p) noexcept;
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+constexpr int gi = 5;
+constexpr float gf = 8.f;
+
+int main() {
+	static_assert(std::launder(&gi) == &gi, "" );
+	static_assert(std::launder(&gf) == &gf, "" );
+
+  	const int *i = &gi;
+  	const float *f = &gf;
+static_assert(std::is_same::value, "");
+static_assert(std::is_same::value, "");
+
+	assert(std::launder(i) == i);
+	assert(std::launder(f) == f);
+}
Index: test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
@@ -0,0 +1,27 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===---

[PATCH] D40144: Implement `std::launder`

2017-11-17 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists marked an inline comment as done.
mclow.lists added inline comments.



Comment at: include/new:174
+_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
+constexpr _Tp* launder(_Tp* __p) noexcept { return __p;}
+#endif

efriedma wrote:
> efriedma wrote:
> > How is the compiler supposed to know that "std::__1::launder()" has special 
> > semantics?
> Oh, wait, is this actually not in the __1 namespace?  Sort of hard to tell 
> because the patch wasn't posted with enough context.
> 
> It isn't exactly great to special-case functions named "std::launder"... but 
> wouldn't be the first name in the std namespace which has special compiler 
> semantics.
I'm about to move it into the _1 namespace. Since it's calling a compiler 
intrinsic, it doesn't need to be in a special place.



https://reviews.llvm.org/D40144



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40144: Implement `std::launder`

2017-11-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D40144#927866, @hfinkel wrote:

> In https://reviews.llvm.org/D40144#927828, @tcanens wrote:
>
> > At least for GCC, it should use `__builtin_launder`.
>
>
> I presume we'll need to add something similar for Clang as well.


Yes, we agreed to use the same builtin name for this in Clang and GCC quite a 
while back, but haven't actually got around to implementing it in Clang yet. 
You should use `__has_builtin` to detect the existence of this builtin in 
Clang. In GCC, I believe this is available iff `__GNUC__` is 7 or greater.


https://reviews.llvm.org/D40144



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40144: Implement `std::launder`

2017-11-16 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

In https://reviews.llvm.org/D40144#927828, @tcanens wrote:

> At least for GCC, it should use `__builtin_launder`.


I presume we'll need to add something similar for Clang as well.

> Also needs to implement "The program is ill-formed if `T` is a function type 
> or //cv// `void`."




https://reviews.llvm.org/D40144



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40144: Implement `std::launder`

2017-11-16 Thread Tim Song via Phabricator via cfe-commits
tcanens added a comment.

At least for GCC, it should use `__builtin_launder`.

Also needs to implement "The program is ill-formed if `T` is a function type or 
//cv// `void`."


https://reviews.llvm.org/D40144



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40144: Implement `std::launder`

2017-11-16 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: include/new:174
+_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
+constexpr _Tp* launder(_Tp* __p) noexcept { return __p;}
+#endif

efriedma wrote:
> How is the compiler supposed to know that "std::__1::launder()" has special 
> semantics?
Oh, wait, is this actually not in the __1 namespace?  Sort of hard to tell 
because the patch wasn't posted with enough context.

It isn't exactly great to special-case functions named "std::launder"... but 
wouldn't be the first name in the std namespace which has special compiler 
semantics.


https://reviews.llvm.org/D40144



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40144: Implement `std::launder`

2017-11-16 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: include/new:174
+_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
+constexpr _Tp* launder(_Tp* __p) noexcept { return __p;}
+#endif

How is the compiler supposed to know that "std::__1::launder()" has special 
semantics?


https://reviews.llvm.org/D40144



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40144: Implement `std::launder`

2017-11-16 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: 
test/std/language.support/support.dynamic/ptr.launder/launder.fail.cpp:26
+int *p = nullptr;
+std::launder(p);  // expected-error {{ignoring return value of function 
declared with 'nodiscard' attribute}}
+}

Would one also expect a decent static analyzer to warn that you are laundering 
a null pointer? (and should we care?)


https://reviews.llvm.org/D40144



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40144: Implement `std::launder`

2017-11-16 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists created this revision.

`std::launder` was introduced into c++17 as a compiler optimization barrier.  
It's something that the compiler 'knows about', and affects codegen.

See https://wg21.link/p0137r1 for more.


https://reviews.llvm.org/D40144

Files:
  include/new
  test/std/language.support/support.dynamic/ptr.launder/launder.fail.cpp
  test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
  www/cxx1z_status.html

Index: www/cxx1z_status.html
===
--- www/cxx1z_status.html
+++ www/cxx1z_status.html
@@ -104,6 +104,7 @@
 	https://wg21.link/p0083r3";>p0083r3LWGSplicing Maps and SetsOulu
 	https://wg21.link/p0084r2";>p0084r2LWGEmplace Return TypeOuluComplete4.0
 	https://wg21.link/p0088r3";>p0088r3LWGVariant: a type-safe union for C++17OuluComplete4.0
+	https://wg21.link/p0137r1";>p0137r1CWGCore Issue 1776: Replacement of class objects containing reference membersOuluComplete6.0
 	https://wg21.link/p0163r0";>p0163r0LWGshared_ptr::weak_typeOuluComplete3.9
 	https://wg21.link/p0174r2";>p0174r2LWGDeprecating Vestigial Library Parts in C++17Oulu
 	https://wg21.link/p0175r1";>p0175r1LWGSynopses for the C libraryOulu
Index: test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
@@ -0,0 +1,35 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  constexpr T* launder(T* p) noexcept;
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+constexpr int gi = 5;
+constexpr float gf = 8.f;
+
+int main() {
+	static_assert(std::launder(&gi) == &gi, "" );
+	static_assert(std::launder(&gf) == &gf, "" );
+
+  	const int *i = &gi;
+  	const float *f = &gf;
+static_assert(std::is_same::value, "");
+static_assert(std::is_same::value, "");
+
+	assert(std::launder(i) == i);
+	assert(std::launder(f) == f);
+}
Index: test/std/language.support/support.dynamic/ptr.launder/launder.fail.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.fail.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.fail.cpp
@@ -0,0 +1,27 @@
+// -*- C++ -*-
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  constexpr T* launder(T* p) noexcept;
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
+// UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+int main ()
+{
+int *p = nullptr;
+std::launder(p);  // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}}
+}
Index: include/new
===
--- include/new
+++ include/new
@@ -46,6 +46,8 @@
 new_handler set_new_handler(new_handler new_p) noexcept;
 new_handler get_new_handler() noexcept;
 
+// 21.6.4, pointer optimization barrier
+template  constexpr T* launder(T* p) noexcept; // C++17
 }  // std
 
 void* operator new(std::size_t size);   // replaceable
@@ -166,6 +168,11 @@
 #endif
 #endif
 
+#if _LIBCPP_STD_VER > 14
+template 
+_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
+constexpr _Tp* launder(_Tp* __p) noexcept { return __p;}
+#endif
 }  // std
 
 #if defined(_LIBCPP_CXX03_LANG)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits