[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary`

2023-09-11 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

Oh, I shouldn't have so much green in the status, whoops!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary`

2023-09-11 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

In D135341#4643712 , @erichkeane 
wrote:

> Is the changes to cxx_status.html still relevant/current?

Yeah.

> Also, did we ever figure out what GCC did for a builtin here?  Do they have 
> one yet?  If not, have we encouraged them to implement this one?  If so, DID 
> they implement this one?

They have implemented both, it seems :)

See https://godbolt.org/z/G8eeMfsej


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary`

2023-09-11 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Is the changes to cxx_status.html still relevant/current?  Also, did we ever 
figure out what GCC did for a builtin here?  Do they have one yet?  If not, 
have we encouraged them to implement this one?  If so, DID they implement this 
one?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary`

2023-09-11 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 556488.
cjdb added a comment.

responds to feedback:

- removes diagnostic
- adds documentation


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1091,6 +1091,197 @@
   https://wg21.link/p0195r2;>P0195R2
   Clang 4
 
+  Change scope of lambda trailing-return-type
+  https://wg21.link/P2036R3;>P2036R3
+  Clang 17
+
+
+  https://wg21.link/P2579R0;>P2579R0
+
+
+  Multidimensional subscript operator
+  https://wg21.link/P2128R6;>P2128R6
+  Clang 15
+
+
+  Non-literal variables (and labels and gotos) in constexpr functions
+  https://wg21.link/P2242R3;>P2242R3
+  Clang 15
+
+
+  Character encoding of diagnostic text
+  https://wg21.link/P2246R1;>P2246R1
+  Yes
+
+
+  Character sets and encodings
+  https://wg21.link/P2314R4;>P2314R4
+  Yes
+
+
+  Consistent character literal encoding
+  https://wg21.link/P2316R2;>P2316R2
+  Yes
+
+
+  Add support for preprocessing directives elifdef and elifndef
+  https://wg21.link/P2334R1;>P2334R1
+  Clang 13
+
+
+  Extend init-statement to allow alias-declaration
+  https://wg21.link/P2360R0;>P2360R0
+  Clang 14
+
+
+  auto(x): decay-copy in the language
+  https://wg21.link/P0849R8;>P0849R8
+  Clang 15
+
+
+
+  Attributes on Lambda-Expressions
+  https://wg21.link/P2173R1;>P2173R1
+  Clang 13
+
+
+  constexpr for cmath and cstdlib
+  https://wg21.link/P0533R9;>P0533R9
+  No
+
+
+  Type trait to determine if a reference binds to a temporary
+  https://wg21.link/P2255R2;>P2255R2
+  
+Partial
+  Clang provides __reference_constructs_from_temporary type
+  trait builtin, with which std::reference_constructs_from_temporary
+  implemented. __reference_converts_from_temporary needs to be
+  provided, following the normal cross-vendor convention to implement
+  traits requiring compiler support directly.
+
+  
+
+
+
+  The Equality Operator You Are Looking For
+  https://wg21.link/P2468R2;>P2468R2
+  Clang 16
+
+
+  De-deprecating volatile compound operations
+  https://wg21.link/P2327R1;>P2327R1
+  Clang 15
+
+
+  Support for #warning
+  https://wg21.link/P2437R1;>P2437R1
+  Yes
+
+
+  Remove non-encodable wide character literals and multicharacter wide character literals
+  https://wg21.link/P2362R3;>P2362R3
+  Clang 14
+
+
+  Labels at the end of compound statements
+  https://wg21.link/P2324R2;>P2324R2
+  Clang 16
+
+
+  Delimited escape sequences
+  https://wg21.link/P2290R3;>P2290R3
+  Clang 15
+
+
+  Named universal character escapes
+  https://wg21.link/P2071R2;>P2071R2
+  Clang 15
+
+
+  Relaxing some constexpr restrictions
+  https://wg21.link/P2448R2;>P2448R2
+  
+Clang 17 (Partial)
+	  We do not support outside of defaulted special memeber functions the change that constexpr functions no
+  longer have to be constexpr compatible but rather support a less restricted requirements for constexpr
+  functions. Which include allowing non-literal types as return values and paremeters, allow calling of
+  non-constexpr functions and constructors.
+
+  
+
+
+  Using unknown pointers and references in constant expressions
+  https://wg21.link/P2280R4;>P2280R4
+  No
+
+
+  static operator()
+  https://wg21.link/P1169R4;>P1169R4
+  Clang 16
+
+
+  Extended floating-point types and standard names
+  https://wg21.link/P1467R9;>P1467R9
+  No
+
+
+  Class template argument deduction from inherited constructors
+  https://wg21.link/P2582R1;>P2582R1
+  No
+
+
+  Portable assumptions
+  https://wg21.link/P1774R8;>P1774R8
+  No
+
+
+  Support for UTF-8 as a portable source file encoding
+  https://wg21.link/P2295R6;>P2295R6
+  Clang 15
+
+
+  char8_t Compatibility and Portability Fix
+  https://wg21.link/P2513R3;>P2513R3
+  Clang 16
+
+
+  Relax requirements on wchar_t to match existing practices
+  https://wg21.link/P2460R2;>P2460R2
+  Yes
+   

[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary`

2023-09-11 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

In D135341#4126101 , @erichkeane 
wrote:

> On the fence about the diagnostic at all, but definitely should not be doing 
> string magic to make it quoted.  Otherwise this is a LGTM.

Whoops, missed this comment. I'll be addressing your feedback and  merging 
later this week.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary`

2023-02-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

On the fence about the diagnostic at all, but definitely should not be doing 
string magic to make it quoted.  Otherwise this is a LGTM.




Comment at: clang/lib/Sema/SemaExprCXX.cpp:5620
+std::string Spelling = "'" + std::string(getTraitSpelling(BTT)) + "'";
+return Self.Diag(KeyLoc, diag::err_reserved_identifier_for_future_use) << 
Spelling;
+  }

This is my only problem with this... we shouldn't have to do this magic to get 
this to work.  The diagnostic should have the quote in it, OR we should just 
pass an identifier (which, IIRC, ensures we wrap it in quotes anyway).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary`

2023-02-10 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

In D135341#4111884 , @cjdb wrote:

> In D135341#4111673 , @ldionne wrote:
>
>> I've been looking at implementing `reference_constructs_from_temporary` & 
>> friends and this would be sweet to have. Is this blocked on something 
>> specific?
>
> This trait should be ready to go, pending an LGTM. 
> `__reference_converts_from_temporary` is a different story, and someone else 
> might need to do this one if you need it in a timely fashion (but I'll be 
> happy to review it).

Sounds good! This naively looks good to me, but it would be nice if a Clang 
regular could take a look!




Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:397
+def err_reserved_identifier_for_future_use : Error<
+  "%0 is a compiler-reserved identifier for a future feature">;
 }

cjdb wrote:
> ldionne wrote:
> > cjdb wrote:
> > > erichkeane wrote:
> > > > I don't think we should diagnose this for individual identifiers, I 
> > > > don't think this adds much value, and the identifier is already 
> > > > reserved for implementation use.  This implies we are going to diagnose 
> > > > ALL future reserved things, which we have no intention of doing.
> > > The motivation for this error is to ensure that standard library 
> > > implementations don't take this name (`__remove_cvref` and 
> > > `__is_null_pointer` had to get names that weren't a 1:1 mapping to their 
> > > library counterparts as a result).
> > Oh, just ask and we can rename ours! What do you want us to rename?
> Much appreciated! I think `__remove_cvref` had a libc++ conflict and 
> `__is_null_pointer` had a libstdc++ conflict, so it's not specific to one 
> library. I figured that it would be easier for backwards-compatibility 
> reasons to just rename them to something slightly more awkward, so that 
> previous versions of the stdlib don't spontaneously break for more recent 
> compilers. This is more of an issue when you're dealing with package managers 
> like apt, where some things depend on libc++-v$OLD, but there aren't any 
> restrictions on Clang's version (for example, I use nightly Clang on Ubuntu, 
> but apt notes that the Discord app has an older libc++ dependency).
> 
> After having let this sit for a few months, I don't really have strong 
> opinions on reserving `__std_trait` anymore, so I'll touch this up in the 
> morning.
I just checked and I think we define `__remove_cvref_t`, but not 
`__remove_cvref` (that probably changed in the last year). In the future, don't 
hesitate to ping us if we are using a name that Clang would like to use, we 
should almost always be able to quickly get out of your way!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary`

2023-02-07 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

In D135341#4111673 , @ldionne wrote:

> I've been looking at implementing `reference_constructs_from_temporary` & 
> friends and this would be sweet to have. Is this blocked on something 
> specific?

This trait should be ready to go, pending an LGTM. 
`__reference_converts_from_temporary` is a different story, and someone else 
might need to do this one if you need it in a timely fashion (but I'll be happy 
to review it).




Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:397
+def err_reserved_identifier_for_future_use : Error<
+  "%0 is a compiler-reserved identifier for a future feature">;
 }

ldionne wrote:
> cjdb wrote:
> > erichkeane wrote:
> > > I don't think we should diagnose this for individual identifiers, I don't 
> > > think this adds much value, and the identifier is already reserved for 
> > > implementation use.  This implies we are going to diagnose ALL future 
> > > reserved things, which we have no intention of doing.
> > The motivation for this error is to ensure that standard library 
> > implementations don't take this name (`__remove_cvref` and 
> > `__is_null_pointer` had to get names that weren't a 1:1 mapping to their 
> > library counterparts as a result).
> Oh, just ask and we can rename ours! What do you want us to rename?
Much appreciated! I think `__remove_cvref` had a libc++ conflict and 
`__is_null_pointer` had a libstdc++ conflict, so it's not specific to one 
library. I figured that it would be easier for backwards-compatibility reasons 
to just rename them to something slightly more awkward, so that previous 
versions of the stdlib don't spontaneously break for more recent compilers. 
This is more of an issue when you're dealing with package managers like apt, 
where some things depend on libc++-v$OLD, but there aren't any restrictions on 
Clang's version (for example, I use nightly Clang on Ubuntu, but apt notes that 
the Discord app has an older libc++ dependency).

After having let this sit for a few months, I don't really have strong opinions 
on reserving `__std_trait` anymore, so I'll touch this up in the morning.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary`

2023-02-07 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

I've been looking at implementing `reference_constructs_from_temporary` & 
friends and this would be sweet to have. Is this blocked on something specific?




Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:397
+def err_reserved_identifier_for_future_use : Error<
+  "%0 is a compiler-reserved identifier for a future feature">;
 }

cjdb wrote:
> erichkeane wrote:
> > I don't think we should diagnose this for individual identifiers, I don't 
> > think this adds much value, and the identifier is already reserved for 
> > implementation use.  This implies we are going to diagnose ALL future 
> > reserved things, which we have no intention of doing.
> The motivation for this error is to ensure that standard library 
> implementations don't take this name (`__remove_cvref` and 
> `__is_null_pointer` had to get names that weren't a 1:1 mapping to their 
> library counterparts as a result).
Oh, just ask and we can rename ours! What do you want us to rename?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary`

2022-10-11 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:1476
   is false. Note this trait will also return false when the initialization of
   ``T`` from ``U`` is ill-formed.
+* ``__reference_constructs_from_temporary(T, U)`` (C++)

royjacobson wrote:
> We should deprecate this, as `__reference_constructs_from_temporary` is 
> implemented now. There's a list of deprecated builtins in 
> SemaExprCXX.cpp:DiagnoseBuiltinDeprecation so I think it should be pretty 
> easy to add a warning for users that this is a non-standard attribute.
Though for the CI's sake maybe it's better to wait until after libcxx stop 
using it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary`

2022-10-10 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:1476
   is false. Note this trait will also return false when the initialization of
   ``T`` from ``U`` is ill-formed.
+* ``__reference_constructs_from_temporary(T, U)`` (C++)

We should deprecate this, as `__reference_constructs_from_temporary` is 
implemented now. There's a list of deprecated builtins in 
SemaExprCXX.cpp:DiagnoseBuiltinDeprecation so I think it should be pretty easy 
to add a warning for users that this is a non-standard attribute.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary`

2022-10-10 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:397
+def err_reserved_identifier_for_future_use : Error<
+  "%0 is a compiler-reserved identifier for a future feature">;
 }

erichkeane wrote:
> I don't think we should diagnose this for individual identifiers, I don't 
> think this adds much value, and the identifier is already reserved for 
> implementation use.  This implies we are going to diagnose ALL future 
> reserved things, which we have no intention of doing.
The motivation for this error is to ensure that standard library 
implementations don't take this name (`__remove_cvref` and `__is_null_pointer` 
had to get names that weren't a 1:1 mapping to their library counterparts as a 
result).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary`

2022-10-10 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticCommonKinds.td:397
+def err_reserved_identifier_for_future_use : Error<
+  "%0 is a compiler-reserved identifier for a future feature">;
 }

I don't think we should diagnose this for individual identifiers, I don't think 
this adds much value, and the identifier is already reserved for implementation 
use.  This implies we are going to diagnose ALL future reserved things, which 
we have no intention of doing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary`

2022-10-08 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 466318.
cjdb retitled this revision from "[clang] adds 
`__reference_constructs_from_temporary` and 
`__reference_converts_from_temporary`" to "[clang] adds 
`__reference_constructs_from_temporary`".
cjdb added a comment.

discards work on `__reference_converts_from_temporary` for now. This feature 
isn't as trivial to implement as `__reference_constructs_from_temporary`, so 
it's deserving of its own commit. The two features are used exclusively, so 
it's not like adding one without the other will lead to an incomplete standard 
type.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1419,10 +1419,9 @@
   https://wg21.link/P2255R2;>P2255R2
   
 Partial
-  Clang provides a __reference_binds_to_temporary type trait
-  builtin, with which the library facility can be partially implemented.
-  Both __reference_constructs_from_temporary and
-  __reference_converts_from_temporary builtins should be
+  Clang provides __reference_constructs_from_temporary type
+  trait builtin, with which std::reference_constructs_from_temporary
+  implemented. __reference_converts_from_temporary needs to be
   provided, following the normal cross-vendor convention to implement
   traits requiring compiler support directly.
 
Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -2535,6 +2535,55 @@
   { int arr[T((__reference_binds_to_temporary(const int &, long)))]; }
 }
 
+void reference_constructs_from_temporary_checks() {
+  static_assert(!__reference_constructs_from_temporary(int &, int &), "");
+  static_assert(!__reference_constructs_from_temporary(int &, int &&), "");
+
+  static_assert(!__reference_constructs_from_temporary(int const &, int &), "");
+  static_assert(!__reference_constructs_from_temporary(int const &, int const &), "");
+  static_assert(!__reference_constructs_from_temporary(int const &, int &&), "");
+
+  static_assert(!__reference_constructs_from_temporary(int &, long &), ""); // doesn't construct
+
+  static_assert(__reference_constructs_from_temporary(int const &, long &), "");
+  static_assert(__reference_constructs_from_temporary(int const &, long &&), "");
+  static_assert(__reference_constructs_from_temporary(int &&, long &), "");
+
+  using LRef = ConvertsToRef;
+  using RRef = ConvertsToRef;
+  using CLRef = ConvertsToRef;
+  using LongRef = ConvertsToRef;
+  static_assert(__is_constructible(int &, LRef), "");
+  static_assert(!__reference_constructs_from_temporary(int &, LRef), "");
+
+  static_assert(__is_constructible(int &&, RRef), "");
+  static_assert(!__reference_constructs_from_temporary(int &&, RRef), "");
+
+  static_assert(__is_constructible(int const &, CLRef), "");
+  static_assert(!__reference_constructs_from_temporary(int &&, CLRef), "");
+
+  static_assert(__is_constructible(int const &, LongRef), "");
+  static_assert(__reference_constructs_from_temporary(int const &, LongRef), "");
+
+  // Test that it doesn't accept non-reference types as input.
+  static_assert(!__reference_constructs_from_temporary(int, long), "");
+
+  static_assert(__reference_constructs_from_temporary(const int &, long), "");
+
+  // Additional checks
+  static_assert(__reference_constructs_from_temporary(POD const&, Derives), "");
+  static_assert(__reference_constructs_from_temporary(int&&, int), "");
+  static_assert(__reference_constructs_from_temporary(const int&, int), "");
+  static_assert(!__reference_constructs_from_temporary(int&&, int&&), "");
+  static_assert(!__reference_constructs_from_temporary(const int&, int&&), "");
+  static_assert(__reference_constructs_from_temporary(int&&, long&&), "");
+  static_assert(__reference_constructs_from_temporary(int&&, long), "");
+}
+
+void reference_converts_from_temporary() {
+  (void)__reference_converts_from_temporary(int, int); // expected-error{{'__reference_converts_from_temporary' is a compiler-reserved identifier for a future feature}}
+}
+
 void array_rank() {
   int t01[T(__array_rank(IntAr) == 1)];
   int t02[T(__array_rank(ConstIntArAr) == 2)];
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -29,6 +29,7 

[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary` and `__reference_converts_from_temporary`

2022-10-07 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb updated this revision to Diff 466088.
cjdb added a comment.

Gets `__reference_constructs_from_temporary` correct. Still WIP for the latter.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1417,16 +1417,7 @@
 
   Type trait to determine if a reference binds to a temporary
   https://wg21.link/P2255R2;>P2255R2
-  
-Partial
-  Clang provides a __reference_binds_to_temporary type trait
-  builtin, with which the library facility can be partially implemented.
-  Both __reference_constructs_from_temporary and
-  __reference_converts_from_temporary builtins should be
-  provided, following the normal cross-vendor convention to implement
-  traits requiring compiler support directly.
-
-  
+  Clang 16
 
 
 
Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -4704,6 +4704,96 @@
   { int arr[T((__reference_binds_to_temporary(const int &, long)))]; }
 }
 
+void reference_constructs_from_temporary_checks() {
+  static_assert(!__reference_constructs_from_temporary(int &, int &), "");
+  static_assert(!__reference_constructs_from_temporary(int &, int &&), "");
+
+  static_assert(!__reference_constructs_from_temporary(int const &, int &), "");
+  static_assert(!__reference_constructs_from_temporary(int const &, int const &), "");
+  static_assert(!__reference_constructs_from_temporary(int const &, int &&), "");
+
+  static_assert(!__reference_constructs_from_temporary(int &, long &), ""); // doesn't construct
+
+  static_assert(__reference_constructs_from_temporary(int const &, long &), "");
+  static_assert(__reference_constructs_from_temporary(int const &, long &&), "");
+  static_assert(__reference_constructs_from_temporary(int &&, long &), "");
+
+  using LRef = ConvertsToRef;
+  using RRef = ConvertsToRef;
+  using CLRef = ConvertsToRef;
+  using LongRef = ConvertsToRef;
+  static_assert(__is_constructible(int &, LRef), "");
+  static_assert(!__reference_constructs_from_temporary(int &, LRef), "");
+
+  static_assert(__is_constructible(int &&, RRef), "");
+  static_assert(!__reference_constructs_from_temporary(int &&, RRef), "");
+
+  static_assert(__is_constructible(int const &, CLRef), "");
+  static_assert(!__reference_constructs_from_temporary(int &&, CLRef), "");
+
+  static_assert(__is_constructible(int const &, LongRef), "");
+  static_assert(__reference_constructs_from_temporary(int const &, LongRef), "");
+
+  // Test that it doesn't accept non-reference types as input.
+  static_assert(!__reference_constructs_from_temporary(int, long), "");
+
+  static_assert(__reference_constructs_from_temporary(const int &, long), "");
+
+  // Additional checks
+  static_assert(__reference_constructs_from_temporary(POD const&, Derives), "");
+  static_assert(__reference_constructs_from_temporary(int&&, int), "");
+  static_assert(__reference_constructs_from_temporary(const int&, int), "");
+  static_assert(!__reference_constructs_from_temporary(int&&, int&&), "");
+  static_assert(!__reference_constructs_from_temporary(const int&, int&&), "");
+  static_assert(__reference_constructs_from_temporary(int&&, long&&), "");
+  static_assert(__reference_constructs_from_temporary(int&&, long), "");
+}
+
+void reference_converts_from_temporary_checks() {
+  static_assert(!__reference_converts_from_temporary(int &, int &), "");
+  static_assert(!__reference_converts_from_temporary(int &, int &&), "");
+
+  static_assert(!__reference_converts_from_temporary(int const &, int &), "");
+  static_assert(!__reference_converts_from_temporary(int const &, int const &), "");
+  static_assert(!__reference_converts_from_temporary(int const &, int &&), "");
+
+  static_assert(!__reference_converts_from_temporary(int &, long &), ""); // doesn't construct
+
+  static_assert(__reference_converts_from_temporary(int const &, long &), "");
+  static_assert(__reference_converts_from_temporary(int const &, long &&), "");
+  static_assert(__reference_converts_from_temporary(int &&, long &), "");
+
+  using LRef = ConvertsToRef;
+  using RRef = ConvertsToRef;
+  using CLRef = ConvertsToRef;
+  using LongRef = ConvertsToRef;
+  static_assert(__is_convertible(LRef, int &), "");
+  static_assert(!__reference_converts_from_temporary(int &, LRef), "");
+
+  

[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary` and `__reference_converts_from_temporary`

2022-10-06 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

In D135341#3841126 , @ldionne wrote:

> Interesting, I actually wasn't even aware of that C++23 feature in the 
> library. FWIW, libc++ will be more than happy to use that builtin instead of 
> trying to figure it out inside the library (if that's even possible)! We'll 
> have to check whether GCC implements it, but hopefully it has something 
> similar. So this definitely LGTM from the libc++ side of things, assuming the 
> Clang folks are happy with the implementation.

It's possible to easily implement `reference_constructs_from_temporary` in the 
library, but the converts one is far more tricky because 
`__reference_binds_to_temporary` only cares about construction. I don't know if 
GCC implements it (I thought it did, but I can't find the commit in a trivial 
Google search), but I did learn that libstdc++ has a guard for this name.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary` and `__reference_converts_from_temporary`

2022-10-06 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

Interesting, I actually wasn't even aware of that C++23 feature in the library. 
FWIW, libc++ will be more than happy to use that builtin instead of trying to 
figure it out inside the library (if that's even possible)! We'll have to check 
whether GCC implements it, but hopefully it has something similar. So this 
definitely LGTM from the libc++ side of things, assuming the Clang folks are 
happy with the implementation.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary` and `__reference_converts_from_temporary`

2022-10-06 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb planned changes to this revision.
cjdb added a comment.

I learnt last night that this one is incredibly wrong and needs revising.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135341/new/

https://reviews.llvm.org/D135341

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary` and `__reference_converts_from_temporary`

2022-10-05 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb created this revision.
cjdb added reviewers: aaron.ballman, shafik, erichkeane, tcanens.
Herald added a project: All.
cjdb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

Depends on D135339 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135341

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1417,16 +1417,7 @@
 
   Type trait to determine if a reference binds to a temporary
   https://wg21.link/P2255R2;>P2255R2
-  
-Partial
-  Clang provides a __reference_binds_to_temporary type trait
-  builtin, with which the library facility can be partially implemented.
-  Both __reference_constructs_from_temporary and
-  __reference_converts_from_temporary builtins should be
-  provided, following the normal cross-vendor convention to implement
-  traits requiring compiler support directly.
-
-  
+  Clang 16
 
 
 
Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -4704,6 +4704,92 @@
   { int arr[T((__reference_binds_to_temporary(const int &, long)))]; }
 }
 
+void reference_constructs_from_temporary_checks() {
+  static_assert(!__reference_constructs_from_temporary(int &, int &), "");
+  static_assert(!__reference_constructs_from_temporary(int &, int &&), "");
+
+  static_assert(!__reference_constructs_from_temporary(int const &, int &), "");
+  static_assert(!__reference_constructs_from_temporary(int const &, int const &), "");
+  static_assert(!__reference_constructs_from_temporary(int const &, int &&), "");
+
+  static_assert(!__reference_constructs_from_temporary(int &, long &), ""); // doesn't construct
+
+  // Diverges from __reference_binds_to_temporary
+  static_assert(!__reference_constructs_from_temporary(int const &, long &), "");
+  // Diverges from __reference_binds_to_temporary
+  static_assert(!__reference_constructs_from_temporary(int const &, long &&), "");
+  // Diverges from __reference_binds_to_temporary
+  static_assert(!__reference_constructs_from_temporary(int &&, long &), "");
+
+  using LRef = ConvertsToRef;
+  using RRef = ConvertsToRef;
+  using CLRef = ConvertsToRef;
+  using LongRef = ConvertsToRef;
+  static_assert(__is_constructible(int &, LRef), "");
+  static_assert(!__reference_constructs_from_temporary(int &, LRef), "");
+
+  static_assert(__is_constructible(int &&, RRef), "");
+  static_assert(!__reference_constructs_from_temporary(int &&, RRef), "");
+
+  static_assert(__is_constructible(int const &, CLRef), "");
+  static_assert(!__reference_constructs_from_temporary(int &&, CLRef), "");
+
+  static_assert(__is_constructible(int const &, LongRef), "");
+  static_assert(!__reference_constructs_from_temporary(int const &, LongRef), "");
+
+  // Test that it doesn't accept non-reference types as input.
+  static_assert(!__reference_constructs_from_temporary(int, long), "");
+
+  static_assert(!__reference_constructs_from_temporary(const int &, long), "");
+
+  // Additional checks
+  static_assert(__reference_constructs_from_temporary(int&&, int), "");
+  static_assert(__reference_constructs_from_temporary(POD const&, Derives), "");
+}
+
+void reference_converts_from_temporary_checks() {
+  static_assert(!__reference_converts_from_temporary(int &, int &), "");
+  static_assert(!__reference_converts_from_temporary(int &, int &&), "");
+
+  static_assert(!__reference_converts_from_temporary(int const &, int &), "");
+  static_assert(!__reference_converts_from_temporary(int const &, int const &), "");
+  static_assert(!__reference_converts_from_temporary(int const &, int &&), "");
+
+  static_assert(!__reference_converts_from_temporary(int &, long &), ""); // doesn't construct
+
+  // Diverges from __reference_binds_to_temporary
+  static_assert(!__reference_converts_from_temporary(int const &, long &), "");
+  // Diverges from __reference_binds_to_temporary
+  static_assert(!__reference_converts_from_temporary(int const &, long &&), "");
+  // Diverges from __reference_binds_to_temporary
+  static_assert(!__reference_converts_from_temporary(int &&, long &), "");
+
+  using LRef = ConvertsToRef;
+  using RRef = ConvertsToRef;
+  using CLRef = ConvertsToRef;
+  using LongRef =