[libcxx] r338479 - [libc++][C++17] Elementary string conversions for integral types

2018-07-31 Thread Zhihao Yuan via cfe-commits
Author: lichray
Date: Tue Jul 31 19:38:30 2018
New Revision: 338479

URL: http://llvm.org/viewvc/llvm-project?rev=338479&view=rev
Log:
[libc++][C++17] Elementary string conversions for integral types

Summary:
Major QoI considerations:

- The facility is backported to C++14, same as libstdc++.
- Efforts have been made to minimize the header dependencies.
- The design is friendly to the uses of MSVC intrinsics (`__emulu`, `_umul128`, 
`_BitScanForward`, `_BitScanForward64`) but not implemented; future 
contributions are welcome.

Thanks to Milo Yip for contributing the implementation of `__u64toa` and 
`__u32toa`.

References:
 https://wg21.link/p0067r5
 https://wg21.link/p0682r1

Reviewers: mclow.lists, EricWF

Reviewed By: mclow.lists

Subscribers: ldionne, Quuxplusone, christof, mgorny, cfe-commits

Differential Revision: https://reviews.llvm.org/D41458

Added:
libcxx/trunk/include/charconv
libcxx/trunk/src/charconv.cpp
libcxx/trunk/test/std/utilities/charconv/
libcxx/trunk/test/std/utilities/charconv/charconv.from.chars/

libcxx/trunk/test/std/utilities/charconv/charconv.from.chars/integral.bool.fail.cpp

libcxx/trunk/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp
libcxx/trunk/test/std/utilities/charconv/charconv.to.chars/

libcxx/trunk/test/std/utilities/charconv/charconv.to.chars/integral.bool.fail.cpp
libcxx/trunk/test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp
libcxx/trunk/test/support/charconv_test_helpers.h
Modified:
libcxx/trunk/include/CMakeLists.txt
libcxx/trunk/include/module.modulemap
libcxx/trunk/test/libcxx/double_include.sh.cpp

Modified: libcxx/trunk/include/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/CMakeLists.txt?rev=338479&r1=338478&r2=338479&view=diff
==
--- libcxx/trunk/include/CMakeLists.txt (original)
+++ libcxx/trunk/include/CMakeLists.txt Tue Jul 31 19:38:30 2018
@@ -32,6 +32,7 @@ set(files
   cerrno
   cfenv
   cfloat
+  charconv
   chrono
   cinttypes
   ciso646

Added: libcxx/trunk/include/charconv
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/charconv?rev=338479&view=auto
==
--- libcxx/trunk/include/charconv (added)
+++ libcxx/trunk/include/charconv Tue Jul 31 19:38:30 2018
@@ -0,0 +1,610 @@
+// -*- C++ -*-
+//===-- charconv 
--===//
+//
+// 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.
+//
+//===--===//
+
+#ifndef _LIBCPP_CHARCONV
+#define _LIBCPP_CHARCONV
+
+/*
+charconv synopsis
+
+namespace std {
+
+  // floating-point format for primitive numerical conversion
+  enum class chars_format {
+scientific = unspecified,
+fixed = unspecified,
+hex = unspecified,
+general = fixed | scientific
+  };
+
+  // 23.20.2, primitive numerical output conversion
+  struct to_chars_result {
+char* ptr;
+errc ec;
+  };
+
+  to_chars_result to_chars(char* first, char* last, see below value,
+   int base = 10);
+
+  to_chars_result to_chars(char* first, char* last, float value);
+  to_chars_result to_chars(char* first, char* last, double value);
+  to_chars_result to_chars(char* first, char* last, long double value);
+
+  to_chars_result to_chars(char* first, char* last, float value,
+   chars_format fmt);
+  to_chars_result to_chars(char* first, char* last, double value,
+   chars_format fmt);
+  to_chars_result to_chars(char* first, char* last, long double value,
+   chars_format fmt);
+
+  to_chars_result to_chars(char* first, char* last, float value,
+   chars_format fmt, int precision);
+  to_chars_result to_chars(char* first, char* last, double value,
+   chars_format fmt, int precision);
+  to_chars_result to_chars(char* first, char* last, long double value,
+   chars_format fmt, int precision);
+
+  // 23.20.3, primitive numerical input conversion
+  struct from_chars_result {
+const char* ptr;
+errc ec;
+  };
+
+  from_chars_result from_chars(const char* first, const char* last,
+   see below& value, int base = 10);
+
+  from_chars_result from_chars(const char* first, const char* last,
+   float& value,
+   chars_format fmt = chars_format::general);
+  from_chars_result from_chars(const char* first, const char* last,
+   double& value,
+   chars_format fmt = chars_format::general);
+  from_chars_resu

[libcxx] r338486 - [libc++] Fix build failures after merging

2018-07-31 Thread Zhihao Yuan via cfe-commits
Author: lichray
Date: Tue Jul 31 22:21:26 2018
New Revision: 338486

URL: http://llvm.org/viewvc/llvm-project?rev=338486&view=rev
Log:
[libc++] Fix build failures after merging 

Summary:
- fix a stupid unit test typo
- add  symbols to Linux abilist

Reviewers: EricWF

Subscribers: christof, ldionne, cfe-commits

Differential Revision: https://reviews.llvm.org/D50130

Modified:
libcxx/trunk/lib/abi/x86_64-unknown-linux-gnu.v1.abilist

libcxx/trunk/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp
libcxx/trunk/test/support/charconv_test_helpers.h

Modified: libcxx/trunk/lib/abi/x86_64-unknown-linux-gnu.v1.abilist
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/lib/abi/x86_64-unknown-linux-gnu.v1.abilist?rev=338486&r1=338485&r2=338486&view=diff
==
--- libcxx/trunk/lib/abi/x86_64-unknown-linux-gnu.v1.abilist (original)
+++ libcxx/trunk/lib/abi/x86_64-unknown-linux-gnu.v1.abilist Tue Jul 31 
22:21:26 2018
@@ -1192,6 +1192,8 @@
 {'name': '_ZNSt3__15wclogE', 'is_defined': True, 'type': 'OBJECT', 'size': 160}
 {'name': '_ZNSt3__15wcoutE', 'is_defined': True, 'type': 'OBJECT', 'size': 160}
 {'name': '_ZNSt3__16__clocEv', 'is_defined': True, 'type': 'FUNC'}
+{'name': '_ZNSt3__16__itoa8__u64toaEmPc', 'is_defined': True, 'type': 'FUNC'}
+{'name': '_ZNSt3__16__itoa8__u32toaEjPc', 'is_defined': True, 'type': 'FUNC'}
 {'name': '_ZNSt3__16__sortIRNS_6__lessIaaEEPaEEvT0_S5_T_', 'is_defined': True, 
'type': 'FUNC'}
 {'name': '_ZNSt3__16__sortIRNS_6__lessIccEEPcEEvT0_S5_T_', 'is_defined': True, 
'type': 'FUNC'}
 {'name': '_ZNSt3__16__sortIRNS_6__lessIddEEPdEEvT0_S5_T_', 'is_defined': True, 
'type': 'FUNC'}

Modified: 
libcxx/trunk/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp?rev=338486&r1=338485&r2=338486&view=diff
==
--- 
libcxx/trunk/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp 
Tue Jul 31 22:21:26 2018
@@ -37,6 +37,7 @@ struct test_basics : roundtrip_test_base
 using xl = std::numeric_limits;
 
 test(1, b);
+test(-1, b);
 test(xl::lowest(), b);
 test((xl::max)(), b);
 test((xl::max)() / 2, b);

Modified: libcxx/trunk/test/support/charconv_test_helpers.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/charconv_test_helpers.h?rev=338486&r1=338485&r2=338486&view=diff
==
--- libcxx/trunk/test/support/charconv_test_helpers.h (original)
+++ libcxx/trunk/test/support/charconv_test_helpers.h Tue Jul 31 22:21:26 2018
@@ -178,7 +178,7 @@ struct roundtrip_test_base
 {
 assert(x == 0xc);
 assert(r2.ptr == buf);
-assert(r.ec == std::errc::invalid_argument);
+assert(r2.ec == std::errc::invalid_argument);
 }
 else
 {


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


r327780 - Fix codegen for structured binding binding in conditions

2018-03-17 Thread Zhihao Yuan via cfe-commits
Author: lichray
Date: Sat Mar 17 14:01:27 2018
New Revision: 327780

URL: http://llvm.org/viewvc/llvm-project?rev=327780&view=rev
Log:
Fix codegen for structured binding binding in conditions

Summary:
The codegen for conditions assumes that a normal variable declaration is used 
in a condition, but this is not the case when a structured binding is used.

This fixes [PR36747](http://llvm.org/pr36747).

Thanks Nicolas Lesser for contributing the patch.

Reviewers: lichray, rsmith

Reviewed By: lichray

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D44534

Modified:
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/test/Parser/decomposed-condition.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=327780&r1=327779&r2=327780&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Sat Mar 17 14:01:27 2018
@@ -608,7 +608,7 @@ void CodeGenFunction::EmitIfStmt(const I
 EmitStmt(S.getInit());
 
   if (S.getConditionVariable())
-EmitAutoVarDecl(*S.getConditionVariable());
+EmitDecl(*S.getConditionVariable());
 
   // If the condition constant folds and can be elided, try to avoid emitting
   // the condition and the dead arm of the if/else.
@@ -705,7 +705,7 @@ void CodeGenFunction::EmitWhileStmt(cons
   RunCleanupsScope ConditionScope(*this);
 
   if (S.getConditionVariable())
-EmitAutoVarDecl(*S.getConditionVariable());
+EmitDecl(*S.getConditionVariable());
 
   // Evaluate the conditional in the while header.  C99 6.8.5.1: The
   // evaluation of the controlling expression takes place before each
@@ -865,7 +865,7 @@ void CodeGenFunction::EmitForStmt(const
 // If the for statement has a condition scope, emit the local variable
 // declaration.
 if (S.getConditionVariable()) {
-  EmitAutoVarDecl(*S.getConditionVariable());
+  EmitDecl(*S.getConditionVariable());
 }
 
 llvm::BasicBlock *ExitBlock = LoopExit.getBlock();
@@ -1574,7 +1574,7 @@ void CodeGenFunction::EmitSwitchStmt(con
   // Emit the condition variable if needed inside the entire cleanup scope
   // used by this special case for constant folded switches.
   if (S.getConditionVariable())
-EmitAutoVarDecl(*S.getConditionVariable());
+EmitDecl(*S.getConditionVariable());
 
   // At this point, we are no longer "within" a switch instance, so
   // we can temporarily enforce this to ensure that any embedded case
@@ -1603,7 +1603,7 @@ void CodeGenFunction::EmitSwitchStmt(con
 EmitStmt(S.getInit());
 
   if (S.getConditionVariable())
-EmitAutoVarDecl(*S.getConditionVariable());
+EmitDecl(*S.getConditionVariable());
   llvm::Value *CondV = EmitScalarExpr(S.getCond());
 
   // Create basic block to hold stuff that comes after switch

Modified: cfe/trunk/test/Parser/decomposed-condition.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/decomposed-condition.cpp?rev=327780&r1=327779&r2=327780&view=diff
==
--- cfe/trunk/test/Parser/decomposed-condition.cpp (original)
+++ cfe/trunk/test/Parser/decomposed-condition.cpp Sat Mar 17 14:01:27 2018
@@ -1,5 +1,20 @@
 // RUN: %clang_cc1 -std=c++1z %s -verify
 
+namespace std {
+  template struct tuple_size;
+  template struct tuple_element;
+}
+
+struct Get {
+  template int get() { return 0; }
+  operator bool() { return true; }
+};
+
+namespace std {
+  template<> struct tuple_size { static constexpr int value = 1; };
+  template<> struct tuple_element<0, Get> { using type = int; };
+}
+
 struct Na {
   bool flag;
   float data;
@@ -17,29 +32,35 @@ Rst f();
 Na g();
 
 namespace CondInIf {
-void h() {
+int h() {
   if (auto [ok, d] = f()) // expected-warning {{ISO C++17 does not permit 
structured binding declaration in a condition}}
 ;
   if (auto [ok, d] = g()) // expected-warning {{ISO C++17 does not permit 
structured binding declaration in a condition}} expected-error {{value of type 
'Na' is not contextually convertible to 'bool'}}
 ;
+  if (auto [value] = Get()) // expected-warning {{ISO C++17 does not permit 
structured binding declaration in a condition}}
+return value;
 }
 } // namespace CondInIf
 
 namespace CondInWhile {
-void h() {
+int h() {
   while (auto [ok, d] = f()) // expected-warning {{ISO C++17 does not permit 
structured binding declaration in a condition}}
 ;
   while (auto [ok, d] = g()) // expected-warning {{ISO C++17 does not permit 
structured binding declaration in a condition}} expected-error {{value of type 
'Na' is not contextually convertible to 'bool'}}
 ;
+  while (auto [value] = Get()) // expected-warning{{ISO C++17 does not permit 
structured binding declaration in a condition}}
+return value;
 }
 } // namespace CondInWhile
 
 namespace CondInFo

r327782 - [C++17] Allow an empty expression in an if init statement

2018-03-17 Thread Zhihao Yuan via cfe-commits
Author: lichray
Date: Sat Mar 17 14:42:10 2018
New Revision: 327782

URL: http://llvm.org/viewvc/llvm-project?rev=327782&view=rev
Log:
[C++17] Allow an empty expression in an if init statement

Summary:
This fixes [PR35381](https://llvm.org/pr35381) and an additional bug where 
clang didn't warn about the C++17 extension when having an expression in the 
init statement.

Thanks Nicolas Lesser for contributing the patch.

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: erik.pilkington, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D40445

Modified:
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/test/CXX/stmt.stmt/stmt.select/p3.cpp

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=327782&r1=327781&r2=327782&view=diff
==
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Sat Mar 17 14:42:10 2018
@@ -1744,17 +1744,34 @@ Sema::ConditionResult Parser::ParseCXXCo
   ParsedAttributesWithRange attrs(AttrFactory);
   MaybeParseCXX11Attributes(attrs);
 
+  const auto WarnOnInit = [this, &CK] {
+Diag(Tok.getLocation(), getLangOpts().CPlusPlus17
+? diag::warn_cxx14_compat_init_statement
+: diag::ext_init_statement)
+<< (CK == Sema::ConditionKind::Switch);
+  };
+
   // Determine what kind of thing we have.
   switch (isCXXConditionDeclarationOrInitStatement(InitStmt)) {
   case ConditionOrInitStatement::Expression: {
 ProhibitAttributes(attrs);
 
+// We can have an empty expression here.
+//   if (; true);
+if (InitStmt && Tok.is(tok::semi)) {
+  WarnOnInit();
+  SourceLocation SemiLoc = ConsumeToken();
+  *InitStmt = Actions.ActOnNullStmt(SemiLoc);
+  return ParseCXXCondition(nullptr, Loc, CK);
+}
+
 // Parse the expression.
 ExprResult Expr = ParseExpression(); // expression
 if (Expr.isInvalid())
   return Sema::ConditionError();
 
 if (InitStmt && Tok.is(tok::semi)) {
+  WarnOnInit();
   *InitStmt = Actions.ActOnExprStmt(Expr.get());
   ConsumeToken();
   return ParseCXXCondition(nullptr, Loc, CK);
@@ -1764,10 +1781,7 @@ Sema::ConditionResult Parser::ParseCXXCo
   }
 
   case ConditionOrInitStatement::InitStmtDecl: {
-Diag(Tok.getLocation(), getLangOpts().CPlusPlus17
-? diag::warn_cxx14_compat_init_statement
-: diag::ext_init_statement)
-<< (CK == Sema::ConditionKind::Switch);
+WarnOnInit();
 SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
 DeclGroupPtrTy DG =
 ParseSimpleDeclaration(DeclaratorContext::InitStmtContext, DeclEnd,

Modified: cfe/trunk/test/CXX/stmt.stmt/stmt.select/p3.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/stmt.stmt/stmt.select/p3.cpp?rev=327782&r1=327781&r2=327782&view=diff
==
--- cfe/trunk/test/CXX/stmt.stmt/stmt.select/p3.cpp (original)
+++ cfe/trunk/test/CXX/stmt.stmt/stmt.select/p3.cpp Sat Mar 17 14:42:10 2018
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++1z -Wc++14-compat -verify %s -DCPP17
 
 int f();
 
@@ -10,10 +11,67 @@ void g() {
   }
 }
 
-
 void h() {
   if (int x = f()) // expected-note 2{{previous definition}}
 int x; // expected-error{{redefinition of 'x'}}
   else
 int x; // expected-error{{redefinition of 'x'}}
 }
+
+void ifInitStatement() {
+  int Var = 0;
+
+  if (int I = 0; true) {}
+  if (Var + Var; true) {}
+  if (; true) {}
+#ifdef CPP17
+  // expected-warning@-4 {{if initialization statements are incompatible with 
C++ standards before C++17}}
+  // expected-warning@-4 {{if initialization statements are incompatible with 
C++ standards before C++17}}
+  // expected-warning@-4 {{if initialization statements are incompatible with 
C++ standards before C++17}}
+#else
+  // expected-warning@-8 {{'if' initialization statements are a C++17 
extension}}
+  // expected-warning@-8 {{'if' initialization statements are a C++17 
extension}}
+  // expected-warning@-8 {{'if' initialization statements are a C++17 
extension}}
+#endif
+}
+
+void switchInitStatement() {
+  int Var = 0;
+
+  switch (int I = 0; Var) {}
+  switch (Var + Var; Var) {}
+  switch (; Var) {}
+#ifdef CPP17
+  // expected-warning@-4 {{switch initialization statements are incompatible 
with C++ standards before C++17}}
+  // expected-warning@-4 {{switch initialization statements are incompatible 
with C++ standards before C++17}}
+  // expected-warning@-4 {{switch initialization statements are incompatible 
with C++ standards before C++17}}
+#else
+  // expected-warning@-8 {{'switch' initialization statements are a C++17 
extension}}
+  // expected-warning@-8 {{'switch' ini

[libcxx] r336164 - [libc++] Lift std::errc into a separated header

2018-07-02 Thread Zhihao Yuan via cfe-commits
Author: lichray
Date: Mon Jul  2 20:25:10 2018
New Revision: 336164

URL: http://llvm.org/viewvc/llvm-project?rev=336164&view=rev
Log:
[libc++] Lift std::errc into a separated header

Summary: This is needed to implement ``, otherwise `` would 
need to include ``, which pulls in `` -- a header which 
the `` proposal intends to keep away from.

Reviewers: mclow.lists, EricWF

Reviewed By: mclow.lists

Subscribers: christof, cfe-commits

Differential Revision: https://reviews.llvm.org/D41347

Added:
libcxx/trunk/include/__errc
Modified:
libcxx/trunk/include/module.modulemap
libcxx/trunk/include/system_error

Added: libcxx/trunk/include/__errc
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__errc?rev=336164&view=auto
==
--- libcxx/trunk/include/__errc (added)
+++ libcxx/trunk/include/__errc Mon Jul  2 20:25:10 2018
@@ -0,0 +1,218 @@
+// -*- C++ -*-
+//=== __errc 
--===//
+//
+// 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.
+//
+//===--===//
+
+#ifndef _LIBCPP___ERRC
+#define _LIBCPP___ERRC
+
+/*
+system_error synopsis
+
+namespace std
+{
+
+enum class errc
+{
+address_family_not_supported,   // EAFNOSUPPORT
+address_in_use, // EADDRINUSE
+address_not_available,  // EADDRNOTAVAIL
+already_connected,  // EISCONN
+argument_list_too_long, // E2BIG
+argument_out_of_domain, // EDOM
+bad_address,// EFAULT
+bad_file_descriptor,// EBADF
+bad_message,// EBADMSG
+broken_pipe,// EPIPE
+connection_aborted, // ECONNABORTED
+connection_already_in_progress, // EALREADY
+connection_refused, // ECONNREFUSED
+connection_reset,   // ECONNRESET
+cross_device_link,  // EXDEV
+destination_address_required,   // EDESTADDRREQ
+device_or_resource_busy,// EBUSY
+directory_not_empty,// ENOTEMPTY
+executable_format_error,// ENOEXEC
+file_exists,// EEXIST
+file_too_large, // EFBIG
+filename_too_long,  // ENAMETOOLONG
+function_not_supported, // ENOSYS
+host_unreachable,   // EHOSTUNREACH
+identifier_removed, // EIDRM
+illegal_byte_sequence,  // EILSEQ
+inappropriate_io_control_operation, // ENOTTY
+interrupted,// EINTR
+invalid_argument,   // EINVAL
+invalid_seek,   // ESPIPE
+io_error,   // EIO
+is_a_directory, // EISDIR
+message_size,   // EMSGSIZE
+network_down,   // ENETDOWN
+network_reset,  // ENETRESET
+network_unreachable,// ENETUNREACH
+no_buffer_space,// ENOBUFS
+no_child_process,   // ECHILD
+no_link,// ENOLINK
+no_lock_available,  // ENOLCK
+no_message_available,   // ENODATA
+no_message, // ENOMSG
+no_protocol_option, // ENOPROTOOPT
+no_space_on_device, // ENOSPC
+no_stream_resources,// ENOSR
+no_such_device_or_address,  // ENXIO
+no_such_device, // ENODEV
+no_such_file_or_directory,  // ENOENT
+no_such_process,// ESRCH
+not_a_directory,// ENOTDIR
+not_a_socket,   // ENOTSOCK
+not_a_stream,   // ENOSTR
+not_connected,  // ENOTCONN
+not_enough_memory,  // ENOMEM
+not_supported,  // ENOTSUP
+operation_canceled, // ECANCELED
+operation_in_progress,  // EINPROGRESS
+operation_not_permitted,// EPERM
+operation_not_supported,// EOPNOTSUPP
+operation_would_block,  // EWOULDBLOCK
+owner_dead, // EOWNERDEAD
+permission_denied,  // EACCES
+protocol_error, // EPROTO
+protocol_not_supported, // EPROTONOSUPPORT
+read_only_file_system,  // EROFS
+resource_deadlock_would_occur,  // EDEADLK
+resource_unavailable_try_again, // EAGAIN
+result_out_of_range,   

[libcxx] r336165 - [libc++] Install the missing header __errc

2018-07-02 Thread Zhihao Yuan via cfe-commits
Author: lichray
Date: Mon Jul  2 21:01:44 2018
New Revision: 336165

URL: http://llvm.org/viewvc/llvm-project?rev=336165&view=rev
Log:
[libc++] Install the missing header __errc

Summary: Omitted from D41347.

Reviewers: EricWF

Subscribers: mgorny, christof, ldionne, cfe-commits

Differential Revision: https://reviews.llvm.org/D48864

Modified:
libcxx/trunk/include/CMakeLists.txt

Modified: libcxx/trunk/include/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/CMakeLists.txt?rev=336165&r1=336164&r2=336165&view=diff
==
--- libcxx/trunk/include/CMakeLists.txt (original)
+++ libcxx/trunk/include/CMakeLists.txt Mon Jul  2 21:01:44 2018
@@ -2,6 +2,7 @@ set(files
   __bit_reference
   __bsd_locale_defaults.h
   __bsd_locale_fallbacks.h
+  __errc
   __debug
   __functional_03
   __functional_base


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


r320008 - Test commit access

2017-12-06 Thread Zhihao Yuan via cfe-commits
Author: lichray
Date: Wed Dec  6 22:27:58 2017
New Revision: 320008

URL: http://llvm.org/viewvc/llvm-project?rev=320008&view=rev
Log:
Test commit access

Modified:
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=320008&r1=320007&r2=320008&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Dec  6 22:27:58 2017
@@ -4295,7 +4295,7 @@ static TypeSourceInfo *GetFullTypeForDec
   << T << D.getSourceRange();
 D.setInvalidType(true);
   } else if (D.getName().getKind() ==
- UnqualifiedId::IK_DeductionGuideName) {
+ UnqualifiedId::IK_DeductionGuideName) {
 if (T != Context.DependentTy) {
   S.Diag(D.getDeclSpec().getLocStart(),
  diag::err_deduction_guide_with_complex_decl)


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


r320011 - Allow conditions to be decomposed with structured bindings

2017-12-06 Thread Zhihao Yuan via cfe-commits
Author: lichray
Date: Wed Dec  6 23:03:15 2017
New Revision: 320011

URL: http://llvm.org/viewvc/llvm-project?rev=320011&view=rev
Log:
Allow conditions to be decomposed with structured bindings

Summary:
This feature was discussed but not yet proposed.  It allows a structured 
binding to appear as a //condition//

if (auto [ok, val] = f(...))

So the user can save an extra //condition// if the statement can test the value 
to-be-decomposed instead.  Formally, it makes the value of the underlying 
object of the structured binding declaration also the value of a //condition// 
that is an initialized declaration.

Considering its logicality which is entirely evident from its trivial 
implementation, I think it might be acceptable to land it as an extension for 
now before I write the paper.

Reviewers: rsmith, faisalv, aaron.ballman

Reviewed By: rsmith

Subscribers: aaron.ballman, cfe-commits

Differential Revision: https://reviews.llvm.org/D39284

Added:
cfe/trunk/test/Parser/decomposed-condition.cpp
cfe/trunk/test/SemaCXX/decomposed-condition.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/Parser/cxx1z-decomposition.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=320011&r1=320010&r2=320011&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Dec  6 23:03:15 
2017
@@ -414,6 +414,9 @@ def warn_cxx14_compat_decomp_decl : Warn
   "C++ standards before C++17">, DefaultIgnore, InGroup;
 def ext_decomp_decl : ExtWarn<
   "decomposition declarations are a C++17 extension">, InGroup;
+def ext_decomp_decl_cond : ExtWarn<
+  "ISO C++17 does not permit structured binding declaration in a condition">,
+  InGroup>;
 def err_decomp_decl_spec : Error<
   "decomposition declaration cannot be declared "
   "%plural{1:'%1'|:with '%1' specifiers}0">;

Modified: cfe/trunk/include/clang/Sema/DeclSpec.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=320011&r1=320010&r2=320011&view=diff
==
--- cfe/trunk/include/clang/Sema/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Sema/DeclSpec.h Wed Dec  6 23:03:15 2017
@@ -1995,9 +1995,9 @@ public:
 case BlockContext:
 case ForContext:
 case InitStmtContext:
+case ConditionContext:
   return true;
 
-case ConditionContext:
 case MemberContext:
 case PrototypeContext:
 case TemplateParamContext:

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=320011&r1=320010&r2=320011&view=diff
==
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Wed Dec  6 23:03:15 2017
@@ -1715,6 +1715,8 @@ Parser::ParseCXXTypeConstructExpression(
 /// type-specifier-seq declarator '=' assignment-expression
 /// [C++11] type-specifier-seq declarator '=' initializer-clause
 /// [C++11] type-specifier-seq declarator braced-init-list
+/// [Clang] type-specifier-seq ref-qualifier[opt] '[' identifier-list ']'
+/// brace-or-equal-initializer
 /// [GNU]   type-specifier-seq declarator simple-asm-expr[opt] attributes[opt]
 /// '=' assignment-expression
 ///

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=320011&r1=320010&r2=320011&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Dec  6 23:03:15 2017
@@ -692,8 +692,9 @@ Sema::ActOnDecompositionDeclarator(Scope
   assert(D.isDecompositionDeclarator());
   const DecompositionDeclarator &Decomp = D.getDecompositionDeclarator();
 
-  // The syntax only allows a decomposition declarator as a simple-declaration
-  // or a for-range-declaration, but we parse it in more cases than that.
+  // The syntax only allows a decomposition declarator as a simple-declaration,
+  // a for-range-declaration, or a condition in Clang, but we parse it in more
+  // cases than that.
   if (!D.mayHaveDecompositionDeclarator()) {
 Diag(Decomp.getLSquareLoc(), diag::err_decomp_decl_context)
   << Decomp.getSourceRange();
@@ -708,9 +709,12 @@ Sema::ActOnDecompositionDeclarator(Scope
 return nullptr;
   }
 
-  Diag(Decomp.getLSquareLoc(), getLangOpts().CPlusPlus17
-   ? diag::warn_cxx14_compat_decomp_decl
-  

r320401 - P0620 follow-up: deducing `auto` from braced-init-list in new expr

2017-12-11 Thread Zhihao Yuan via cfe-commits
Author: lichray
Date: Mon Dec 11 10:29:54 2017
New Revision: 320401

URL: http://llvm.org/viewvc/llvm-project?rev=320401&view=rev
Log:
P0620 follow-up: deducing `auto` from braced-init-list in new expr

Summary:
This is a side-effect brought in by p0620r0, which allows other placeholder 
types (derived from `auto` and `decltype(auto)`) to be usable in a `new` 
expression with a single-clause //braced-init-list// as its initializer (8.3.4 
[expr.new]/2).  N3922 defined its semantics.

References:
 http://wg21.link/p0620r0
 http://wg21.link/n3922

Reviewers: rsmith, aaron.ballman

Reviewed By: rsmith

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D39451

Added:
cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx14.cpp
cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx1z.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp
cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=320401&r1=320400&r2=320401&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Dec 11 10:29:54 
2017
@@ -1988,8 +1988,9 @@ def err_auto_var_requires_init : Error<
   "declaration of variable %0 with deduced type %1 requires an initializer">;
 def err_auto_new_requires_ctor_arg : Error<
   "new expression for type %0 requires a constructor argument">;
-def err_auto_new_list_init : Error<
-  "new expression for type %0 cannot use list-initialization">;
+def ext_auto_new_list_init : Extension<
+  "ISO C++ standards before C++17 do not allow new expression for "
+  "type %0 to use list-initialization">, InGroup;
 def err_auto_var_init_no_expression : Error<
   "initializer for variable %0 with type %1 is empty">;
 def err_auto_var_init_multiple_expressions : Error<

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=320401&r1=320400&r2=320401&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Dec 11 10:29:54 2017
@@ -1748,20 +1748,27 @@ Sema::BuildCXXNew(SourceRange Range, boo
 if (AllocType.isNull())
   return ExprError();
   } else if (Deduced) {
+bool Braced = (initStyle == CXXNewExpr::ListInit);
+if (NumInits == 1) {
+  if (auto p = dyn_cast_or_null(Inits[0])) {
+Inits = p->getInits();
+NumInits = p->getNumInits();
+Braced = true;
+  }
+}
+
 if (initStyle == CXXNewExpr::NoInit || NumInits == 0)
   return ExprError(Diag(StartLoc, diag::err_auto_new_requires_ctor_arg)
<< AllocType << TypeRange);
-if (initStyle == CXXNewExpr::ListInit ||
-(NumInits == 1 && isa(Inits[0])))
-  return ExprError(Diag(Inits[0]->getLocStart(),
-diag::err_auto_new_list_init)
-   << AllocType << TypeRange);
 if (NumInits > 1) {
   Expr *FirstBad = Inits[1];
   return ExprError(Diag(FirstBad->getLocStart(),
 diag::err_auto_new_ctor_multiple_expressions)
<< AllocType << TypeRange);
 }
+if (Braced && !getLangOpts().CPlusPlus17)
+  Diag(Initializer->getLocStart(), diag::ext_auto_new_list_init)
+  << AllocType << TypeRange;
 Expr *Deduce = Inits[0];
 QualType DeducedType;
 if (DeduceAutoType(AllocTypeInfo, Deduce, DeducedType) == DAR_Failed)

Modified: cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp?rev=320401&r1=320400&r2=320401&view=diff
==
--- cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp (original)
+++ cfe/trunk/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp Mon Dec 11 
10:29:54 2017
@@ -9,12 +9,14 @@ struct only {
 void f() {
   only p = new const auto (0);
   only q = new (auto) (0.0);
+  only r = new auto {'a'};
 
   new auto; // expected-error{{new expression for type 'auto' requires a 
constructor argument}}
   new (const auto)(); // expected-error{{new expression for type 'const auto' 
requires a constructor argument}}
   new (auto) (1,2,3); // expected-error{{new expression for type 'auto' 
contains multiple constructor arguments}}
-  new auto {1,2,3}; // expected-error{{new expression for type 'auto' cannot 
use list-initialization}}
-  new auto ({1,2,3}); // expected-error{{new expression for type 'auto' cannot 
use list-initialization}}

[libcxx] r320509 - [libcxx] P0604, invoke_result and is_invocable

2017-12-12 Thread Zhihao Yuan via cfe-commits
Author: lichray
Date: Tue Dec 12 10:42:04 2017
New Revision: 320509

URL: http://llvm.org/viewvc/llvm-project?rev=320509&view=rev
Log:
[libcxx] P0604, invoke_result and is_invocable

Summary:
Introduce a new form of `result_of` without function type encoding.

Rename and split `is_callable/is_nothrow_callable` into 
`is_invocable/is_nothrow_invocable/is_invocable_r/is_nothrow_invocable_r` (and 
associated types accordingly)

Change function type encoding of previous `is_callable/is_nothrow_callable` 
traits to conventional template type parameter lists.


Reviewers: EricWF, mclow.lists, bebuch

Reviewed By: EricWF, bebuch

Subscribers: lichray, bebuch, cfe-commits

Differential Revision: https://reviews.llvm.org/D38831

Added:
libcxx/trunk/test/std/utilities/meta/meta.rel/is_invocable.pass.cpp
libcxx/trunk/test/std/utilities/meta/meta.rel/is_nothrow_invocable.pass.cpp
Removed:
libcxx/trunk/test/std/utilities/meta/meta.rel/is_callable.pass.cpp
libcxx/trunk/test/std/utilities/meta/meta.rel/is_nothrow_callable.pass.cpp
Modified:
libcxx/trunk/include/type_traits
libcxx/trunk/include/variant
libcxx/trunk/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp

libcxx/trunk/test/std/utilities/function.objects/unord.hash/non_enum.pass.cpp

libcxx/trunk/test/std/utilities/meta/meta.trans/meta.trans.other/result_of.pass.cpp

libcxx/trunk/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp

Modified: libcxx/trunk/include/type_traits
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=320509&r1=320508&r2=320509&view=diff
==
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Tue Dec 12 10:42:04 2017
@@ -137,13 +137,11 @@ namespace std
 template  struct is_base_of;
 template  struct is_convertible;
 
-template  struct is_callable; // not defined
-template 
-  struct is_callable;
-
-template  struct is_nothrow_callable; // not defined
-template 
-  struct is_nothrow_callable;
+template  struct is_invocable;
+template  struct is_invocable_r;
+
+template  struct is_nothrow_invocable;
+template  struct 
is_nothrow_invocable_r;
 
 // Alignment properties and transformations:
 template  struct alignment_of;
@@ -157,6 +155,7 @@ namespace std
 template  struct underlying_type;
 template  class result_of; // undefined
 template  class result_of;
+template  struct invoke_result;  // C++17
 
 // const-volatile modifications:
 template 
@@ -215,8 +214,10 @@ namespace std
   using common_type_t = typename common_type::type;  // C++14
 template 
   using underlying_type_t = typename underlying_type::type;  // C++14
-template 
-  using result_of_t   = typename result_of::type;  // 
C++14
+template 
+  using result_of_t   = typename result_of::type;  // C++14
+template 
+  using invoke_result_t   = typename invoke_result::type; 
 // C++17
 
 template 
   using void_t = void;   // C++17
@@ -370,10 +371,14 @@ namespace std
 = is_base_of::value;  // 
C++17
   template  constexpr bool is_convertible_v
 = is_convertible::value;   // 
C++17
-  template  constexpr bool is_callable_v
-= is_callable::value;  // 
C++17
-  template  constexpr bool is_nothrow_callable_v
-= is_nothrow_callable::value;  // 
C++17
+  template  constexpr bool is_invocable_v
+= is_invocable::value;  // 
C++17
+  template  constexpr bool 
is_invocable_r_v
+= is_invocable_r::value; // 
C++17
+  template  constexpr bool 
is_nothrow_invocable_v
+= is_nothrow_invocable::value;  // 
C++17
+  template  constexpr bool 
is_nothrow_invocable_r_v
+= is_nothrow_invocable_r::value; // 
C++17
 
   // [meta.logical], logical operator traits:
   template struct conjunction;   // 
C++17
@@ -4402,6 +4407,13 @@ using __nothrow_invokable_r =
 >;
 
 template 
+using __nothrow_invokable =
+__nothrow_invokable_r_imp<
+__invokable<_Fp, _Args...>::value,
+true, void, _Fp, _Args...
+>;
+
+template 
 struct __invoke_of
 : public enable_if<
 __invokable<_Fp, _Args...>::value,
@@ -4423,30 +4435,48 @@ template  using result_of_t =
 
 #if _LIBCPP_STD_VER > 14
 
-// is_callable
+// invoke_result
 
-template 
-struct _LIBCPP_TEMPLATE_VIS is_callable;
+template 
+struct _LIBCPP_TEMPLATE_VIS invoke_result
+: __invoke_of<_Fn, _Args...>
+{
+};
+
+template 
+using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
+
+// is_invocable
 
-template 
-struct _LIBCPP_TEMPLATE_VIS is_callable<_Fn(_Args..

[libcxx] r320604 - [libcxx] Fix basic_stringbuf constructor

2017-12-13 Thread Zhihao Yuan via cfe-commits
Author: lichray
Date: Wed Dec 13 10:12:55 2017
New Revision: 320604

URL: http://llvm.org/viewvc/llvm-project?rev=320604&view=rev
Log:
[libcxx] Fix basic_stringbuf constructor

Summary:
[libcxx] Fix basic_stringbuf constructor

The C++ Standard [stringbuf.cons]p1 defines the effects of the basic_stringbuf
constructor that takes ios_base::openmode as follows:
  Effects: Constructs an object of class basic_stringbuf, initializing the
  base class with basic_streambuf(), and initializing mode with which.
  Postconditions: str() == "".

The default constructor of basic_streambuf shall initialize all its
pointer member objects to null pointers [streambuf.cons]p1.

Currently libc++ calls "str(string_type());" in the aforementioned constructor
setting basic_streambuf's pointers to a non-null value.

This patch removes the call (note that the postcondition str() == ""
remains valid because __str_ is default-initialized) and adds a test checking
that the basic_streambuf's pointers are null after construction.

Thanks Mikhail Maltsev for the patch.

Reviewers: EricWF, mclow.lists

Reviewed By: mclow.lists

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D40707

Modified:
libcxx/trunk/include/sstream

libcxx/trunk/test/std/input.output/string.streams/stringbuf/stringbuf.cons/default.pass.cpp

Modified: libcxx/trunk/include/sstream
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/sstream?rev=320604&r1=320603&r2=320604&view=diff
==
--- libcxx/trunk/include/sstream (original)
+++ libcxx/trunk/include/sstream Wed Dec 13 10:12:55 2017
@@ -243,7 +243,6 @@ basic_stringbuf<_CharT, _Traits, _Alloca
 : __hm_(0),
   __mode_(__wch)
 {
-str(string_type());
 }
 
 template 

Modified: 
libcxx/trunk/test/std/input.output/string.streams/stringbuf/stringbuf.cons/default.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/string.streams/stringbuf/stringbuf.cons/default.pass.cpp?rev=320604&r1=320603&r2=320604&view=diff
==
--- 
libcxx/trunk/test/std/input.output/string.streams/stringbuf/stringbuf.cons/default.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/input.output/string.streams/stringbuf/stringbuf.cons/default.pass.cpp
 Wed Dec 13 10:12:55 2017
@@ -17,6 +17,21 @@
 #include 
 #include 
 
+template
+struct testbuf
+: std::basic_stringbuf
+{
+void check()
+{
+assert(this->eback() == NULL);
+assert(this->gptr() == NULL);
+assert(this->egptr() == NULL);
+assert(this->pbase() == NULL);
+assert(this->pptr() == NULL);
+assert(this->epptr() == NULL);
+}
+};
+
 int main()
 {
 {
@@ -27,4 +42,12 @@ int main()
 std::wstringbuf buf;
 assert(buf.str() == L"");
 }
+{
+testbuf buf;
+buf.check();
+}
+{
+testbuf buf;
+buf.check();
+}
 }


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


[clang] 09b75f4 - [clang-format] New BreakInheritanceList style AfterComma

2021-05-28 Thread Zhihao Yuan via cfe-commits

Author: Zhihao Yuan
Date: 2021-05-28T18:24:00-05:00
New Revision: 09b75f480d1d578d48307fd7f3b024b66a75712f

URL: 
https://github.com/llvm/llvm-project/commit/09b75f480d1d578d48307fd7f3b024b66a75712f
DIFF: 
https://github.com/llvm/llvm-project/commit/09b75f480d1d578d48307fd7f3b024b66a75712f.diff

LOG: [clang-format] New BreakInheritanceList style AfterComma

This inheritance list style has been widely adopted by Symantec,
a division of Broadcom Inc. It breaks after the commas that
separate the base-specifiers:

class Derived : public Base1,
private Base2
{
};

Differential Revision: https://reviews.llvm.org/D103204

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 459887705d4ec..bbe2807c2e23a 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2038,6 +2038,15 @@ the configuration (without a prefix: ``Auto``).
Base2
{};
 
+  * ``BILS_AfterComma`` (in configuration: ``AfterComma``)
+Break inheritance list only after the commas.
+
+.. code-block:: c++
+
+   class Foo : Base1,
+   Base2
+   {};
+
 
 
 **BreakStringLiterals** (``bool``)

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 81609fa6efdfd..cbf0f9b0e2c49 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -250,6 +250,9 @@ clang-format
   accepts ``AllIfsAndElse`` value that allows to put "else if" and "else" short
   statements on a single line. (Fixes https://llvm.org/PR50019.)
 
+- Option ``BreakInheritanceList`` gets a new style, ``AfterComma``. It breaks
+  only after the commas that separate the base-specifiers.
+
 - ``git-clang-format`` no longer formats changes to symbolic links. (Fixes
   https://llvm.org/PR46992.)
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 4392b4aa4b43a..c30e357b5d0dd 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1829,7 +1829,14 @@ struct FormatStyle {
 ///Base2
 ///{};
 /// \endcode
-BILS_AfterColon
+BILS_AfterColon,
+/// Break inheritance list only after the commas.
+/// \code
+///class Foo : Base1,
+///Base2
+///{};
+/// \endcode
+BILS_AfterComma,
   };
 
   /// The inheritance list style to use.

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c50786c9d2f7a..c85ecd970ff15 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -240,6 +240,7 @@ struct 
ScalarEnumerationTraits {
 IO.enumCase(Value, "BeforeColon", FormatStyle::BILS_BeforeColon);
 IO.enumCase(Value, "BeforeComma", FormatStyle::BILS_BeforeComma);
 IO.enumCase(Value, "AfterColon", FormatStyle::BILS_AfterColon);
+IO.enumCase(Value, "AfterComma", FormatStyle::BILS_AfterComma);
   }
 };
 

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d1aa3e422b5a8..daa624000ff6d 100755
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3639,6 +3639,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
&Line,
   if (Style.BreakInheritanceList == FormatStyle::BILS_BeforeComma &&
   Right.is(TT_InheritanceComma))
 return true;
+  if (Style.BreakInheritanceList == FormatStyle::BILS_AfterComma &&
+  Left.is(TT_InheritanceComma))
+return true;
   if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
 // Multiline raw string literals are special wrt. line breaks. The author
 // has made a deliberate choice and might have aligned the contents of the

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index cf3e7b1df3900..efabaabf6e7f5 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2290,6 +2290,28 @@ TEST_F(FormatTest, BreakInheritanceStyle) {
"public aaa< // break\n"
"> {};",
StyleWithInheritanceBreakAfterColon);
+
+  FormatStyle StyleWithInheritanceBreakAfterComma = getLLVMStyle();
+  StyleWithInheritanceBreakAfterComma.BreakInheritanceList =
+  FormatStyle::BILS_AfterComma;
+  verifyFormat("class MyClass : public X {};",
+   StyleWithInheritanceBreakAfterComma);
+  verifyFormat("class MyClass : public X,\n"
+   "public Y {};",
+   StyleWithInheritanceBreakAfterComma);
+  verifyForm

[clang] 41a0e85 - [PowerPC] Drop stdlib paths in freestanding tests

2021-12-04 Thread Zhihao Yuan via cfe-commits

Author: Zhihao Yuan
Date: 2021-12-04T16:51:13-06:00
New Revision: 41a0e850fa30acf2ffd1c4ffda335f07ea0c249b

URL: 
https://github.com/llvm/llvm-project/commit/41a0e850fa30acf2ffd1c4ffda335f07ea0c249b
DIFF: 
https://github.com/llvm/llvm-project/commit/41a0e850fa30acf2ffd1c4ffda335f07ea0c249b.diff

LOG: [PowerPC] Drop stdlib paths in freestanding tests

When targeting FreeBSD on a Linux host with a copy
of system libc++, Clang prepends /usr/include/c++/v1
to the search paths even with -ffreestanding, and
fails to compile a program with a
single #include 

Dropping the path with -nostdlibinc.

Differential Revision: https://reviews.llvm.org/D114497

Added: 


Modified: 
clang/test/CodeGen/ppc-xmmintrin.c

Removed: 




diff  --git a/clang/test/CodeGen/ppc-xmmintrin.c 
b/clang/test/CodeGen/ppc-xmmintrin.c
index 158c235c7d894..07bbe71667c98 100644
--- a/clang/test/CodeGen/ppc-xmmintrin.c
+++ b/clang/test/CodeGen/ppc-xmmintrin.c
@@ -10,13 +10,13 @@
 // RUN: %clang -x c++ -fsyntax-only -target powerpc64le-unknown-linux-gnu 
-mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns
 
-// RUN: %clang -S -emit-llvm -target powerpc64-unknown-freebsd13.0 -mcpu=pwr8 
-ffreestanding -DNO_WARN_X86_INTRINSICS %s \
+// RUN: %clang -S -emit-llvm -target powerpc64-unknown-freebsd13.0 -mcpu=pwr8 
-ffreestanding -nostdlibinc -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-BE
-// RUN: %clang -x c++ -fsyntax-only -target powerpc64-unknown-freebsd13.0 
-mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
+// RUN: %clang -x c++ -fsyntax-only -target powerpc64-unknown-freebsd13.0 
-mcpu=pwr8 -ffreestanding -nostdlibinc -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns
-// RUN: %clang -S -emit-llvm -target powerpc64le-unknown-freebsd13.0 
-mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
+// RUN: %clang -S -emit-llvm -target powerpc64le-unknown-freebsd13.0 
-mcpu=pwr8 -ffreestanding -nostdlibinc -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns -o - | 
llvm-cxxfilt -n | FileCheck %s --check-prefixes=CHECK,CHECK-LE
-// RUN: %clang -x c++ -fsyntax-only -target powerpc64le-unknown-freebsd13.0 
-mcpu=pwr8 -ffreestanding -DNO_WARN_X86_INTRINSICS %s \
+// RUN: %clang -x c++ -fsyntax-only -target powerpc64le-unknown-freebsd13.0 
-mcpu=pwr8 -ffreestanding -nostdlibinc -DNO_WARN_X86_INTRINSICS %s \
 // RUN:   -fno-discard-value-names -mllvm -disable-llvm-optzns
 
 #include 



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


r328409 - [C++17] Fix class template argument deduction for default constructors without an initializer

2018-03-23 Thread Zhihao Yuan via cfe-commits
Author: lichray
Date: Fri Mar 23 21:32:11 2018
New Revision: 328409

URL: http://llvm.org/viewvc/llvm-project?rev=328409&view=rev
Log:
[C++17] Fix class template argument deduction for default constructors without 
an initializer

Summary:
As the title says, this makes following code compile:

```
template struct Foo {};
Foo() -> Foo;

Foo f; // ok
```

Thanks Nicolas Lesser for coining the fix.

Reviewers: rsmith, lichray

Reviewed By: rsmith, lichray

Subscribers: lichray, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D38216

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp
cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=328409&r1=328408&r2=328409&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Mar 23 21:32:11 2018
@@ -10396,12 +10396,22 @@ QualType Sema::deduceVarTypeFromInitiali
   // C++11 [dcl.spec.auto]p3
   if (!Init) {
 assert(VDecl && "no init for init capture deduction?");
-Diag(VDecl->getLocation(), diag::err_auto_var_requires_init)
-  << VDecl->getDeclName() << Type;
-return QualType();
+
+// Except for class argument deduction, and then for an initializing
+// declaration only, i.e. no static at class scope or extern.
+if (!isa(Deduced) ||
+VDecl->hasExternalStorage() ||
+VDecl->isStaticDataMember()) {
+  Diag(VDecl->getLocation(), diag::err_auto_var_requires_init)
+<< VDecl->getDeclName() << Type;
+  return QualType();
+}
   }
 
-  ArrayRef DeduceInits = Init;
+  ArrayRef DeduceInits;
+  if (Init)
+DeduceInits = Init;
+
   if (DirectInit) {
 if (auto *PL = dyn_cast_or_null(Init))
   DeduceInits = PL->exprs();

Modified: 
cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp?rev=328409&r1=328408&r2=328409&view=diff
==
--- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp 
(original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.class.deduct/p1.cpp 
Fri Mar 23 21:32:11 2018
@@ -5,8 +5,7 @@ A() -> A;
 A(int) -> A;
 
 static constexpr inline const volatile A a = {}; // ok, specifiers are 
permitted
-// FIXME: There isn't really a good reason to reject this.
-A b; // expected-error {{requires an initializer}}
+A b;
 A c [[]] {};
 
 A d = {}, e = {};
@@ -16,3 +15,5 @@ struct B {
   static A a; // expected-error {{requires an initializer}}
 };
 extern A x; // expected-error {{requires an initializer}}
+static A y;
+

Modified: cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp?rev=328409&r1=328408&r2=328409&view=diff
==
--- cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp (original)
+++ cfe/trunk/test/Parser/cxx1z-class-template-argument-deduction.cpp Fri Mar 
23 21:32:11 2018
@@ -137,7 +137,6 @@ namespace expr {
 (void)A{n};
 (void)new A(n);
 (void)new A{n};
-// FIXME: We should diagnose the lack of an initializer here.
 (void)new A;
   }
 }
@@ -150,7 +149,7 @@ namespace decl {
 
   auto k() -> A; // expected-error{{requires template arguments}}
 
-  A a; // expected-error {{declaration of variable 'a' with deduced type 'A' 
requires an initializer}}
+  A a;
   A b = 0;
   const A c = 0;
   A (parens) = 0; // expected-error {{cannot use parentheses when declaring 
variable with deduced class template specialization type}}


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


r328797 - [test] Fix an XRay test on FreeBSD

2018-03-29 Thread Zhihao Yuan via cfe-commits
Author: lichray
Date: Thu Mar 29 08:50:44 2018
New Revision: 328797

URL: http://llvm.org/viewvc/llvm-project?rev=328797&view=rev
Log:
[test] Fix an XRay test on FreeBSD

Summary: Fixing clang-test on FreeBSD as a follow-up of 
https://reviews.llvm.org/D43378 to handle the revert happened in r325749.

Reviewers: devnexen, krytarowski, dberris

Subscribers: emaste, dberris, cfe-commits

Differential Revision: https://reviews.llvm.org/D45002

Modified:
cfe/trunk/test/Driver/XRay/xray-instrument-os.c

Modified: cfe/trunk/test/Driver/XRay/xray-instrument-os.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/XRay/xray-instrument-os.c?rev=328797&r1=328796&r2=328797&view=diff
==
--- cfe/trunk/test/Driver/XRay/xray-instrument-os.c (original)
+++ cfe/trunk/test/Driver/XRay/xray-instrument-os.c Thu Mar 29 08:50:44 2018
@@ -1,4 +1,4 @@
 // RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: -linux-
+// XFAIL: -linux-, -freebsd
 // REQUIRES-ANY: amd64, x86_64, x86_64h, arm, aarch64, arm64
 typedef int a;


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


[clang] 136b293 - [c++2b] Implement P0849R8 auto(x)

2022-02-28 Thread Zhihao Yuan via cfe-commits

Author: Zhihao Yuan
Date: 2022-02-28T19:21:08-06:00
New Revision: 136b2931292083c8d69c09de9b952c86417b2c5d

URL: 
https://github.com/llvm/llvm-project/commit/136b2931292083c8d69c09de9b952c86417b2c5d
DIFF: 
https://github.com/llvm/llvm-project/commit/136b2931292083c8d69c09de9b952c86417b2c5d.diff

LOG: [c++2b] Implement P0849R8 auto(x)

https://wg21.link/p0849

Reviewed By: aaron.ballman, erichkeane

Differential Revision: https://reviews.llvm.org/D113393

Added: 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.auto.deduct/p2.cpp
clang/test/CXX/expr/expr.post/expr.type.conv/p1-2b.cpp
clang/test/Parser/cxx2b-auto-x.cpp
clang/test/SemaCXX/cxx2b-ast-print.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/StmtPrinter.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp
clang/test/CXX/expr/expr.unary/expr.new/p2-cxx0x.cpp
clang/test/CXX/expr/expr.unary/expr.new/p2-cxx14.cpp
clang/test/CXX/expr/expr.unary/expr.new/p2-cxx1z.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4131c022f5944..d5f6c2d730f59 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,6 +123,7 @@ C++2b Feature Support
 ^
 
 - Implemented `P2128R6: Multidimensional subscript operator 
`_.
+- Implemented `P0849R8: auto(x): decay-copy in the language 
`_.
 
 CUDA Language Changes in Clang
 --

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8f631b7c1a8a2..945d4e2976503 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2320,13 +2320,23 @@ def ext_auto_new_list_init : Extension<
   "type %0 to use list-initialization">, InGroup;
 def err_auto_var_init_no_expression : Error<
   "initializer for variable %0 with type %1 is empty">;
+def err_auto_expr_init_no_expression : Error<
+  "initializer for functional-style cast to %0 is empty">;
 def err_auto_var_init_multiple_expressions : Error<
   "initializer for variable %0 with type %1 contains multiple expressions">;
+def err_auto_expr_init_multiple_expressions : Error<
+  "initializer for functional-style cast to %0 contains multiple expressions">;
 def err_auto_var_init_paren_braces : Error<
   "cannot deduce type for variable %1 with type %2 from "
   "%select{parenthesized|nested}0 initializer list">;
 def err_auto_new_ctor_multiple_expressions : Error<
   "new expression for type %0 contains multiple constructor arguments">;
+def err_auto_expr_init_paren_braces : Error<
+  "cannot deduce actual type for %1 from "
+  "%select{parenthesized|nested}0 initializer list">;
+def warn_cxx20_compat_auto_expr : Warning<
+  "'auto' as a functional-style cast is incompatible with C++ standards "
+  "before C++2b">, InGroup, DefaultIgnore;
 def err_auto_missing_trailing_return : Error<
   "'auto' return without trailing return type; deduced return types are a "
   "C++14 extension">;
@@ -2340,6 +2350,8 @@ def err_auto_var_deduction_failure : Error<
   "variable %0 with type %1 has incompatible initializer of type %2">;
 def err_auto_var_deduction_failure_from_init_list : Error<
   "cannot deduce actual type for variable %0 with type %1 from initializer 
list">;
+def err_auto_expr_deduction_failure : Error<
+  "functional-style cast to %0 has incompatible initializer of type %1">;
 def err_auto_new_deduction_failure : Error<
   "new expression for type %0 has incompatible constructor argument of type 
%1">;
 def err_auto_inconsistent_deduction : Error<

diff  --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index 5ad935591ecd9..677181f925a54 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -1940,14 +1940,23 @@ void 
StmtPrinter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Node) {
 }
 
 void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) {
-  Node->getType().print(OS, Policy);
-  // If there are no parens, this is list-initialization, and the braces are
-  // part of the syntax of the inner construct.
-  if (Node->getLParenLoc().isValid())
-OS << "(";
+  auto TargetType = Node->getType();
+  auto *Auto = TargetType->getContainedDeducedType();
+  bool Bare = Auto && Auto->isDeduced();
+
+  // Parenthesize deduced casts.
+  if (Bare)
+OS << '(';
+  TargetType.print(OS, Policy);
+  if (Bare)
+OS << ')';
+
+  // No extra braces surrounding the inner construct.
+  if (!Node->isListInitialization())
+OS << '(';
   P

[clang] d1a59ee - [Clang] Remove redundant init-parens in AST print

2022-02-28 Thread Zhihao Yuan via cfe-commits

Author: Zhihao Yuan
Date: 2022-02-28T19:31:16-06:00
New Revision: d1a59eefd3a09f08ba425a20899fbd1766babc45

URL: 
https://github.com/llvm/llvm-project/commit/d1a59eefd3a09f08ba425a20899fbd1766babc45
DIFF: 
https://github.com/llvm/llvm-project/commit/d1a59eefd3a09f08ba425a20899fbd1766babc45.diff

LOG: [Clang] Remove redundant init-parens in AST print

Given a dependent `T` (maybe an undeduced `auto`),

Before:

new T(z)  -->  new T((z))  # changes meaning with more args
new T{z}  -->  new T{z}
T(z)  -->  T(z)
T{z}  -->  T({z})  # forbidden if T is auto

After:

new T(z)  -->  new T(z)
new T{z}  -->  new T{z}
T(z)   --> T(z)
T{z}   --> T{z}

Depends on D113393

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D120608

Added: 


Modified: 
clang/lib/AST/StmtPrinter.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
clang/test/SemaCXX/cxx2b-ast-print.cpp

Removed: 




diff  --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index 677181f925a54..a6aa9fe45b027 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -2153,11 +2153,13 @@ void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) {
 OS << ")";
 
   CXXNewExpr::InitializationStyle InitStyle = E->getInitializationStyle();
-  if (InitStyle) {
-if (InitStyle == CXXNewExpr::CallInit)
+  if (InitStyle != CXXNewExpr::NoInit) {
+bool Bare = InitStyle == CXXNewExpr::CallInit &&
+!isa(E->getInitializer());
+if (Bare)
   OS << "(";
 PrintExpr(E->getInitializer());
-if (InitStyle == CXXNewExpr::CallInit)
+if (Bare)
   OS << ")";
   }
 }
@@ -2219,19 +2221,19 @@ void 
StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) {
   PrintExpr(E->getSubExpr());
 }
 
-void
-StmtPrinter::VisitCXXUnresolvedConstructExpr(
-   CXXUnresolvedConstructExpr *Node) {
+void StmtPrinter::VisitCXXUnresolvedConstructExpr(
+CXXUnresolvedConstructExpr *Node) {
   Node->getTypeAsWritten().print(OS, Policy);
-  OS << "(";
-  for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(),
- ArgEnd = Node->arg_end();
-   Arg != ArgEnd; ++Arg) {
+  if (!Node->isListInitialization())
+OS << '(';
+  for (auto Arg = Node->arg_begin(), ArgEnd = Node->arg_end(); Arg != ArgEnd;
+   ++Arg) {
 if (Arg != Node->arg_begin())
   OS << ", ";
 PrintExpr(*Arg);
   }
-  OS << ")";
+  if (!Node->isListInitialization())
+OS << ')';
 }
 
 void StmtPrinter::VisitCXXDependentScopeMemberExpr(

diff  --git 
a/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp 
b/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
index 39e882b8fa5f9..4e37a195398e8 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
@@ -72,7 +72,7 @@ struct E {
 };
 
 template requires requires(T t) { typename 
E::non_default_constructible{}; }
-// expected-note@-1 {{because 'typename E::non_default_constructible({})' 
would be invalid: no matching constructor for initialization of 'typename 
E::non_default_constructible'}}
+// expected-note@-1 {{because 'typename E::non_default_constructible{}' 
would be invalid: no matching constructor for initialization of 'typename 
E::non_default_constructible'}}
 struct r6 {};
 
 using r6i1 = r6;

diff  --git a/clang/test/SemaCXX/cxx2b-ast-print.cpp 
b/clang/test/SemaCXX/cxx2b-ast-print.cpp
index 4aa1b23280c39..58eb785a00771 100644
--- a/clang/test/SemaCXX/cxx2b-ast-print.cpp
+++ b/clang/test/SemaCXX/cxx2b-ast-print.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -std=c++2b -fsyntax-only -ast-print %s | FileCheck %s
 
+template  class C>
 void test_auto_expr(long long y, auto &&z) {
   int x[] = {3, 4};
 
@@ -15,16 +16,36 @@ void test_auto_expr(long long y, auto &&z) {
 
   // CHECK{LITERAL}: auto(z)
   void(auto(z));
-  // CHECK{LITERAL}: auto({z})
-  void(auto{z}); // T({z}) is legal unless T = auto
+  // CHECK{LITERAL}: auto{z}
+  void(auto{z});
 
   // CHECK{LITERAL}: new int *(x)
   void(new auto(x));
   // CHECK{LITERAL}: new int *{x}
   void(new auto{x});
 
+  // CHECK{LITERAL}: new auto(z)
+  void(new auto(z));
+  // CHECK{LITERAL}: new auto{z}
+  void(new auto{z});
+
   // CHECK{LITERAL}: new long long(y)
   void(new decltype(auto)(y));
   // CHECK{LITERAL}: new long long{y}
   void(new decltype(auto){y});
+
+  // CHECK{LITERAL}: new decltype(auto)(z)
+  void(new decltype(auto)(z));
+  // CHECK{LITERAL}: new decltype(auto){z}
+  void(new decltype(auto){z});
+
+  // CHECK{LITERAL}: C(x, y, z)
+  void(C(x, y, z));
+  // CHECK{LITERAL}: C{x, y, z}
+  void(C{x, y, z});
+
+  // CHECK{LITERAL}: new C(x, y, z)
+  void(new C(x, y, z));
+  // CHECK{LITERAL}: new C{x, y

[clang] 44eee65 - [AST] Print NTTP args as string-literals when possible

2022-03-01 Thread Zhihao Yuan via cfe-commits

Author: Zhihao Yuan
Date: 2022-03-01T19:34:27-06:00
New Revision: 44eee659f1c530a684fa2e57a983d962b5980620

URL: 
https://github.com/llvm/llvm-project/commit/44eee659f1c530a684fa2e57a983d962b5980620
DIFF: 
https://github.com/llvm/llvm-project/commit/44eee659f1c530a684fa2e57a983d962b5980620.diff

LOG: [AST] Print NTTP args as string-literals when possible

C++20 non-type template parameter prints `MyType<{{116, 104, 105, 115}}>` when 
the code is as simple as `MyType<"this">`. This patch prints 
`MyType<{"this"}>`, with one layer of braces preserved for the intermediate 
structural type to trigger CTAD.

`StringLiteral` handles this case, but `StringLiteral` inside `APValue` code 
looks like a circular dependency. The proposed patch implements a cheap 
strategy to emit string literals in diagnostic messages only when they are 
readable and fall back to integer sequences.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D115031

Added: 
clang/test/SemaCXX/cxx2a-nttp-printing.cpp
clang/test/SemaTemplate/temp_arg_string_printing.cpp

Modified: 
clang/include/clang/AST/DeclTemplate.h
clang/include/clang/AST/PrettyPrinter.h
clang/include/clang/Basic/CharInfo.h
clang/lib/AST/APValue.cpp
clang/lib/AST/ASTDiagnostic.cpp
clang/lib/AST/DeclTemplate.cpp
clang/lib/AST/Expr.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/TemplateBase.cpp
clang/lib/Sema/Sema.cpp
clang/unittests/AST/TypePrinterTest.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 319e605a8a1c5..0459ee8fb6164 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -3313,10 +3313,12 @@ class TemplateParamObjectDecl : public ValueDecl,
 
   /// Print this object as an equivalent expression.
   void printAsExpr(llvm::raw_ostream &OS) const;
+  void printAsExpr(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
 
   /// Print this object as an initializer suitable for a variable of the
   /// object's type.
   void printAsInit(llvm::raw_ostream &OS) const;
+  void printAsInit(llvm::raw_ostream &OS, const PrintingPolicy &Policy) const;
 
   const APValue &getValue() const { return Value; }
 

diff  --git a/clang/include/clang/AST/PrettyPrinter.h 
b/clang/include/clang/AST/PrettyPrinter.h
index fd40328d8dcf7..54cb57227f7a0 100644
--- a/clang/include/clang/AST/PrettyPrinter.h
+++ b/clang/include/clang/AST/PrettyPrinter.h
@@ -74,7 +74,7 @@ struct PrintingPolicy {
 SuppressImplicitBase(false), FullyQualifiedName(false),
 PrintCanonicalTypes(false), PrintInjectedClassNameWithArguments(true),
 UsePreferredNames(true), AlwaysIncludeTypeForTemplateArgument(false),
-CleanUglifiedParameters(false) {}
+CleanUglifiedParameters(false), EntireContentsOfLargeArray(true) {}
 
   /// Adjust this printing policy for cases where it's known that we're
   /// printing C++ code (for instance, if AST dumping reaches a C++-only
@@ -286,6 +286,10 @@ struct PrintingPolicy {
   /// This only affects parameter names, and so describes a compatible API.
   unsigned CleanUglifiedParameters : 1;
 
+  /// Whether to print the entire array initializers, especially on non-type
+  /// template parameters, no matter how many elements there are.
+  unsigned EntireContentsOfLargeArray : 1;
+
   /// Callbacks to use to allow the behavior of printing to be customized.
   const PrintingCallbacks *Callbacks = nullptr;
 };

diff  --git a/clang/include/clang/Basic/CharInfo.h 
b/clang/include/clang/Basic/CharInfo.h
index c751b6a005e28..7d41193835089 100644
--- a/clang/include/clang/Basic/CharInfo.h
+++ b/clang/include/clang/Basic/CharInfo.h
@@ -38,15 +38,16 @@ namespace charinfo {
   };
 } // end namespace charinfo
 
-/// Returns true if this is an ASCII character.
+/// Returns true if a byte is an ASCII character.
 LLVM_READNONE inline bool isASCII(char c) {
   return static_cast(c) <= 127;
 }
 
 LLVM_READNONE inline bool isASCII(unsigned char c) { return c <= 127; }
 
-/// Returns true if this is an ASCII character.
+/// Returns true if a codepoint is an ASCII character.
 LLVM_READNONE inline bool isASCII(uint32_t c) { return c <= 127; }
+LLVM_READNONE inline bool isASCII(int64_t c) { return 0 <= c && c <= 127; }
 
 /// Returns true if this is a valid first character of a C identifier,
 /// which is [a-zA-Z_].
@@ -162,6 +163,44 @@ LLVM_READONLY inline bool isRawStringDelimBody(unsigned 
char c) {
   CHAR_DIGIT|CHAR_UNDER|CHAR_RAWDEL)) != 0;
 }
 
+enum class EscapeChar {
+  Single = 1,
+  Double = 2,
+  SingleAndDouble = static_cast(Single) | static_cast(Double),
+};
+
+/// Return C-style escaped string for special characters, or an empty string if
+/// there is no such mapping.
+template 
+LLVM_READONLY inline auto escapeCStyle(CharT Ch) -> StringRef {
+  sw

[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-22 Thread Zhihao Yuan via cfe-commits

lichray wrote:

> > We used this extension to improve virtual function calling performance, 
> > there are simple and small virtual functions which are frequently called 
> > and can not be eliminated and it is in a delegation thus compiler can not 
> > optimize. [...]
> 
> Can `declcall` (https://wg21.link/p2825) be used for this? It is on track for 
> C++26.

Not according to the design as of R5, because the operand of `declcall` is an 
unevaluated operand, hence it will not walk into `this` value to find the entry 
in the actual vtable. Devirtualized pointer in p2825r5 can only be obtained 
when _qualified-id_ is involved.

https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)

2025-04-22 Thread Zhihao Yuan via cfe-commits

lichray wrote:

> Perhaps we could provide a builtin function that takes an object pointer and 
> a pointer-to-member-function and returns a devirtualized 
> pointer-to-member-function (or returns the original PMF if it wasn't a 
> pointer to a virtual function)? Unlike the GCC extension, that kind of 
> interface can actually work in general.

I suggest viewing the demands at the same time and taking a leveled approach:

1. invoking base implementation via a handle
2. saving a snapshot of a pending virtual call (delegate)
3. resolve virtual call on one object, apply the results on other objects

Each level is less safe than the previous one. 1 slightly troubles Liskov 
substitution, 2 doesn't work before the object establishes the runtime type 
[(in a 
constructor)](https://discourse.llvm.org/t/rfc-implement-gcc-bound-pmf-in-clang/85951/5?u=lichray),
 and 3 can apply the call to objects without such a runtime type.

1 is addressed by [p2825](https://wg21.link/p2825).

C++26 `std::function_ref` (with `nontype`) can address 2 at the cost of a 
thunk, usually optimized by sibling call optimization, and safe to use, but you 
can argue that "simply" assigning from the bit pattern of a C++Builder 
`__closure` object may just be what user wants.

The dynamic portion of GCC's bound method can address 3, but the feature can 
also be deemed a building block of `__closure`.

Imagine that you can evaluate `p->mem_fn`, literally a pending virtual call, 
and get a struct of two members, this will allow the use of structured binding:

```cpp
auto [bpf, pobj] = p->mem_fn;
```

Then, to fulfill 3, we only need a way to package the components back into such 
a struct to substitute the `pobj` with a pointer to a different object:

```cpp
auto rebound_method = decltype(p->mem_fn){ bpf, pother };
rebound_method();
```

This option is explored by C folks in 
[n2862](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2862.pdf). In which 
paper, the rebinding procedure is done by the `wide_set_context` API.

https://github.com/llvm/llvm-project/pull/135649
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits