[clang] bb9dedc - [Frontend] Restore Preprocessor::getPredefines()

2022-08-31 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-08-31T23:16:49+03:00
New Revision: bb9dedce5d01f5608acd784942481f386c710c0d

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

LOG: [Frontend] Restore Preprocessor::getPredefines()

https://reviews.llvm.org/rG6bbf51f3ed59ae37f0fec729f25af002111c9e74 from May 
removed Preprocessor::getPredefines() from Clang's API, presumably as a cleanup 
because this method is unused in the LLVM codebase.

However, it was/is used by a small number of third-party tools and is pretty 
harmless, so this patch adds it back and documents why it's here.

The issue was raised in https://github.com/llvm/llvm-project/issues/57483, it 
would be nice to be able to land it into Clang 15 as it breaks those 
third-party tools and we can't easily add it back in bug fix releases.

Reviewed By: brad.king, thieta

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

Added: 


Modified: 
clang/include/clang/Lex/Preprocessor.h

Removed: 




diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index c00600c68a34..7507be19f037 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -1375,6 +1375,11 @@ class Preprocessor {
   StringRef getLastMacroWithSpelling(SourceLocation Loc,
  ArrayRef Tokens) const;
 
+  /// Get the predefines for this processor.
+  /// Used by some third-party tools to inspect and add predefines (see
+  /// https://github.com/llvm/llvm-project/issues/57483).
+  const std::string &getPredefines() const { return Predefines; }
+
   /// Set the predefines for this Preprocessor.
   ///
   /// These predefines are automatically injected when parsing the main file.



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


[clang] 28bc410 - [DOC][Clang] Update cxx_status.html after the 15 release and fix a broken link in release notes

2022-09-06 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-09-06T21:59:27+03:00
New Revision: 28bc41099970f5cdab0addc60cc96b115ce657f8

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

LOG: [DOC][Clang] Update cxx_status.html after the 15 release and fix a broken 
link in release notes

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1d381649b6bb4..4a418e976bd4f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -215,7 +215,7 @@ C++20 Feature Support
   `GH55216 `_.
 - Correctly set expression evaluation context as 'immediate function context' 
in
   consteval functions.
-  This fixes `GH51182 `
+  This fixes `GH51182 `_.
 
 - Fixes an assert crash caused by looking up missing vtable information on 
``consteval``
   virtual functions. Fixes `GH55065 
`_.

diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 5876e39a0b536..e9a71bba7a0b8 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -1128,7 +1128,7 @@ C++20 implementation status
 
   Immediate functions (consteval)
   https://wg21.link/p1073r3";>P1073R3
-  Clang 15
+  Clang 15
 

 https://wg21.link/p1937r2";>P1937R2
@@ -1172,7 +1172,7 @@ C++20 implementation status
 
   Modules
   https://wg21.link/p1103r3";>P1103R3
-  Clang 15
+  Clang 15
 

 https://wg21.link/p1766r1";>P1766R1 (DR)
@@ -1188,7 +1188,7 @@ C++20 implementation status
   

 https://wg21.link/p1874r1";>P1874R1
-Clang 15
+Clang 15
   

 https://wg21.link/p1979r0";>P1979R0
@@ -1196,7 +1196,7 @@ C++20 implementation status
   

 https://wg21.link/p1779r3";>P1779R3
-Clang 15
+Clang 15
   
   
 https://wg21.link/p1857r3";>P1857R3
@@ -1370,12 +1370,12 @@ C++2b implementation status
 
   Multidimensional subscript operator
   https://wg21.link/P2128R6";>P2128R6
-  Clang 15
+  Clang 15
 
 
   Non-literal variables (and labels and gotos) in constexpr 
functions
   https://wg21.link/P2242R3";>P2242R3
-  Clang 15
+  Clang 15
 
 
   Character encoding of diagnostic text
@@ -1405,7 +1405,7 @@ C++2b implementation status
 
   auto(x): decay-copy in the language
   https://wg21.link/P0849R8";>P0849R8
-  Clang 15
+  Clang 15
 
 
 
@@ -1441,7 +1441,7 @@ C++2b implementation status
 
   De-deprecating volatile compound operations
   https://wg21.link/P2327R1";>P2327R1
-  Clang 15
+  Clang 15
 
 
   Support for #warning
@@ -1461,12 +1461,12 @@ C++2b implementation status
 
   Delimited escape sequences
   https://wg21.link/P2290R3";>P2290R3
-  Clang 15
+  Clang 15
 
 
   Named universal character escapes
   https://wg21.link/P2071R2";>P2071R2
-  Clang 15
+  Clang 15
 
 
   Relaxing some constexpr restrictions
@@ -1501,7 +1501,7 @@ C++2b implementation status
 
   Support for UTF-8 as a portable source file encoding
   https://wg21.link/P2295R6";>P2295R6
-  Clang 15
+  Clang 15
 
 
   char8_t Compatibility and Portability Fix



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


[clang] 508c431 - [SemaCXX] Validate destructor is valid for dependent classes

2022-08-02 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-08-02T21:50:54+03:00
New Revision: 508c431ed9ab6d2074f1c68e3ee6b245ece57d5a

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

LOG: [SemaCXX] Validate destructor is valid for dependent classes

We didn't check that a destructor's name matches the directly enclosing class 
if the class was dependent.
I enabled the check we already had for non-dependent types, which seems to 
work. Added appropriate tests.

Fixes GitHub issue #56772

Reviewed By: erichkeane

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/member-class-11.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 782659346e52e..9dc08639dafb4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -52,6 +52,8 @@ Bug Fixes
 - Fixes an accepts-invalid bug in C when using a ``_Noreturn`` function
   specifier on something other than a function declaration. This fixes
   `Issue 56800 `_.
+- Fix `#56772 `_ - invalid
+  destructor names were incorrectly accepted on template classes.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0557120949a9b..eca20002b30da 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11496,17 +11496,12 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
   CXXRecordDecl *Record = Destructor->getParent();
   QualType ClassType = Context.getTypeDeclType(Record);
 
-  // FIXME: Shouldn't we be able to perform this check even when the class
-  // type is dependent? Both gcc and edg can handle that.
-  if (!ClassType->isDependentType()) {
-DeclarationName Name
-  = Context.DeclarationNames.getCXXDestructorName(
-Context.getCanonicalType(ClassType));
-if (NewFD->getDeclName() != Name) {
-  Diag(NewFD->getLocation(), diag::err_destructor_name);
-  NewFD->setInvalidDecl();
-  return Redeclaration;
-}
+  DeclarationName Name = Context.DeclarationNames.getCXXDestructorName(
+  Context.getCanonicalType(ClassType));
+  if (NewFD->getDeclName() != Name) {
+Diag(NewFD->getLocation(), diag::err_destructor_name);
+NewFD->setInvalidDecl();
+return Redeclaration;
   }
 } else if (auto *Guide = dyn_cast(NewFD)) {
   if (auto *TD = Guide->getDescribedFunctionTemplate())

diff  --git a/clang/test/SemaCXX/member-class-11.cpp 
b/clang/test/SemaCXX/member-class-11.cpp
index c230c5305e7a8..68873ebad9d1d 100644
--- a/clang/test/SemaCXX/member-class-11.cpp
+++ b/clang/test/SemaCXX/member-class-11.cpp
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 struct rdar9677163 {
   struct Y { ~Y(); };
@@ -6,3 +8,22 @@ struct rdar9677163 {
   Y::~Y() { } // expected-error{{non-friend class member '~Y' cannot have a 
qualified name}}
   ~Z(); // expected-error{{expected the class name after '~' to name the 
enclosing class}}
 };
+
+namespace GH56772 {
+
+template
+struct A {
+  ~A();
+};
+#if __cplusplus >= 202002L
+// FIXME: This isn't valid in C++20 and later.
+#endif
+
+struct B;
+
+template
+struct C {
+  ~B(); // expected-error {{expected the class name after '~' to name the 
enclosing class}}
+};
+
+}



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


[clang] 94fd00f - [Concepts] Fix placeholder constraints when references are involved

2022-03-23 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-03-23T11:14:58-04:00
New Revision: 94fd00f41ebddf84148f494410130527169d9573

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

LOG: [Concepts] Fix placeholder constraints when references are involved

Placeholder types were not checked for constraint satisfaction when modified by 
references or pointers.
The behavior now matches that of GCC and MSVC.

Are there other modifiers we might need to "peel"? I'm not sure my approach to 
this is the 'right' way to fix this, the loop feels a bit clunky.

GitHub issues [[ https://github.com/llvm/llvm-project/issues/54443 | #54443 ]], 
[[ https://github.com/llvm/llvm-project/issues/53911 | #53911 ]]

Reviewed By: erichkeane

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaTemplate/concepts.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 403bc08eec9be..865da1eb2aa1b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -65,6 +65,10 @@ Bug Fixes
   fixes `Issue 53044 `_.
 - Allow `-Wno-gnu` to silence GNU extension diagnostics for pointer arithmetic
   diagnostics. Fixes `Issue 5 
`_.
+- Placeholder constraints, as in `Concept auto x = f();`, were not checked 
when modifiers
+  like ``auto&`` or ``auto**`` were added. These constraints are now checked.
+  This fixes  `Issue 53911 
`_
+  and  `Issue 54443 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index a53d83ea700b6..cb273aa285906 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4769,12 +4769,13 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *&Init, 
QualType &Result,
   return DAR_FailedAlreadyDiagnosed;
   }
 
-  if (const auto *AT = Type.getType()->getAs()) {
+  QualType MaybeAuto = Type.getType().getNonReferenceType();
+  while (MaybeAuto->isPointerType())
+MaybeAuto = MaybeAuto->getPointeeType();
+  if (const auto *AT = MaybeAuto->getAs()) {
 if (AT->isConstrained() && !IgnoreConstraints) {
-  auto ConstraintsResult =
-  CheckDeducedPlaceholderConstraints(*this, *AT,
- Type.getContainedAutoTypeLoc(),
- DeducedType);
+  auto ConstraintsResult = CheckDeducedPlaceholderConstraints(
+  *this, *AT, Type.getContainedAutoTypeLoc(), DeducedType);
   if (ConstraintsResult != DAR_Succeeded)
 return ConstraintsResult;
 }

diff  --git a/clang/test/SemaTemplate/concepts.cpp 
b/clang/test/SemaTemplate/concepts.cpp
index 132761b2d68ae..23c79421bb6f8 100644
--- a/clang/test/SemaTemplate/concepts.cpp
+++ b/clang/test/SemaTemplate/concepts.cpp
@@ -171,7 +171,7 @@ namespace PR50561 {
 }
 
 namespace PR49188 {
-  template concept C = false; // expected-note 6 {{because 
'false' evaluated to false}}
+  template concept C = false; // expected-note 7 {{because 
'false' evaluated to false}}
 
   C auto f1() { // expected-error {{deduced type 'void' does not satisfy 'C'}}
 return void();
@@ -189,7 +189,7 @@ namespace PR49188 {
   }
   C decltype(auto) f6() { // expected-error {{deduced type 'void' does not 
satisfy 'C'}}
   }
-  C auto& f7() { // expected-error {{cannot form a reference to 'void'}}
+  C auto& f7() { // expected-error {{deduced type 'void' does not satisfy 'C'}}
 return void();
   }
   C auto& f8() {
@@ -199,13 +199,16 @@ namespace PR49188 {
   }
 }
 namespace PR53911 {
-  template concept C = false;
+  template concept C = false; // expected-note 3 {{because 'false' 
evaluated to false}}
 
-  C auto *f1() {
-return (void*)nullptr; // FIXME: should error
+  C auto *f1() { // expected-error {{deduced type 'void' does not satisfy 'C'}}
+return (void*)nullptr;
   }
-  C auto *f2() {
-return (int*)nullptr; // FIXME: should error
+  C auto *f2() { // expected-error {{deduced type 'int' does not satisfy 'C'}}
+return (int*)nullptr;
+  }
+  C auto *f3() { // expected-error {{deduced type 'int' does not satisfy 
'C'}}
+return (int*)nullptr;
   }
 }
 
@@ -222,3 +225,34 @@ struct B {
 };
 void (*f2)() = B::f; // expected-error {{address of overloaded function 'f' 
does not match required type}}
 }
+
+namespace PR54443 {
+
+template 
+struct is_same { static constexpr bool value = false; };
+
+template 
+struct is

[clang] 454d1df - [Concepts] Fix overload resolution bug with constrained candidates

2022-04-19 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-04-19T04:45:28-04:00
New Revision: 454d1df9423c95e54c3a2f5cb58d864096032d09

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

LOG: [Concepts] Fix overload resolution bug with constrained candidates

When doing overload resolution, we have to check that candidates' parameter 
types are equal before trying to find a better candidate through checking which 
candidate is more constrained.
This revision adds this missing check and makes us diagnose those cases as 
ambiguous calls when the types are not equal.

Fixes GitHub issue https://github.com/llvm/llvm-project/issues/53640

Reviewed By: erichkeane

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

Added: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c396322f2de57..a7a6fab5fe535 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,6 +123,11 @@ Bug Fixes
   a lambda expression that shares the name of a variable in a containing
   if/while/for/switch init statement as a redeclaration.
   This fixes `Issue 54913 
`_.
+- Overload resolution for constrained function templates could use the partial
+  order of constraints to select an overload, even if the parameter types of
+  the functions were 
diff erent. It now diagnoses this case correctly as an
+  ambiguous call and an error. Fixes
+  `Issue 53640 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index e2ae02ea9f76f..fd9433cb1b786 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3590,7 +3590,8 @@ class Sema final {
 QualType& ConvertedType);
   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos = nullptr);
+  unsigned *ArgPos = nullptr,
+  bool Reversed = false);
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
@@ -8768,7 +8769,8 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false);
+  unsigned NumCallArguments2, bool Reversed = false,
+  bool AllowOrderingByConstraints = true);
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 1add971a81a02..6e45fdfbeb089 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2945,24 +2945,30 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic 
&PDiag,
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their argument types. Caller has already checked that
-/// they have same number of arguments.  If the parameters are 
diff erent,
+/// for equality of their parameter types. Caller has already checked that
+/// they have same number of parameters.  If the parameters are 
diff erent,
 /// ArgPos will have the parameter index of the first 
diff erent parameter.
+/// If `Reversed` is true, the parameters of `NewType` will be compared in
+/// reverse order. That's useful if one of the functions is being used as a 
C++20
+/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos) {
-  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
-  N = NewType->param_type_begin(),
-  E = OldType->param_type_end();
-   O && (O != E); ++O, ++N) {
+  unsigned *ArgPos, bool Reversed) {
+  assert(OldType->getNumParams() == NewType->getNumParams() &&
+ "Can't compare parameters of

[clang] 7641004 - Revert "[Concepts] Fix overload resolution bug with constrained candidates"

2022-04-19 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-04-19T07:51:21-04:00
New Revision: 76410040b9f391185c7df48c14519860e1cf75e5

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

LOG: Revert "[Concepts] Fix overload resolution bug with constrained candidates"

This reverts commit 454d1df9423c95e54c3a2f5cb58d864096032d09.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a7a6fab5fe535..c396322f2de57 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,11 +123,6 @@ Bug Fixes
   a lambda expression that shares the name of a variable in a containing
   if/while/for/switch init statement as a redeclaration.
   This fixes `Issue 54913 
`_.
-- Overload resolution for constrained function templates could use the partial
-  order of constraints to select an overload, even if the parameter types of
-  the functions were 
diff erent. It now diagnoses this case correctly as an
-  ambiguous call and an error. Fixes
-  `Issue 53640 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index fd9433cb1b786..e2ae02ea9f76f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3590,8 +3590,7 @@ class Sema final {
 QualType& ConvertedType);
   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos = nullptr,
-  bool Reversed = false);
+  unsigned *ArgPos = nullptr);
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
@@ -8769,8 +8768,7 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false,
-  bool AllowOrderingByConstraints = true);
+  unsigned NumCallArguments2, bool Reversed = false);
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 6e45fdfbeb089..1add971a81a02 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2945,30 +2945,24 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic 
&PDiag,
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their parameter types. Caller has already checked that
-/// they have same number of parameters.  If the parameters are 
diff erent,
+/// for equality of their argument types. Caller has already checked that
+/// they have same number of arguments.  If the parameters are 
diff erent,
 /// ArgPos will have the parameter index of the first 
diff erent parameter.
-/// If `Reversed` is true, the parameters of `NewType` will be compared in
-/// reverse order. That's useful if one of the functions is being used as a 
C++20
-/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos, bool Reversed) {
-  assert(OldType->getNumParams() == NewType->getNumParams() &&
- "Can't compare parameters of functions with 
diff erent number of "
- "parameters!");
-  for (size_t I = 0; I < OldType->getNumParams(); I++) {
-// Reverse iterate over the parameters of `OldType` if `Reversed` is true.
-size_t J = Reversed ? (OldType->getNumParams() - I - 1) : I;
-
+  unsigned *ArgPos) {
+  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
+  N = NewType->param_type_begin(),
+  E = OldType->param_type_end();
+   O && (O != E); ++O, ++N) {
 // Ignore address spaces in pointee type. This is to disallow overloading
 // on __ptr32/__ptr64 address spaces

[clang] 807e418 - [Concepts] Fix overload resolution bug with constrained candidates

2022-04-23 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-04-23T17:24:59-04:00
New Revision: 807e418413a0958ad1ea862093fb262673b2afa1

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

LOG: [Concepts] Fix overload resolution bug with constrained candidates

When doing overload resolution, we have to check that candidates' parameter 
types are equal before trying to find a better candidate through checking which 
candidate is more constrained.
This revision adds this missing check and makes us diagnose those cases as 
ambiguous calls when the types are not equal.

Fixes GitHub issue https://github.com/llvm/llvm-project/issues/53640

Reviewed By: erichkeane

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

Added: 
clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3f1c86cdc3aca..e78167bad589e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -123,6 +123,11 @@ Bug Fixes
   a lambda expression that shares the name of a variable in a containing
   if/while/for/switch init statement as a redeclaration.
   This fixes `Issue 54913 
`_.
+- Overload resolution for constrained function templates could use the partial
+  order of constraints to select an overload, even if the parameter types of
+  the functions were 
diff erent. It now diagnoses this case correctly as an
+  ambiguous call and an error. Fixes
+  `Issue 53640 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 9093bb39e9e86..114725498c982 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3580,7 +3580,8 @@ class Sema final {
 QualType& ConvertedType);
   bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos = nullptr);
+  unsigned *ArgPos = nullptr,
+  bool Reversed = false);
   void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag,
   QualType FromType, QualType ToType);
 
@@ -8749,7 +8750,8 @@ class Sema final {
   FunctionTemplateDecl *getMoreSpecializedTemplate(
   FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc,
   TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1,
-  unsigned NumCallArguments2, bool Reversed = false);
+  unsigned NumCallArguments2, bool Reversed = false,
+  bool AllowOrderingByConstraints = true);
   UnresolvedSetIterator
   getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd,
  TemplateSpecCandidateSet &FailedCandidates,

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 1add971a81a02..6e45fdfbeb089 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -2945,24 +2945,30 @@ void Sema::HandleFunctionTypeMismatch(PartialDiagnostic 
&PDiag,
 }
 
 /// FunctionParamTypesAreEqual - This routine checks two function proto types
-/// for equality of their argument types. Caller has already checked that
-/// they have same number of arguments.  If the parameters are 
diff erent,
+/// for equality of their parameter types. Caller has already checked that
+/// they have same number of parameters.  If the parameters are 
diff erent,
 /// ArgPos will have the parameter index of the first 
diff erent parameter.
+/// If `Reversed` is true, the parameters of `NewType` will be compared in
+/// reverse order. That's useful if one of the functions is being used as a 
C++20
+/// synthesized operator overload with a reversed parameter order.
 bool Sema::FunctionParamTypesAreEqual(const FunctionProtoType *OldType,
   const FunctionProtoType *NewType,
-  unsigned *ArgPos) {
-  for (FunctionProtoType::param_type_iterator O = OldType->param_type_begin(),
-  N = NewType->param_type_begin(),
-  E = OldType->param_type_end();
-   O && (O != E); ++O, ++N) {
+  unsigned *ArgPos, bool Reversed) {
+  assert(OldType->getNumParams() == NewType->getNumParams() &&
+ "Can't compare parameters of

[clang] 0b89d1d - [Sema] Add deprecation warnings for some compiler provided __has_* type traits

2022-07-12 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-07-12T19:24:17+03:00
New Revision: 0b89d1d59f82cf5b45c250cd5c3351e43ce35ef9

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

LOG: [Sema] Add deprecation warnings for some compiler provided __has_* type 
traits

Some compiler provided type traits like __has_trivial_constructor have been 
documented
as deprecated for quite some time.
Still, some people apparently still use them, even though mixing them with 
concepts
and with deleted functions leads to weird results. There's also disagreement 
about some
edge cases between GCC (which Clang claims to follow) and MSVC.

This patch adds deprecation warnings for the usage of those builtins, except 
for __has_trivial_destructor
which doesn't have a GCC alternative.

I made the warning on by default, so I had to silence it for some tests but 
it's not too many.

Some (decade old) history of issues with those builtins:
https://github.com/llvm/llvm-project/issues/18187
https://github.com/llvm/llvm-project/issues/18559
https://github.com/llvm/llvm-project/issues/22161
https://github.com/llvm/llvm-project/issues/33063

The abseil usage of them that triggered me to add this warning:
https://github.com/abseil/abseil-cpp/issues/1201

Weird interaction of those builtins with C++20's conditionally trivial special 
member functions:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106085

Reviewed By: #clang-language-wg, aaron.ballman

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

Added: 
clang/test/SemaCXX/deprecated-builtins.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CXX/dcl.decl/dcl.init/p5.cpp
clang/test/CXX/drs/dr18xx.cpp
clang/test/CXX/drs/dr21xx.cpp
clang/test/CXX/special/class.copy/p12-0x.cpp
clang/test/CXX/special/class.copy/p25-0x.cpp
clang/test/CXX/special/class.ctor/p5-0x.cpp
clang/test/Modules/cxx-decls.cpp
clang/test/SemaCXX/cxx0x-defaulted-functions.cpp
clang/test/SemaCXX/cxx11-crashes.cpp
clang/test/SemaCXX/sizeless-1.cpp
clang/test/SemaCXX/trivial-constructor.cpp
clang/test/SemaCXX/trivial-destructor.cpp
clang/test/SemaCXX/type-traits.cpp
clang/test/SemaObjCXX/arc-type-traits.mm
clang/test/SemaObjCXX/objc-weak-type-traits.mm

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f7f5b8d50eb63..f8977d5ac720b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -312,6 +312,10 @@ Non-comprehensive list of changes in this release
   - ASAN_OPTIONS=detect_stack_use_after_return=1 (only on Linux).
   - MSAN_OPTIONS=poison_in_dtor=1.
 
+- Some type-trait builtins, such as ``__has_trivial_assign``, have been 
documented
+  as deprecated for a while because their semantics don't mix well with 
post-C++11 type-traits.
+  Clang now emits deprecation warnings for them under the flag 
``-Wdeprecated-builtins``.
+
 New Compiler Flags
 --
 - Added the ``-fno-knr-functions`` flag to allow users to opt into the C2x

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 0c9646e525e50..53e246a39ed86 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -188,6 +188,7 @@ def UnguardedAvailability : 
DiagGroup<"unguarded-availability",
 def : DiagGroup<"partial-availability", [UnguardedAvailability]>;
 def DeprecatedDynamicExceptionSpec
 : DiagGroup<"deprecated-dynamic-exception-spec">;
+def DeprecatedBuiltins : DiagGroup<"deprecated-builtins">;
 def DeprecatedImplementations :DiagGroup<"deprecated-implementations">;
 def DeprecatedIncrementBool : DiagGroup<"deprecated-increment-bool">;
 def DeprecatedRegister : DiagGroup<"deprecated-register">;
@@ -210,6 +211,7 @@ def Deprecated : DiagGroup<"deprecated", 
[DeprecatedAnonEnumEnumConversion,
   DeprecatedEnumCompareConditional,
   DeprecatedEnumEnumConversion,
   DeprecatedEnumFloatConversion,
+  DeprecatedBuiltins,
   DeprecatedIncrementBool,
   DeprecatedPragma,
   DeprecatedRegister,

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0d25c718d09e9..ca6390a02ce82 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5562,6 +5562,9 @@ def warn_d

[clang] 202b327 - [DOC] Add DR1734 and DR1496 Clang's cxx_dr_status as not implemented

2022-07-13 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-07-14T00:48:35+03:00
New Revision: 202b327f5d293a6f795a01933835b5ad53d8ed42

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

LOG: [DOC] Add DR1734 and DR1496 Clang's cxx_dr_status as not implemented

Those two DRs about the (copy) triviality of types with deleted special member 
functions are not implemented in Clang.
Document them as such.

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/test/CXX/drs/dr14xx.cpp
clang/test/CXX/drs/dr17xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr14xx.cpp b/clang/test/CXX/drs/dr14xx.cpp
index 06fcc190784d9..526211c0e0062 100644
--- a/clang/test/CXX/drs/dr14xx.cpp
+++ b/clang/test/CXX/drs/dr14xx.cpp
@@ -501,4 +501,16 @@ namespace dr1495 { // dr1495: 4
   template int c<0, Ts...>; // expected-error {{not more 
specialized}}
 #endif
 }
+
+namespace dr1496 { // dr1496: no
+#if __cplusplus >= 201103L
+struct A {
+A() = delete;
+};
+// FIXME: 'A' should not be trivial because the class lacks at least one
+// default constructor which is not deleted.
+static_assert(__is_trivial(A), "");
+#endif
+}
+
 #endif

diff  --git a/clang/test/CXX/drs/dr17xx.cpp b/clang/test/CXX/drs/dr17xx.cpp
index c8648908ebda9..addf1d274e91b 100644
--- a/clang/test/CXX/drs/dr17xx.cpp
+++ b/clang/test/CXX/drs/dr17xx.cpp
@@ -27,6 +27,18 @@ namespace dr1715 { // dr1715: 3.9
 #endif
 }
 
+namespace dr1734 { // dr1734: no
+#if __cplusplus >= 201103L
+struct A {
+A(const A&) = delete;
+};
+// FIXME: 'A' should not be trivially copyable because the class lacks at least
+// one non-deleted copy constructor, move constructor, copy assignment
+// operator, or move assignment operator.
+static_assert(__is_trivially_copyable(A), "");
+#endif
+}
+
 namespace dr1736 { // dr1736: 3.9
 #if __cplusplus >= 201103L
 struct S {

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index e437da1bfda99..466f287c75d90 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -8790,7 +8790,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg1496";>1496
 CD4
 Triviality with deleted and missing default constructors
-Unknown
+No
   
   
 https://wg21.link/cwg1497";>1497
@@ -10218,7 +10218,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg1734";>1734
 CD4
 Nontrivial deleted copy functions
-Unknown
+No
   
   
 https://wg21.link/cwg1735";>1735



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


[clang] 64f0f7e - __has_trivial_copy should map to __is_trivially_copyable

2022-08-13 Thread Roy Jacobson via cfe-commits

Author: Zachary Henkel
Date: 2022-08-13T22:54:52+03:00
New Revision: 64f0f7e6460019a38fe2f1cbe4b9446a3268af18

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

LOG:  __has_trivial_copy should map to __is_trivially_copyable

Found during clang 15 RC1 testing due to the new diagnostic added by 
@royjacobson since clang 14.  Uncertain if this fix meets the bar to also be 
applied to the release branch.

If accepted, I'll need someone with commit access to submit on my behalf.

Reviewed By: royjacobson, aaron.ballman, erichkeane

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

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/deprecated-builtins.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3adf0a12fc4c3..0e8028d2cc066 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1373,7 +1373,7 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__has_trivial_move_assign`` (GNU, Microsoft):
   Deprecated, use ``__is_trivially_assignable`` instead.
 * ``__has_trivial_copy`` (GNU, Microsoft):
-  Deprecated, use ``__is_trivially_constructible`` instead.
+  Deprecated, use ``__is_trivially_copyable`` instead.
 * ``__has_trivial_constructor`` (GNU, Microsoft):
   Deprecated, use ``__is_trivially_constructible`` instead.
 * ``__has_trivial_move_constructor`` (GNU, Microsoft):

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index e3e2df03a5025..c43c9dc21bd5e 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5412,6 +5412,8 @@ void DiagnoseBuiltinDeprecation(Sema& S, TypeTrait Kind,
   Replacement = BTT_IsTriviallyAssignable;
   break;
 case UTT_HasTrivialCopy:
+  Replacement = UTT_IsTriviallyCopyable;
+  break;
 case UTT_HasTrivialDefaultConstructor:
 case UTT_HasTrivialMoveConstructor:
   Replacement = TT_IsTriviallyConstructible;

diff  --git a/clang/test/SemaCXX/deprecated-builtins.cpp 
b/clang/test/SemaCXX/deprecated-builtins.cpp
index 2bb687c1ef129..849b9b014fff2 100644
--- a/clang/test/SemaCXX/deprecated-builtins.cpp
+++ b/clang/test/SemaCXX/deprecated-builtins.cpp
@@ -11,7 +11,7 @@ void f() {
 a = __has_nothrow_constructor(A);  // expected-warning-re 
{{__has_nothrow_constructor {{.*}} use __is_nothrow_constructible}}
 a = __has_trivial_assign(A);  // expected-warning-re 
{{__has_trivial_assign {{.*}} use __is_trivially_assignable}}
 a = __has_trivial_move_assign(A);  // expected-warning-re 
{{__has_trivial_move_assign {{.*}} use __is_trivially_assignable}}
-a = __has_trivial_copy(A);  // expected-warning-re {{__has_trivial_copy 
{{.*}} use __is_trivially_constructible}}
+a = __has_trivial_copy(A);  // expected-warning-re {{__has_trivial_copy 
{{.*}} use __is_trivially_copyable}}
 a = __has_trivial_constructor(A);  // expected-warning-re 
{{__has_trivial_constructor {{.*}} use __is_trivially_constructible}}
 a = __has_trivial_move_constructor(A);  // expected-warning-re 
{{__has_trivial_move_constructor {{.*}} use __is_trivially_constructible}}
 a = __has_trivial_destructor(A);  // expected-warning-re 
{{__has_trivial_destructor {{.*}} use __is_trivially_destructible}}



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


[clang] 68786f0 - [Sema] Fix friend destructor declarations after D130936

2022-08-16 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-08-16T22:28:19+03:00
New Revision: 68786f06327519b30ab3ee2ba27451ec051bbb6f

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

LOG: [Sema] Fix friend destructor declarations after D130936

I accidentally broke friend destructor declarations in D130936.

Modify it to skip performing the destructor name check if we have a dependent 
friend declaration.

Reviewed By: hubert.reinterpretcast

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

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/member-class-11.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 94009d33fa94e..7e7433d13d002 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11514,16 +11514,25 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 if (CXXConstructorDecl *Constructor = dyn_cast(NewFD)) 
{
   CheckConstructor(Constructor);
 } else if (CXXDestructorDecl *Destructor =
-dyn_cast(NewFD)) {
-  CXXRecordDecl *Record = Destructor->getParent();
-  QualType ClassType = Context.getTypeDeclType(Record);
-
-  DeclarationName Name = Context.DeclarationNames.getCXXDestructorName(
-  Context.getCanonicalType(ClassType));
-  if (NewFD->getDeclName() != Name) {
-Diag(NewFD->getLocation(), diag::err_destructor_name);
-NewFD->setInvalidDecl();
-return Redeclaration;
+   dyn_cast(NewFD)) {
+  // We check here for invalid destructor names.
+  // If we have a friend destructor declaration that is dependent, we can't
+  // diagnose right away because cases like this are still valid:
+  // template  struct A { friend T::X::~Y(); };
+  // struct B { struct Y { ~Y(); }; using X = Y; };
+  // template struct A;
+  if (NewFD->getFriendObjectKind() == Decl::FriendObjectKind::FOK_None ||
+  !Destructor->getThisType()->isDependentType()) {
+CXXRecordDecl *Record = Destructor->getParent();
+QualType ClassType = Context.getTypeDeclType(Record);
+
+DeclarationName Name = Context.DeclarationNames.getCXXDestructorName(
+Context.getCanonicalType(ClassType));
+if (NewFD->getDeclName() != Name) {
+  Diag(NewFD->getLocation(), diag::err_destructor_name);
+  NewFD->setInvalidDecl();
+  return Redeclaration;
+}
   }
 } else if (auto *Guide = dyn_cast(NewFD)) {
   if (auto *TD = Guide->getDescribedFunctionTemplate())

diff  --git a/clang/test/SemaCXX/member-class-11.cpp 
b/clang/test/SemaCXX/member-class-11.cpp
index 68873ebad9d1d..20d6bce954f19 100644
--- a/clang/test/SemaCXX/member-class-11.cpp
+++ b/clang/test/SemaCXX/member-class-11.cpp
@@ -26,4 +26,56 @@ struct C {
   ~B(); // expected-error {{expected the class name after '~' to name the 
enclosing class}}
 };
 
+template 
+struct D {
+  friend T::S::~S();
+private:
+  static constexpr int secret = 42;
+};
+
+template 
+struct E {
+  friend T::S::~V();
+};
+
+struct BadInstantiation {
+  struct S {
+struct V {};
+  };
+};
+
+struct GoodInstantiation {
+  struct V {
+~V();
+  };
+  using S = V;
+};
+
+// FIXME: We should diagnose this while instantiating.
+E x;
+E y;
+
+struct Q {
+  struct S { ~S(); };
+};
+
+Q::S::~S() {
+  void foo(int);
+  foo(D::secret);
+}
+
+struct X {
+  ~X();
+};
+struct Y;
+
+struct Z1 {
+  friend X::~Y(); // expected-error {{expected the class name after '~' to 
name the enclosing class}}
+};
+
+template 
+struct Z2 {
+  friend X::~Y(); // expected-error {{expected the class name after '~' to 
name the enclosing class}}
+};
+
 }



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


[clang] 7171615 - [Clang] Implement P0848 (Conditionally Trivial Special Member Functions)

2022-08-23 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-08-23T21:48:42+03:00
New Revision: 7171615099142ed49042c0f27af437b05150dd9b

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

LOG: [Clang] Implement P0848 (Conditionally Trivial Special Member Functions)

This patch implements P0848 in Clang.

During the instantiation of a C++ class, in `Sema::ActOnFields`, we evaluate 
constraints for all the SMFs and compare the constraints to compute the 
eligibility. We defer the computation of the type's [copy-]trivial bits from 
addedMember to the eligibility computation, like we did for destructors in 
D126194. `canPassInRegisters` is modified as well to better respect the 
ineligibility of functions.

Note: Because of the non-implementation of DR1734 and DR1496, I treat deleted 
member functions as 'eligible' for the purpose of [copy-]triviallity. This is 
unfortunate, but I couldn't think of a way to make this make sense otherwise.

Reviewed By: #clang-language-wg, cor3ntin, aaron.ballman

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

Added: 
clang/test/AST/conditionally-trivial-smfs.cpp
clang/test/SemaCXX/constrained-special-member-functions.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/DeclCXX.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 64a2ce2bb2b8b..90cb8a60d3ace 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -162,6 +162,10 @@ C++20 Feature Support
   (C++14 [dcl.constexpr]p6 (CWG DR647/CWG DR1358))
 - Correctly defer dependent immediate function invocations until template 
instantiation.
   This fixes `GH55601 `_.
+- Implemented "Conditionally Trivial Special Member Functions" (`P0848 
`_).
+  Note: The handling of deleted functions is not yet compliant, as Clang
+  does not implement `DR1496 
`_
+  and `DR1734 
`_.
 
 
 

diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 38c46b112b803..4e259df1b95e1 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -894,9 +894,11 @@ void CXXRecordDecl::addedMember(Decl *D) {
 // This is an extension in C++03.
 data().PlainOldData = false;
   }
-  // We delay updating destructor relevant properties until
-  // addedSelectedDestructor.
-  // FIXME: Defer this for the other special member functions as well.
+  // When instantiating a class, we delay updating the destructor and
+  // triviality properties of the class until selecting a destructor and
+  // computing the eligibility of its special member functions. This is
+  // because there might be function constraints that we need to evaluate
+  // and compare later in the instantiation.
   if (!Method->isIneligibleOrNotSelected()) {
 addedEligibleSpecialMemberFunction(Method, SMKind);
   }
@@ -1437,10 +1439,12 @@ void 
CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) {
 
   // Update which trivial / non-trivial special members we have.
   // addedMember will have skipped this step for this member.
-  if (D->isTrivial())
-data().HasTrivialSpecialMembers |= SMKind;
-  else
-data().DeclaredNonTrivialSpecialMembers |= SMKind;
+  if (!D->isIneligibleOrNotSelected()) {
+if (D->isTrivial())
+  data().HasTrivialSpecialMembers |= SMKind;
+else
+  data().DeclaredNonTrivialSpecialMembers |= SMKind;
+  }
 }
 
 void CXXRecordDecl::setCaptures(ASTContext &Context,

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 20bfbf144a30a..eff811e113e5e 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -674,6 +674,9 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
   // C++20 features.
   if (LangOpts.CPlusPlus20) {
 //Builder.defineMacro("__cpp_aggregate_paren_init", "201902L");
+// P0848 is implemented, but we're still waiting for other concepts
+// issues to be addressed before bumping __cpp_concepts up to 202002L.
+// Refer to the discussion of this at https://reviews.llvm.org/D128619.
 Builder.defineMacro("__cpp_concepts", "201907L");
 Builder.defineMacro("__cpp_conditional_explicit", "201806L");
 //Builder.defineMacro("__cpp_consteval", "201811L");

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sem

[clang] 70770a1 - Revert "[Clang] Implement P0848 (Conditionally Trivial Special Member Functions)"

2022-08-24 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-08-25T09:11:06+03:00
New Revision: 70770a16bcfa70b2a4b38d55ab8097f9f92c2326

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

LOG: Revert "[Clang] Implement P0848 (Conditionally Trivial Special Member 
Functions)"

See bug report here: https://github.com/llvm/llvm-project/issues/57351
This reverts commit 7171615099142ed49042c0f27af437b05150dd9b.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/DeclCXX.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/www/cxx_status.html

Removed: 
clang/test/AST/conditionally-trivial-smfs.cpp
clang/test/SemaCXX/constrained-special-member-functions.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6109f4e8ac6bc..46339ff9ce8d1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -167,10 +167,6 @@ C++20 Feature Support
   (C++14 [dcl.constexpr]p6 (CWG DR647/CWG DR1358))
 - Correctly defer dependent immediate function invocations until template 
instantiation.
   This fixes `GH55601 `_.
-- Implemented "Conditionally Trivial Special Member Functions" (`P0848 
`_).
-  Note: The handling of deleted functions is not yet compliant, as Clang
-  does not implement `DR1496 
`_
-  and `DR1734 
`_.
 
 
 

diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 4e259df1b95e1..38c46b112b803 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -894,11 +894,9 @@ void CXXRecordDecl::addedMember(Decl *D) {
 // This is an extension in C++03.
 data().PlainOldData = false;
   }
-  // When instantiating a class, we delay updating the destructor and
-  // triviality properties of the class until selecting a destructor and
-  // computing the eligibility of its special member functions. This is
-  // because there might be function constraints that we need to evaluate
-  // and compare later in the instantiation.
+  // We delay updating destructor relevant properties until
+  // addedSelectedDestructor.
+  // FIXME: Defer this for the other special member functions as well.
   if (!Method->isIneligibleOrNotSelected()) {
 addedEligibleSpecialMemberFunction(Method, SMKind);
   }
@@ -1439,12 +1437,10 @@ void 
CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) {
 
   // Update which trivial / non-trivial special members we have.
   // addedMember will have skipped this step for this member.
-  if (!D->isIneligibleOrNotSelected()) {
-if (D->isTrivial())
-  data().HasTrivialSpecialMembers |= SMKind;
-else
-  data().DeclaredNonTrivialSpecialMembers |= SMKind;
-  }
+  if (D->isTrivial())
+data().HasTrivialSpecialMembers |= SMKind;
+  else
+data().DeclaredNonTrivialSpecialMembers |= SMKind;
 }
 
 void CXXRecordDecl::setCaptures(ASTContext &Context,

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index eff811e113e5e..20bfbf144a30a 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -674,9 +674,6 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
   // C++20 features.
   if (LangOpts.CPlusPlus20) {
 //Builder.defineMacro("__cpp_aggregate_paren_init", "201902L");
-// P0848 is implemented, but we're still waiting for other concepts
-// issues to be addressed before bumping __cpp_concepts up to 202002L.
-// Refer to the discussion of this at https://reviews.llvm.org/D128619.
 Builder.defineMacro("__cpp_concepts", "201907L");
 Builder.defineMacro("__cpp_conditional_explicit", "201806L");
 //Builder.defineMacro("__cpp_consteval", "201811L");

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index ef59ecebb70ac..88939597c454b 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -17968,6 +17968,7 @@ void Sema::ActOnLastBitfield(SourceLocation DeclLoc,
   AllIvarDecls.push_back(Ivar);
 }
 
+namespace {
 /// [class.dtor]p4:
 ///   At the end of the definition of a class, overload resolution is
 ///   performed among the prospective destructors declared in that class with
@@ -17976,7 +17977,7 @@ void Sema::ActOnLastBitfield(SourceLocation DeclLoc,
 ///
 /// We do the overload resolution here, then mark the selected constructor in 
the AST.
 /// Later CXXRecordDecl::getDestructor() will return the s

[clang] b1c960f - [Clang] Implement P0848 (Conditionally Trivial Special Member Functions)

2022-08-25 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-08-26T00:52:52+03:00
New Revision: b1c960fc6dc2891c8d2ca09c184572ca0857ba15

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

LOG: [Clang] Implement P0848 (Conditionally Trivial Special Member Functions)

This patch implements P0848 in Clang.

During the instantiation of a C++ class, in `Sema::ActOnFields`, we evaluate 
constraints for all the SMFs and compare the constraints to compute the 
eligibility. We defer the computation of the type's [copy-]trivial bits from 
addedMember to the eligibility computation, like we did for destructors in 
D126194. `canPassInRegisters` is modified as well to better respect the 
ineligibility of functions.

Note: Because of the non-implementation of DR1734 and DR1496, I treat deleted 
member functions as 'eligible' for the purpose of [copy-]triviallity. This is 
unfortunate, but I couldn't think of a way to make this make sense otherwise.

Reviewed By: #clang-language-wg, cor3ntin, aaron.ballman

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

Added: 
clang/test/AST/conditionally-trivial-smfs-2.cpp
clang/test/AST/conditionally-trivial-smfs.cpp
clang/test/SemaCXX/constrained-special-member-functions.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/DeclCXX.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d40f56f3f3891..6f4747ddd1199 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -167,6 +167,10 @@ C++20 Feature Support
   (C++14 [dcl.constexpr]p6 (CWG DR647/CWG DR1358))
 - Correctly defer dependent immediate function invocations until template 
instantiation.
   This fixes `GH55601 `_.
+- Implemented "Conditionally Trivial Special Member Functions" (`P0848 
`_).
+  Note: The handling of deleted functions is not yet compliant, as Clang
+  does not implement `DR1496 
`_
+  and `DR1734 
`_.
 
 
 

diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 38c46b112b803..4e259df1b95e1 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -894,9 +894,11 @@ void CXXRecordDecl::addedMember(Decl *D) {
 // This is an extension in C++03.
 data().PlainOldData = false;
   }
-  // We delay updating destructor relevant properties until
-  // addedSelectedDestructor.
-  // FIXME: Defer this for the other special member functions as well.
+  // When instantiating a class, we delay updating the destructor and
+  // triviality properties of the class until selecting a destructor and
+  // computing the eligibility of its special member functions. This is
+  // because there might be function constraints that we need to evaluate
+  // and compare later in the instantiation.
   if (!Method->isIneligibleOrNotSelected()) {
 addedEligibleSpecialMemberFunction(Method, SMKind);
   }
@@ -1437,10 +1439,12 @@ void 
CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) {
 
   // Update which trivial / non-trivial special members we have.
   // addedMember will have skipped this step for this member.
-  if (D->isTrivial())
-data().HasTrivialSpecialMembers |= SMKind;
-  else
-data().DeclaredNonTrivialSpecialMembers |= SMKind;
+  if (!D->isIneligibleOrNotSelected()) {
+if (D->isTrivial())
+  data().HasTrivialSpecialMembers |= SMKind;
+else
+  data().DeclaredNonTrivialSpecialMembers |= SMKind;
+  }
 }
 
 void CXXRecordDecl::setCaptures(ASTContext &Context,

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 20bfbf144a30a..162cc264f99cc 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -673,7 +673,11 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
 
   // C++20 features.
   if (LangOpts.CPlusPlus20) {
-//Builder.defineMacro("__cpp_aggregate_paren_init", "201902L");
+// Builder.defineMacro("__cpp_aggregate_paren_init", "201902L");
+
+// P0848 is implemented, but we're still waiting for other concepts
+// issues to be addressed before bumping __cpp_concepts up to 202002L.
+// Refer to the discussion of this at https://reviews.llvm.org/D128619.
 Builder.defineMacro("__cpp_concepts", "201907L");
 Builder.defineMacro("__cpp_conditional_explicit", "

[clang] 368b683 - [Clang] Implement fix for DR2628

2022-09-19 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-09-20T00:07:41+03:00
New Revision: 368b6832de33b366d4eb155f940e7476daace6a8

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

LOG: [Clang] Implement fix for DR2628

Implement suggested fix for [[ https://cplusplus.github.io/CWG/issues/2628.html 
| DR2628. ]] Couldn't update the DR docs because there hasn't been a DR index 
since it was filed, but the tests still run in CI.

Note: I only transfer the constructor constraints, not the struct constraints. 
I think that's OK because the struct constraints are the same
for all constructors so they don't affect the overload resolution, and if they 
deduce to something that doesn't pass the constraints
we catch it anyway. So (hopefully) that should be more efficient without 
sacrificing correctness.

Closes:
https://github.com/llvm/llvm-project/issues/57646
https://github.com/llvm/llvm-project/issues/43829

Reviewed By: erichkeane

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

Added: 
clang/test/CXX/drs/dr26xx.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplate.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2546142d2b3d7..96b0c7e363052 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -151,6 +151,10 @@ Bug Fixes
   `Issue 57369 `_
   `Issue 57643 `_
   `Issue 57793 `_
+- Respect constructor constraints during class template argument deduction 
(CTAD).
+  This is the suggested resolution to CWG DR2628.
+  `Issue 57646 `_
+  `Issue 43829 `_
 
 
 Improvements to Clang's diagnostics

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index e0f913e395771..2ab59e7a37c0d 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2445,6 +2445,8 @@ struct ConvertConstructorToDeductionGuideTransform {
   TInfo->getType(), TInfo, LocEnd, Ctor);
 Guide->setImplicit();
 Guide->setParams(Params);
+if (Ctor && Ctor->getTrailingRequiresClause())
+  Guide->setTrailingRequiresClause(Ctor->getTrailingRequiresClause());
 
 for (auto *Param : Params)
   Param->setDeclContext(Guide);

diff  --git a/clang/test/CXX/drs/dr26xx.cpp b/clang/test/CXX/drs/dr26xx.cpp
new file mode 100644
index 0..1178cefa5bcdf
--- /dev/null
+++ b/clang/test/CXX/drs/dr26xx.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
+
+namespace dr2628 { // dr2628: yes
+
+template 
+struct foo {
+  constexpr foo() requires (!A && !B) = delete; // #DR2628_CTOR
+  constexpr foo() requires (A || B) = delete;
+};
+
+void f() {
+  foo fooable; // expected-error {{call to deleted}}
+  // expected-note@#DR2628_CTOR {{marked deleted here}}
+}
+
+}



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


[clang] 013012b - [Clang][NFC] Add missing feature macros to lexer test

2022-09-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-09-29T21:16:29+03:00
New Revision: 013012b99a5448f067cfdce8dd07cf503a6172a7

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

LOG: [Clang][NFC] Add missing feature macros to lexer test

Added: 


Modified: 
clang/test/Lexer/cxx-features.cpp

Removed: 




diff  --git a/clang/test/Lexer/cxx-features.cpp 
b/clang/test/Lexer/cxx-features.cpp
index 6b6729df15bd1..1963b1dc43a6f 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -39,6 +39,26 @@
 #error "wrong value for __cpp_size_t_suffix"
 #endif
 
+#if check(if_consteval, 0, 0, 0, 0, 0, 202106)
+#error "wrong value for __cpp_if_consteval"
+#endif
+
+#if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202110)
+#error "wrong value for __cpp_multidimensional_subscript"
+#endif
+
+#if check(static_call_operator, 0, 0, 0, 0, 0, 0)
+#error "wrong value for __cpp_static_call_operator"
+#endif
+
+#if check(named_character_escapes, 0, 0, 0, 0, 0, 0)
+#error "wrong value for __cpp_named_character_escapes"
+#endif
+
+#if check(explicit_this_parameter, 0, 0, 0, 0, 0, 0)
+#error "wrong value for __cpp_explicit_this_parameter"
+#endif
+
 // --- C++20 features ---
 
 #if check(aggregate_paren_init, 0, 0, 0, 0, 0, 0)



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


[clang] 6523814 - [Clang] P1169R4: static operator()

2022-09-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-09-29T23:03:26+03:00
New Revision: 6523814c4e38ad70f8fd3fc3c39d089195e099a1

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

LOG: [Clang] P1169R4: static operator()

Implements 'P1169R4: static operator()' from C++2b.

Reviewed By: #clang-language-wg, aaron.ballman

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

Added: 
clang/test/CXX/over/over.match/over.match.best/over.best.ics/p6.cpp
clang/test/CXX/over/over.oper/p7.cpp
clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
clang/test/Parser/cxx2b-lambdas-ext-warns.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/OperatorKinds.def
clang/include/clang/Sema/DeclSpec.h
clang/include/clang/Sema/Overload.h
clang/include/clang/Sema/Sema.h
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/TreeTransform.h
clang/test/Lexer/cxx-features.cpp
clang/test/Parser/cxx2b-lambdas.cpp
clang/test/SemaCXX/lambda-unevaluated.cpp
clang/test/SemaCXX/overloaded-operator-decl.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f464439f7832a..ed5b4a2f031db 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -409,6 +409,7 @@ C++2b Feature Support
 ^
 
 - Support label at end of compound statement (`P2324 
`_).
+- Implemented `P1169R4: static operator() `_.
 
 CUDA/HIP Language Changes in Clang
 --

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index b5ef572ab71bc..d3605d9bcba7d 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1004,7 +1004,8 @@ def warn_cxx98_compat_lambda : Warning<
   "lambda expressions are incompatible with C++98">,
   InGroup, DefaultIgnore;
 def err_lambda_decl_specifier_repeated : Error<
-  "%select{'mutable'|'constexpr'|'consteval'}0 cannot appear multiple times in 
a lambda declarator">;
+  "%select{'mutable'|'static'|'constexpr'|'consteval'}0 cannot "
+  "appear multiple times in a lambda declarator">;
 def err_lambda_capture_misplaced_ellipsis : Error<
   "ellipsis in pack %select{|init-}0capture must appear %select{after|before}0 
"
   "the name of the capture">;
@@ -1043,6 +1044,17 @@ def warn_cxx17_compat_lambda_template_parameter_list: 
Warning<
 def err_lambda_template_parameter_list_empty : Error<
   "lambda template parameter list cannot be empty">;
 
+// C++2b static lambdas
+def err_static_lambda: ExtWarn<
+  "static lambdas are a C++2b extension">, InGroup;
+def warn_cxx20_compat_static_lambda: ExtWarn<
+  "static lambdas are incompatible with C++ standards before C++2b">,
+  InGroup, DefaultIgnore;
+def err_static_mutable_lambda : Error<
+  "lambda cannot be both mutable and static">;
+def err_static_lambda_captures : Error<
+  "a static lambda cannot have any captures">;
+
 // Availability attribute
 def err_expected_version : Error<
   "expected a version of the form 'major[.minor[.subminor]]'">;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 62afa66ca320d..a3e20d0d683d4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9087,6 +9087,11 @@ def err_operator_overload_needs_class_or_enum : Error<
   "or enumeration type">;
 
 def err_operator_overload_variadic : Error<"overloaded %0 cannot be variadic">;
+def ext_operator_overload_static : ExtWarn<
+  "declaring overloaded %0 as 'static' is a C++2b extension">,
+  InGroup, DefaultIgnore;
+def err_call_operator_overload_static : ExtWarn<
+  "declaring overloaded %0 as 'static' is a C++2b extension">, InGroup;
 def err_operator_overload_static : Error<
   "overloaded %0 cannot be a static member function">;
 def err_operator_overload_default_arg : Error<

diff  --git a/clang/include/clang/Basic/OperatorKinds.def 
b/clang/include/clang/Basic/OperatorKinds.def
index d464db29274e1..fab777349ede7 100644
--- a/clang/include/clang/Basic/OperatorKinds.def
+++ b/clang/include/clang/Basic/OperatorKinds.def
@@ -38,8 +38,8 @@
 /// "operator*") can be both unary and binary.
 ///
 /// MemberOnly: True if this operator can only be d

[clang] 8a1e069 - [Clang][NFC] Fix broken link in release notes

2022-09-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-09-29T23:16:17+03:00
New Revision: 8a1e069cc479e501b058bdb1a3d961ee6f852c3d

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

LOG: [Clang][NFC] Fix broken link in release notes

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ed5b4a2f031d..0237a3c4e1b2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -368,7 +368,7 @@ C++ Language Changes in Clang
 C++20 Feature Support
 ^
 - Support capturing structured bindings in lambdas
-  (`P1091R3 `_ and `P1381R1 
`).
+  (`P1091R3 `_ and `P1381R1 
`_).
   This fixes issues `Issue 52720 
`_,
   `Issue 54300 `_,
   `Issue 54301 `_,



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


[clang] 9706bb3 - [Clang] Fix variant crashes from GH58028, GH57370

2022-09-30 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-09-30T11:09:02+03:00
New Revision: 9706bb3165f5e508d5e2247ad8a3f45077df546d

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

LOG: [Clang] Fix variant crashes from GH58028, GH57370

Fixes a null dereference in some diagnostic issuing code.

Closes https://github.com/llvm/llvm-project/issues/57370
Closes https://github.com/llvm/llvm-project/issues/58028

Reviewed By: shafik

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

Added: 
clang/test/SemaCXX/specialization-diagnose-crash.cpp

Modified: 
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 7097b9deb8ed6..ee6fee0ac7324 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -695,10 +695,10 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
 //   member of reference type uninitialized, the program is
 //   ill-formed.
 SemaRef.Diag(Loc, diag::err_init_reference_member_uninitialized)
-  << Field->getType()
-  << ILE->getSyntacticForm()->getSourceRange();
-SemaRef.Diag(Field->getLocation(),
- diag::note_uninit_reference_member);
+<< Field->getType()
+<< (ILE->isSyntacticForm() ? ILE : ILE->getSyntacticForm())
+   ->getSourceRange();
+SemaRef.Diag(Field->getLocation(), diag::note_uninit_reference_member);
   }
   hadError = true;
   return;

diff  --git a/clang/test/SemaCXX/specialization-diagnose-crash.cpp 
b/clang/test/SemaCXX/specialization-diagnose-crash.cpp
new file mode 100644
index 0..ceb3c4655f745
--- /dev/null
+++ b/clang/test/SemaCXX/specialization-diagnose-crash.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+// This is a reduction of GH57370 and GH58028, originally appearing
+// in libstdc++'s variant code.
+
+struct V1 {};
+struct V2 : V1 {
+  int &a;
+};
+
+template  using void_t = void;
+
+template  struct X { T x; };
+
+template  struct Variant {
+  Variant() = delete; // expected-note {{deleted here}}
+};
+
+template 
+struct Variant{T1()})>> {};
+
+void f() {
+  Variant();
+  Variant(); // expected-error {{call to deleted constructor}}
+}



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


[clang] bd1bb8c - [Clang] define __cpp_named_character_escapes

2022-09-30 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-09-30T11:13:18+03:00
New Revision: bd1bb8cd42548d5e50e84f52a5098eec1ee92c98

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

LOG: [Clang] define __cpp_named_character_escapes

Define the feature test macro for named character escapes.
I assume this was not done because it was implemented before formally accepted, 
right? cxx_status says the paper is implemented.

Reviewed By: cor3ntin

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

Added: 


Modified: 
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Lexer/cxx-features.cpp

Removed: 




diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 04ebeea522d65..e9bfab9e695be 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -697,10 +697,11 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
 Builder.defineMacro("__cpp_multidimensional_subscript", "202110L");
   }
 
-  // We provide this as an extension in earlier language modes, so we
-  // also define the macro.
+  // We provide those C++2b features as extensions in earlier language modes, 
so
+  // we also define their feature test macros.
   if (LangOpts.CPlusPlus11)
 Builder.defineMacro("__cpp_static_call_operator", "202207L");
+  Builder.defineMacro("__cpp_named_character_escapes", "202207L");
 
   if (LangOpts.Char8)
 Builder.defineMacro("__cpp_char8_t", "201811L");

diff  --git a/clang/test/Lexer/cxx-features.cpp 
b/clang/test/Lexer/cxx-features.cpp
index d1c9f0d2b2aee..ee52017a2201e 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -51,7 +51,7 @@
 #error "wrong value for __cpp_static_call_operator"
 #endif
 
-#if check(named_character_escapes, 0, 0, 0, 0, 0, 0)
+#if check(named_character_escapes, 202207, 202207, 202207, 202207, 202207, 
202207)
 #error "wrong value for __cpp_named_character_escapes"
 #endif
 



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


[clang] 894c0e9 - Revert "[Clang] Fix variant crashes from GH58028, GH57370"

2022-09-30 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-09-30T11:24:46+03:00
New Revision: 894c0e94f9c62413feef88fd577c430839abaea7

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

LOG: Revert "[Clang] Fix variant crashes from GH58028, GH57370"

This reverts commit 9706bb3165f5e508d5e2247ad8a3f45077df546d, some CI workers 
complain about the test.

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp

Removed: 
clang/test/SemaCXX/specialization-diagnose-crash.cpp



diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ee6fee0ac7324..7097b9deb8ed6 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -695,10 +695,10 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
 //   member of reference type uninitialized, the program is
 //   ill-formed.
 SemaRef.Diag(Loc, diag::err_init_reference_member_uninitialized)
-<< Field->getType()
-<< (ILE->isSyntacticForm() ? ILE : ILE->getSyntacticForm())
-   ->getSourceRange();
-SemaRef.Diag(Field->getLocation(), diag::note_uninit_reference_member);
+  << Field->getType()
+  << ILE->getSyntacticForm()->getSourceRange();
+SemaRef.Diag(Field->getLocation(),
+ diag::note_uninit_reference_member);
   }
   hadError = true;
   return;

diff  --git a/clang/test/SemaCXX/specialization-diagnose-crash.cpp 
b/clang/test/SemaCXX/specialization-diagnose-crash.cpp
deleted file mode 100644
index ceb3c4655f745..0
--- a/clang/test/SemaCXX/specialization-diagnose-crash.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only %s -verify
-// This is a reduction of GH57370 and GH58028, originally appearing
-// in libstdc++'s variant code.
-
-struct V1 {};
-struct V2 : V1 {
-  int &a;
-};
-
-template  using void_t = void;
-
-template  struct X { T x; };
-
-template  struct Variant {
-  Variant() = delete; // expected-note {{deleted here}}
-};
-
-template 
-struct Variant{T1()})>> {};
-
-void f() {
-  Variant();
-  Variant(); // expected-error {{call to deleted constructor}}
-}



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


[clang] 9415aad - [Clang] Fix variant crashes from GH58028, GH57370

2022-09-30 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-09-30T21:17:34+03:00
New Revision: 9415aad6a40fec74296008a25f34164a95c857f4

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

LOG: [Clang] Fix variant crashes from GH58028, GH57370

Fixes a null dereference in some diagnostic issuing code.

Closes https://github.com/llvm/llvm-project/issues/57370
Closes https://github.com/llvm/llvm-project/issues/58028

Reviewed By: shafik

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

Added: 
clang/test/SemaCXX/specialization-diagnose-crash.cpp

Modified: 
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 7097b9deb8ed6..ee6fee0ac7324 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -695,10 +695,10 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
 //   member of reference type uninitialized, the program is
 //   ill-formed.
 SemaRef.Diag(Loc, diag::err_init_reference_member_uninitialized)
-  << Field->getType()
-  << ILE->getSyntacticForm()->getSourceRange();
-SemaRef.Diag(Field->getLocation(),
- diag::note_uninit_reference_member);
+<< Field->getType()
+<< (ILE->isSyntacticForm() ? ILE : ILE->getSyntacticForm())
+   ->getSourceRange();
+SemaRef.Diag(Field->getLocation(), diag::note_uninit_reference_member);
   }
   hadError = true;
   return;

diff  --git a/clang/test/SemaCXX/specialization-diagnose-crash.cpp 
b/clang/test/SemaCXX/specialization-diagnose-crash.cpp
new file mode 100644
index 0..5fd387cab19d9
--- /dev/null
+++ b/clang/test/SemaCXX/specialization-diagnose-crash.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only %s --std=c++17 -verify
+// This is a reduction of GH57370 and GH58028, originally appearing
+// in libstdc++'s variant code.
+
+struct V1 {};
+struct V2 : V1 {
+  int &a;
+};
+
+template  using void_t = void;
+
+template  struct X { T x; };
+
+template  struct Variant {
+  Variant() = delete; // expected-note {{deleted here}}
+};
+
+template 
+struct Variant{T1()})>> {};
+
+void f() {
+  Variant();
+  Variant(); // expected-error {{call to deleted constructor}}
+}



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


[clang] d5dd37a - [Sema] Don't mark deleted special member functions as non-trivial

2023-01-04 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-01-04T21:27:04+02:00
New Revision: d5dd37ac139a74701e16f084eb2609ff58893770

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

LOG: [Sema] Don't mark deleted special member functions as non-trivial

As noted in https://github.com/llvm/llvm-project/issues/59624, we sometimes 
mark implicitly
deleted special member functions as non-trivial. This is unnecessary work and 
leads to some
weird type traits errors.

This fixes the problem by making the implicitly deleted special member 
functions always
trivial.

Reviewed By: #clang-language-wg, erichkeane

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

Added: 
clang/test/SemaCXX/GH59624.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/AST/ast-dump-funcs.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c4030387ae55e..cbf89cb342c73 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -757,6 +757,9 @@ ABI Changes in Clang
   classified such types as non-POD (for the purposes of Itanium ABI). Clang now
   matches the gcc behavior (except on Darwin and PS4). You can switch back to
   the old ABI behavior with the flag: ``-fclang-abi-compat=15.0``.
+- Some types with implicitly deleted special member functions were accidentally
+  marked as non-trivially copyable. This has been fixed
+  (`#59624 `_).
 
 OpenMP Support in Clang
 ---

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 9a80a4874b6db..19ecf21a00ccd 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -14475,11 +14475,6 @@ CXXMethodDecl 
*Sema::DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl) {
nullptr);
   CopyAssignment->setParams(FromParam);
 
-  CopyAssignment->setTrivial(
-ClassDecl->needsOverloadResolutionForCopyAssignment()
-  ? SpecialMemberIsTrivial(CopyAssignment, CXXCopyAssignment)
-  : ClassDecl->hasTrivialCopyAssignment());
-
   // Note that we have added this copy-assignment operator.
   ++getASTContext().NumImplicitCopyAssignmentOperatorsDeclared;
 
@@ -14489,6 +14484,11 @@ CXXMethodDecl 
*Sema::DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl) {
   if (ShouldDeleteSpecialMember(CopyAssignment, CXXCopyAssignment)) {
 ClassDecl->setImplicitCopyAssignmentIsDeleted();
 SetDeclDeleted(CopyAssignment, ClassLoc);
+  } else {
+CopyAssignment->setTrivial(
+ClassDecl->needsOverloadResolutionForCopyAssignment()
+? SpecialMemberIsTrivial(CopyAssignment, CXXCopyAssignment)
+: ClassDecl->hasTrivialCopyAssignment());
   }
 
   if (S)
@@ -14813,11 +14813,6 @@ CXXMethodDecl 
*Sema::DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl) {
nullptr);
   MoveAssignment->setParams(FromParam);
 
-  MoveAssignment->setTrivial(
-ClassDecl->needsOverloadResolutionForMoveAssignment()
-  ? SpecialMemberIsTrivial(MoveAssignment, CXXMoveAssignment)
-  : ClassDecl->hasTrivialMoveAssignment());
-
   // Note that we have added this copy-assignment operator.
   ++getASTContext().NumImplicitMoveAssignmentOperatorsDeclared;
 
@@ -14827,6 +14822,11 @@ CXXMethodDecl 
*Sema::DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl) {
   if (ShouldDeleteSpecialMember(MoveAssignment, CXXMoveAssignment)) {
 ClassDecl->setImplicitMoveAssignmentIsDeleted();
 SetDeclDeleted(MoveAssignment, ClassLoc);
+  } else {
+MoveAssignment->setTrivial(
+ClassDecl->needsOverloadResolutionForMoveAssignment()
+? SpecialMemberIsTrivial(MoveAssignment, CXXMoveAssignment)
+: ClassDecl->hasTrivialMoveAssignment());
   }
 
   if (S)
@@ -15197,18 +15197,6 @@ CXXConstructorDecl 
*Sema::DeclareImplicitCopyConstructor(
   /*TInfo=*/TSI, SC_None, nullptr);
   CopyConstructor->setParams(FromParam);
 
-  CopyConstructor->setTrivial(
-  ClassDecl->needsOverloadResolutionForCopyConstructor()
-  ? SpecialMemberIsTrivial(CopyConstructor, CXXCopyConstructor)
-  : ClassDecl->hasTrivialCopyConstructor());
-
-  CopyConstructor->setTrivialForCall(
-  ClassDecl->hasAttr() ||
-  (ClassDecl->needsOverloadResolutionForCopyConstructor()
-   ? SpecialMemberIsTrivial(CopyConstructor, CXXCopyConstructor,
- TAH_ConsiderTrivialABI)
-   : ClassDecl->hasTrivialCopyConstructorForCall()));
-
   // Note that we have declared this constructor.
   ++getASTContext().NumImplicitCopyConstructorsDeclared;
 
@@ -15218,6 +15206,18 @@ CXXConstructorDecl 
*Sema::DeclareImplicitCopyCon

[clang] 91fefaa - Revert "[Sema] Don't mark deleted special member functions as non-trivial"

2023-01-04 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-01-04T22:39:04+02:00
New Revision: 91fefaa62ea5bfa6b7e85214ab58aae45017365f

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

LOG: Revert "[Sema] Don't mark deleted special member functions as non-trivial"

This reverts commit d5dd37ac139a74701e16f084eb2609ff58893770.

Apparently there's some ABI difference in the Sony builder that fails a test.
Will hopefully investigate tomorrow. 
https://lab.llvm.org/buildbot/#/builders/139/builds/33769

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/AST/ast-dump-funcs.cpp

Removed: 
clang/test/SemaCXX/GH59624.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6430bf2936b55..0fe0097400823 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -754,9 +754,6 @@ ABI Changes in Clang
   classified such types as non-POD (for the purposes of Itanium ABI). Clang now
   matches the gcc behavior (except on Darwin and PS4). You can switch back to
   the old ABI behavior with the flag: ``-fclang-abi-compat=15.0``.
-- Some types with implicitly deleted special member functions were accidentally
-  marked as non-trivially copyable. This has been fixed
-  (`#59624 `_).
 
 OpenMP Support in Clang
 ---

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 19ecf21a00ccd..9a80a4874b6db 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -14475,6 +14475,11 @@ CXXMethodDecl 
*Sema::DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl) {
nullptr);
   CopyAssignment->setParams(FromParam);
 
+  CopyAssignment->setTrivial(
+ClassDecl->needsOverloadResolutionForCopyAssignment()
+  ? SpecialMemberIsTrivial(CopyAssignment, CXXCopyAssignment)
+  : ClassDecl->hasTrivialCopyAssignment());
+
   // Note that we have added this copy-assignment operator.
   ++getASTContext().NumImplicitCopyAssignmentOperatorsDeclared;
 
@@ -14484,11 +14489,6 @@ CXXMethodDecl 
*Sema::DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl) {
   if (ShouldDeleteSpecialMember(CopyAssignment, CXXCopyAssignment)) {
 ClassDecl->setImplicitCopyAssignmentIsDeleted();
 SetDeclDeleted(CopyAssignment, ClassLoc);
-  } else {
-CopyAssignment->setTrivial(
-ClassDecl->needsOverloadResolutionForCopyAssignment()
-? SpecialMemberIsTrivial(CopyAssignment, CXXCopyAssignment)
-: ClassDecl->hasTrivialCopyAssignment());
   }
 
   if (S)
@@ -14813,6 +14813,11 @@ CXXMethodDecl 
*Sema::DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl) {
nullptr);
   MoveAssignment->setParams(FromParam);
 
+  MoveAssignment->setTrivial(
+ClassDecl->needsOverloadResolutionForMoveAssignment()
+  ? SpecialMemberIsTrivial(MoveAssignment, CXXMoveAssignment)
+  : ClassDecl->hasTrivialMoveAssignment());
+
   // Note that we have added this copy-assignment operator.
   ++getASTContext().NumImplicitMoveAssignmentOperatorsDeclared;
 
@@ -14822,11 +14827,6 @@ CXXMethodDecl 
*Sema::DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl) {
   if (ShouldDeleteSpecialMember(MoveAssignment, CXXMoveAssignment)) {
 ClassDecl->setImplicitMoveAssignmentIsDeleted();
 SetDeclDeleted(MoveAssignment, ClassLoc);
-  } else {
-MoveAssignment->setTrivial(
-ClassDecl->needsOverloadResolutionForMoveAssignment()
-? SpecialMemberIsTrivial(MoveAssignment, CXXMoveAssignment)
-: ClassDecl->hasTrivialMoveAssignment());
   }
 
   if (S)
@@ -15197,6 +15197,18 @@ CXXConstructorDecl 
*Sema::DeclareImplicitCopyConstructor(
   /*TInfo=*/TSI, SC_None, nullptr);
   CopyConstructor->setParams(FromParam);
 
+  CopyConstructor->setTrivial(
+  ClassDecl->needsOverloadResolutionForCopyConstructor()
+  ? SpecialMemberIsTrivial(CopyConstructor, CXXCopyConstructor)
+  : ClassDecl->hasTrivialCopyConstructor());
+
+  CopyConstructor->setTrivialForCall(
+  ClassDecl->hasAttr() ||
+  (ClassDecl->needsOverloadResolutionForCopyConstructor()
+   ? SpecialMemberIsTrivial(CopyConstructor, CXXCopyConstructor,
+ TAH_ConsiderTrivialABI)
+   : ClassDecl->hasTrivialCopyConstructorForCall()));
+
   // Note that we have declared this constructor.
   ++getASTContext().NumImplicitCopyConstructorsDeclared;
 
@@ -15206,18 +15218,6 @@ CXXConstructorDecl 
*Sema::DeclareImplicitCopyConstructor(
   if (ShouldDeleteSpecialMember(CopyConstructor, CXXCopyConstructor)) {
 ClassDecl->setImplicitCopyConstructorIsDeleted();
 SetDeclDeleted(CopyConst

[clang] 6a76334 - [Clang] Reject in-class defaulting of previously declared comparison operators

2023-01-17 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-01-17T22:29:51+02:00
New Revision: 6a763343e29f339cf3a9d282a309589174c74f09

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

LOG: [Clang] Reject in-class defaulting of previously declared comparison 
operators

Comparison operators are not allowed to be defaulted if they were previously 
declared outside the class.
Pretty low-impact, but it's nice to reject this without a linking error.
Fixes https://github.com/llvm/llvm-project/issues/51227.

Reviewed By: #clang-language-wg, ChuanqiXu

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
clang/test/CXX/class/class.compare/class.compare.default/p3.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b19b7859cf9f1..7ddf9b75d5745 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -348,6 +348,8 @@ Bug Fixes
 - Fix issue that the standard C++ modules importer will call global
   constructor/destructor for the global varaibles in the importing modules.
   This fixes `Issue 59765 `_
+- Reject in-class defaulting of previosly declared comparison operators. Fixes
+  `Issue 51227 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index de3df4f7dbd04..02a6c2c4214e8 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9363,6 +9363,9 @@ def err_non_first_default_compare_deletes : Error<
   "defaulting %select{this %sub{select_defaulted_comparison_kind}1|"
   "the corresponding implicit 'operator==' for this defaulted 'operator<=>'}0 "
   "would delete it after its first declaration">;
+def err_non_first_default_compare_in_class : Error<
+  "defaulting this %sub{select_defaulted_comparison_kind}0 "
+  "is not allowed because it was already declared outside the class">;
 def note_defaulted_comparison_union : Note<
   "defaulted %0 is implicitly deleted because "
   "%2 is a %select{union-like class|union}1 with variant members">;

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index ea52b703b563e..cf1242beffe99 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -8734,10 +8734,8 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, 
FunctionDecl *FD,
 
   bool First = FD == FD->getCanonicalDecl();
 
-  // If we want to delete the function, then do so; there's nothing else to
-  // check in that case.
-  if (Info.Deleted) {
-if (!First) {
+  if (!First) {
+if (Info.Deleted) {
   // C++11 [dcl.fct.def.default]p4:
   //   [For a] user-provided explicitly-defaulted function [...] if such a
   //   function is implicitly defined as deleted, the program is 
ill-formed.
@@ -8751,7 +8749,21 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, 
FunctionDecl *FD,
   .visit();
   return true;
 }
+if (isa(FD->getLexicalDeclContext())) {
+  // C++20 [class.compare.default]p1:
+  //   [...] A definition of a comparison operator as defaulted that 
appears
+  //   in a class shall be the first declaration of that function.
+  Diag(FD->getLocation(), diag::err_non_first_default_compare_in_class)
+  << (int)DCK;
+  Diag(FD->getCanonicalDecl()->getLocation(),
+   diag::note_previous_declaration);
+  return true;
+}
+  }
 
+  // If we want to delete the function, then do so; there's nothing else to
+  // check in that case.
+  if (Info.Deleted) {
 SetDeclDeleted(FD, FD->getLocation());
 if (!inTemplateInstantiation() && !FD->isImplicit()) {
   Diag(FD->getLocation(), diag::warn_defaulted_comparison_deleted)

diff  --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp 
b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
index 18b4e271c4bf7..f07b19fefbe74 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -179,6 +179,12 @@ bool operator==(S4 const &, S4 const &) = default; // 
expected-error{{not a frie
 struct S5; // expected-note 3{{forward declaration}}
 bool operator==(S5, S5) = default; // expected-error{{not a friend}} 
expected-error 2{{has incomplete

[clang-tools-extra] 5ea341d - [clang] Fix trivially copyable for copy constructor and copy assignment operator

2022-06-17 Thread Roy Jacobson via cfe-commits

Author: Javier Alvarez
Date: 2022-06-17T10:35:01+03:00
New Revision: 5ea341d7c4f9cc4933adc04ff74d59e26ad2f306

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

LOG: [clang] Fix trivially copyable for copy constructor and copy assignment 
operator

>From [class.copy.ctor]:

```
A non-template constructor for class X is a copy constructor if its first
parameter is of type X&, const X&, volatile X& or const volatile X&, and
either there are no other parameters or else all other parameters have
default arguments (9.3.4.7).

A copy/move constructor for class X is trivial if it is not user-provided and 
if:
- class X has no virtual functions (11.7.3) and no virtual base classes 
(11.7.2), and
- the constructor selected to copy/move each direct base class subobject is 
trivial, and
- or each non-static data member of X that is of class type (or array thereof),
  the constructor selected to copy/move that member is trivial;

otherwise the copy/move constructor is non-trivial.
```

So `T(T&) = default`; should be trivial assuming that the previous
provisions are met.

This works in GCC, but not in Clang at the moment:
https://godbolt.org/z/fTGe71b6P

Reviewed By: royjacobson

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

Added: 


Modified: 
clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-const.cpp
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/LangOptions.h
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/drs/dr21xx.cpp
clang/test/CXX/special/class.copy/p12-0x.cpp
clang/test/CXX/special/class.copy/p25-0x.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-const.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-const.cpp
index fd3bddedd5675..beec7fae961a9 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-const.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize-loop-convert-const.cpp
@@ -10,12 +10,12 @@ struct Str {
 };
 
 // This class is non-trivially copyable because the copy-constructor and copy
-// assignment take non-const references.
+// assignment take non-const references and are user-provided.
 struct ModifiesRightSide {
   ModifiesRightSide() = default;
-  ModifiesRightSide(ModifiesRightSide &) = default;
+  ModifiesRightSide(ModifiesRightSide &);
   bool operator<(ModifiesRightSide &) const;
-  ModifiesRightSide &operator=(ModifiesRightSide &) = default;
+  ModifiesRightSide &operator=(ModifiesRightSide &);
 };
 
 template 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ecf574b3b0f8d..e9ea54d591dad 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -391,7 +391,6 @@ AIX Support
   ``-mignore-xcoff-visibility`` option can be manually specified on the
   command-line to recover the previous behavior if desired.
 
-
 C Language Changes in Clang
 ---
 
@@ -478,6 +477,11 @@ ABI Changes in Clang
   (e.g. ``int : 0``) no longer prevents the structure from being considered a
   homogeneous floating-point or vector aggregate. The new behavior agrees with
   the AAPCS specification, and matches the similar bug fix in GCC 12.1.
+- All copy constructors can now be trivial if they are not user-provided,
+  regardless of the type qualifiers of the argument of the defaulted 
constructor,
+  fixing dr2171.
+  You can switch back to the old ABI behavior with the flag:
+  ``-fclang-abi-compat=14.0``.
 
 OpenMP Support in Clang
 ---

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index cf121de6699c8..f1b6cb60ae855 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -215,8 +215,12 @@ class LangOptions : public LangOptionsBase {
 Ver12,
 
 /// Attempt to be ABI-compatible with code generated by Clang 14.0.x.
-/// This causes clang to mangle dependent nested names incorrectly.
-/// This causes clang to pack non-POD members of packed structs.
+/// This causes clang to:
+///   - mangle dependent nested names incorrectly.
+///   - pack non-POD members of packed structs.
+///   - make trivial only those defaulted copy constructors with a
+/// parameter-type-list equivalent to the parameter-type-list of an
+/// implicit declaration.
 Ver14,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 6c8704cd0b789..ebeb98b2f701c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -9772,11 +9772,22 @@ bool Sema::SpecialMemberI

[clang] 21eb1af - [Concepts] Implement overload resolution for destructors (P0848)

2022-06-18 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-06-19T00:30:37+03:00
New Revision: 21eb1af469c3257606aec2270d544e0e8ecf77b2

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

LOG: [Concepts] Implement overload resolution for destructors (P0848)

This patch implements a necessary part of P0848, the overload resolution for 
destructors.
It is now possible to overload destructors based on constraints, and the 
eligible destructor
will be selected at the end of the class.

The approach this patch takes is to perform the overload resolution in 
Sema::ActOnFields
and to mark the selected destructor using a new property in 
FunctionDeclBitfields.

CXXRecordDecl::getDestructor is then modified to use this property to return 
the correct
destructor.

This closes https://github.com/llvm/llvm-project/issues/45614.

Reviewed By: #clang-language-wg, erichkeane

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

Added: 
clang/test/AST/overloaded-destructors.cpp
clang/test/CXX/class/class.dtor/p4.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/DeclCXX.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/AST/ast-dump-decl.cpp
clang/test/CXX/over/over.match/over.match.viable/p3.cpp
clang/test/SemaTemplate/destructor-template.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 947786a783452..e37b93e573491 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -446,6 +446,10 @@ C++20 Feature Support
   that can be used for such compatibility. The demangler now demangles
   symbols with named module attachment.
 
+- As per "Conditionally Trivial Special Member Functions" (P0848), it is
+  now possible to overload destructors using concepts. Note that the rest
+  of the paper about other special member functions is not yet implemented.
+
 C++2b Feature Support
 ^
 

diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index c2133f4e79a15..66fab94b45b8a 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2251,6 +2251,13 @@ class FunctionDecl : public DeclaratorDecl,
  DeclAsWritten->getCanonicalDecl()->isDefaulted());
   }
 
+  bool isIneligibleOrNotSelected() const {
+return FunctionDeclBits.IsIneligibleOrNotSelected;
+  }
+  void setIneligibleOrNotSelected(bool II) {
+FunctionDeclBits.IsIneligibleOrNotSelected = II;
+  }
+
   /// Whether falling off this function implicitly returns null/zero.
   /// If a more specific implicit return value is required, front-ends
   /// should synthesize the appropriate return statements.

diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index a4a44e0b30e64..0611cf5ccb000 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1596,6 +1596,12 @@ class DeclContext {
 uint64_t IsDefaulted : 1;
 uint64_t IsExplicitlyDefaulted : 1;
 uint64_t HasDefaultedFunctionInfo : 1;
+
+/// For member functions of complete types, whether this is an ineligible
+/// special member function or an unselected destructor. See
+/// [class.mem.special].
+uint64_t IsIneligibleOrNotSelected : 1;
+
 uint64_t HasImplicitReturnZero : 1;
 uint64_t IsLateTemplateParsed : 1;
 
@@ -1631,7 +1637,7 @@ class DeclContext {
   };
 
   /// Number of non-inherited bits in FunctionDeclBitfields.
-  enum { NumFunctionDeclBits = 27 };
+  enum { NumFunctionDeclBits = 28 };
 
   /// Stores the bits used by CXXConstructorDecl. If modified
   /// NumCXXConstructorDeclBits and the accessor
@@ -1643,12 +1649,12 @@ class DeclContext {
 /// For the bits in FunctionDeclBitfields.
 uint64_t : NumFunctionDeclBits;
 
-/// 24 bits to fit in the remaining available space.
+/// 23 bits to fit in the remaining available space.
 /// Note that this makes CXXConstructorDeclBitfields take
 /// exactly 64 bits and thus the width of NumCtorInitializers
 /// will need to be shrunk if some bit is added to NumDeclContextBitfields,
 /// NumFunctionDeclBitfields or CXXConstructorDeclBitfields.
-uint64_t NumCtorInitializers : 21;
+uint64_t NumCtorInitializers : 20;
 uint64_t IsInheritingConstructor : 1;
 
 /// Whether this constructor has a trail-allocated explicit specifier.

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/A

[clang] 3faf1f1 - [Clang] Implement static operator[]

2022-11-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-11-29T12:39:52+02:00
New Revision: 3faf1f17a5c30a3ff1181898f2d2c7649066323d

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

LOG: [Clang] Implement static operator[]

After accepted in Kona, update the code to accept static operator[] as well.

No big code changes: accept this operator as static in SemaDeclCXX, update AST 
call generation in SemaOverload and update feature macros + tests accordingly.

Reviewed By: cor3ntin, erichkeane, #clang-language-wg

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

Added: 
clang/test/CodeGenCXX/cxx2b-static-subscript-operator.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/CXX/over/over.oper/p7.cpp
clang/test/CodeGenCXX/cxx2b-static-call-operator.cpp
clang/test/Lexer/cxx-features.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 86911bd3b1a1e..ffce71f8c38a2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -661,7 +661,7 @@ C++2b Feature Support
 ^
 
 - Support label at end of compound statement (`P2324 
`_).
-- Implemented `P1169R4: static operator() `_.
+- Implemented `P1169R4: static operator() `_ and 
`P2589R1: static operator[] `_.
 - Implemented "char8_t Compatibility and Portability Fix" (`P2513R3 
`_).
   This change was applied to C++20 as a Defect Report.
 - Implemented "Permitting static constexpr variables in constexpr functions" 
(`P2647R1 _`).

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 71093da21b0d5..84ce58c69848c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9110,10 +9110,10 @@ def err_operator_overload_needs_class_or_enum : Error<
   "or enumeration type">;
 
 def err_operator_overload_variadic : Error<"overloaded %0 cannot be variadic">;
+def warn_cxx20_compat_operator_overload_static : Warning<
+  "declaring overloaded %0 as 'static' is incompatible with C++ standards "
+  "before C++2b">, InGroup, DefaultIgnore;
 def ext_operator_overload_static : ExtWarn<
-  "declaring overloaded %0 as 'static' is a C++2b extension">,
-  InGroup, DefaultIgnore;
-def err_call_operator_overload_static : ExtWarn<
   "declaring overloaded %0 as 'static' is a C++2b extension">, InGroup;
 def err_operator_overload_static : Error<
   "overloaded %0 cannot be a static member function">;

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 53a5f13e24afe..69480c9469262 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -695,7 +695,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
 Builder.defineMacro("__cpp_implicit_move", "202011L");
 Builder.defineMacro("__cpp_size_t_suffix", "202011L");
 Builder.defineMacro("__cpp_if_consteval", "202106L");
-Builder.defineMacro("__cpp_multidimensional_subscript", "202110L");
+Builder.defineMacro("__cpp_multidimensional_subscript", "202211L");
   }
 
   // We provide those C++2b features as extensions in earlier language modes, 
so

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 174fe43a2cd51..194298ab5f7bf 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -16015,10 +16015,11 @@ bool 
Sema::CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl) {
   //   function allowed to be static is the call operator function.
   if (CXXMethodDecl *MethodDecl = dyn_cast(FnDecl)) {
 if (MethodDecl->isStatic()) {
-  if (Op == OO_Call)
+  if (Op == OO_Call || Op == OO_Subscript)
 Diag(FnDecl->getLocation(),
- (LangOpts.CPlusPlus2b ? diag::ext_operator_overload_static
-   : diag::err_call_operator_overload_static))
+ (LangOpts.CPlusPlus2b
+  ? diag::warn_cxx20_compat_operator_overload_static
+  : diag::ext_operator_overload_static))
 << FnDecl;
   else
 return Diag(FnDecl->getLocation(), diag::err_operator_overload_static)

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index f2c897dbe882f..a20d7dda79300 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.

[clang] 3c75fea - [clang] Compare constraints before diagnosing mismatched ref qualifiers (GH58962)

2022-11-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-11-29T14:57:26+02:00
New Revision: 3c75feab3bbda563374f08e46a7c052c0c6f1c36

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

LOG: [clang] Compare constraints before diagnosing mismatched ref qualifiers 
(GH58962)

As noticed in GH58962, we should only diagnose illegal overloads of member 
functions
when the ref qualifiers don't match if the trailing constraints are the same.

The fix is to move the existing constraints check earlier in Sema::IsOverload.

Closes https://github.com/llvm/llvm-project/issues/58962

Reviewed By: erichkeane

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

Added: 


Modified: 
clang/lib/Sema/SemaOverload.cpp
clang/test/CXX/over/over.load/p2-0x.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index a20d7dda79300..1eb68090a8fdb 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -1316,6 +1316,17 @@ bool Sema::IsOverload(FunctionDecl *New, FunctionDecl 
*Old,
 (!SameTemplateParameterList || !SameReturnType))
   return true;
   }
+
+  if (ConsiderRequiresClauses) {
+Expr *NewRC = New->getTrailingRequiresClause(),
+ *OldRC = Old->getTrailingRequiresClause();
+if ((NewRC != nullptr) != (OldRC != nullptr))
+  return true;
+
+if (NewRC && !AreConstraintExpressionsEqual(Old, OldRC, New, NewRC))
+return true;
+  }
+
   // If the function is a class member, its signature includes the
   // cv-qualifiers (if any) and ref-qualifier (if any) on the function itself.
   //
@@ -1332,14 +1343,15 @@ bool Sema::IsOverload(FunctionDecl *New, FunctionDecl 
*Old,
   if (!UseMemberUsingDeclRules &&
   (OldMethod->getRefQualifier() == RQ_None ||
NewMethod->getRefQualifier() == RQ_None)) {
-// C++0x [over.load]p2:
-//   - Member function declarations with the same name and the same
-// parameter-type-list as well as member function template
-// declarations with the same name, the same parameter-type-list, 
and
-// the same template parameter lists cannot be overloaded if any of
-// them, but not all, have a ref-qualifier (8.3.5).
+// C++20 [over.load]p2:
+//   - Member function declarations with the same name, the same
+// parameter-type-list, and the same trailing requires-clause (if
+// any), as well as member function template declarations with the
+// same name, the same parameter-type-list, the same trailing
+// requires-clause (if any), and the same template-head, cannot be
+// overloaded if any of them, but not all, have a ref-qualifier.
 Diag(NewMethod->getLocation(), diag::err_ref_qualifier_overload)
-  << NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
+<< NewMethod->getRefQualifier() << OldMethod->getRefQualifier();
 Diag(OldMethod->getLocation(), diag::note_previous_declaration);
   }
   return true;
@@ -1403,23 +1415,6 @@ bool Sema::IsOverload(FunctionDecl *New, FunctionDecl 
*Old,
 }
   }
 
-  if (ConsiderRequiresClauses) {
-Expr *NewRC = New->getTrailingRequiresClause(),
- *OldRC = Old->getTrailingRequiresClause();
-if ((NewRC != nullptr) != (OldRC != nullptr))
-  // RC are most certainly 
diff erent - these are overloads.
-  return true;
-
-if (NewRC) {
-  llvm::FoldingSetNodeID NewID, OldID;
-  NewRC->Profile(NewID, Context, /*Canonical=*/true);
-  OldRC->Profile(OldID, Context, /*Canonical=*/true);
-  if (NewID != OldID)
-// RCs are not equivalent - these are overloads.
-return true;
-}
-  }
-
   // The signatures match; this is not an overload.
   return false;
 }

diff  --git a/clang/test/CXX/over/over.load/p2-0x.cpp 
b/clang/test/CXX/over/over.load/p2-0x.cpp
index cf38741056aba..183f3cb322af7 100644
--- a/clang/test/CXX/over/over.load/p2-0x.cpp
+++ b/clang/test/CXX/over/over.load/p2-0x.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
 // Member function declarations with the same name and the same
 // parameter-type-list as well as mem- ber function template
@@ -22,3 +23,31 @@ class Y {
   void k(); // expected-note{{previous declaration}}
   void k() &&; // expected-error{{cannot overload a member function with 
ref-qualifier '&&' with a member function without a ref-qualifier}}
 };
+
+
+#if __cplusplus >= 202002L
+namespace GH58962 {
+
+template
+__add_rvalue_reference(T) declval();
+
+template
+struct type
+{
+void func() requires (R == 0);
+void func() & requires (R == 1);
+void func() && requires (R 

[clang] 13c3228 - [Clang] Implement LWG3823 for __is_aggregate

2022-11-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-11-29T14:57:47+02:00
New Revision: 13c32288354b6175527f4fdece623157d3637da3

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

LOG: [Clang] Implement LWG3823 for __is_aggregate

LWG3823 says that arrays of incomplete types are aggregates. Fix the clang 
builtin to match that.

Closes https://github.com/llvm/llvm-project/issues/59002

Reviewed By: cjdb

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/type-traits.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ffce71f8c38a..551070b27b2d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -304,6 +304,8 @@ Bug Fixes
 - GNU attributes being applied prior to standard attributes would be handled
   improperly, which was corrected to match the behaviour exhibited by GCC.
   `Issue 58229 `_
+- The builtin type trait ``__is_aggregate`` now returns ``true`` for arrays of 
incomplete
+  types in accordance with the suggested fix for `LWG3823 
https://cplusplus.github.io/LWG/issue3823`_
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 8b3cd4211f88..0980f507426c 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4874,9 +4874,16 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, 
TypeTrait UTT,
   Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
 return true;
 
+  // LWG3823: T shall be an array type, a complete type, or cv void.
+  case UTT_IsAggregate:
+if (ArgTy->isArrayType() || ArgTy->isVoidType())
+  return true;
+
+return !S.RequireCompleteType(
+Loc, ArgTy, diag::err_incomplete_type_used_in_type_trait_expr);
+
   // C++1z [meta.unary.prop]:
   //   remove_all_extents_t shall be a complete type or cv void.
-  case UTT_IsAggregate:
   case UTT_IsTrivial:
   case UTT_IsTriviallyCopyable:
   case UTT_IsStandardLayout:

diff  --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 4369ed0c4672..76a67252c941 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -533,13 +533,15 @@ void is_aggregate()
   constexpr bool TrueAfterCpp14 = __cplusplus > 201402L;
 
   __is_aggregate(AnIncompleteType); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteType[1]); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeAr); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArNB); // expected-error {{incomplete type}}
-  __is_aggregate(AnIncompleteTypeArMB); // expected-error {{incomplete type}}
   __is_aggregate(IncompleteUnion); // expected-error {{incomplete type}}
 
+  // Valid since LWG3823
+  static_assert(__is_aggregate(AnIncompleteType[]), "");
+  static_assert(__is_aggregate(AnIncompleteType[1]), "");
+  static_assert(__is_aggregate(AnIncompleteTypeAr), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArNB), "");
+  static_assert(__is_aggregate(AnIncompleteTypeArMB), "");
+
   static_assert(!__is_aggregate(NonPOD), "");
   static_assert(__is_aggregate(NonPODAr), "");
   static_assert(__is_aggregate(NonPODArNB), "");



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


[clang] c64359e - [NFC] fix doc inconsistency in cxx_status

2022-11-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-11-29T15:00:40+02:00
New Revision: c64359ea4c8ee9830dc828ed26d862a763f4535d

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

LOG: [NFC] fix doc inconsistency in cxx_status

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 9559c562bdec..ab4eabb542f5 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -1518,7 +1518,7 @@ C++2b implementation status
 
   static operator[]
   https://wg21.link/P2589R1";>P2589R1
-  16
+  Clang 16
 
 
   Permitting static constexpr variables in constexpr functions 
(DR)



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


[clang] 765d8a1 - [Clang][Sema] Fix incorrect deletion of default constructors for some unions

2023-03-15 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-03-15T23:55:52+02:00
New Revision: 765d8a192180f8f33618087b15c022fe758044af

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

LOG: [Clang][Sema] Fix incorrect deletion of default constructors for some 
unions

If a union has explicit initializers for some members, we shouldn't delete
its default constructor.
Fixes https://github.com/llvm/llvm-project/issues/48416.

Reviewed By: erichkeane

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

Added: 
clang/test/CodeGen/union-non-trivial-member.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/cxx0x-nontrivial-union.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 10be3be259bc..09a3daee6887 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -225,6 +225,8 @@ Bug Fixes to C++ Support
 - Fix an issue about ``decltype`` in the members of class templates derived 
from
   templates with related parameters.
   (`#58674 `_)
+- Fix incorrect deletion of the default constructor of unions in some
+  cases. (`#48416 `_)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 41c76e5c1371..16e1071366b3 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -9158,7 +9158,18 @@ bool 
SpecialMemberDeletionInfo::shouldDeleteForSubobjectCall(
 // must be accessible and non-deleted, but need not be trivial. Such a
 // destructor is never actually called, but is semantically checked as
 // if it were.
-DiagKind = 4;
+if (CSM == Sema::CXXDefaultConstructor) {
+  // [class.default.ctor]p2:
+  //   A defaulted default constructor for class X is defined as deleted if
+  //   - X is a union that has a variant member with a non-trivial default
+  // constructor and no variant member of X has a default member
+  // initializer
+  const auto *RD = cast(Field->getParent());
+  if (!RD->hasInClassInitializer())
+DiagKind = 4;
+} else {
+  DiagKind = 4;
+}
   }
 
   if (DiagKind == -1)

diff  --git a/clang/test/CodeGen/union-non-trivial-member.cpp 
b/clang/test/CodeGen/union-non-trivial-member.cpp
new file mode 100644
index ..fdc9fd16911e
--- /dev/null
+++ b/clang/test/CodeGen/union-non-trivial-member.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 --std=c++17 -emit-llvm %s -o - -triple 
x86_64-unknown-linux-gnu | FileCheck %s
+
+struct non_trivial_constructor {
+constexpr non_trivial_constructor() : x(100) { }
+int x;
+};
+
+union UnionInt {
+int a{1000};
+non_trivial_constructor b;
+};
+
+union UnionNonTrivial {
+int a;
+non_trivial_constructor b{};
+};
+
+void f() {
+UnionInt u1;
+UnionNonTrivial u2;
+}
+
+// CHECK:  define dso_local void @_Z1fv()
+// CHECK:call void @_ZN8UnionIntC1Ev
+// CHECK-NEXT:   call void @_ZN15UnionNonTrivialC1Ev
+
+// CHECK:  define {{.*}}void @_ZN8UnionIntC1Ev
+// CHECK:call void @_ZN8UnionIntC2Ev
+
+// CHECK:  define {{.*}}void @_ZN15UnionNonTrivialC1Ev
+// CHECK:call void @_ZN15UnionNonTrivialC2Ev
+
+// CHECK:  define {{.*}}void @_ZN8UnionIntC2Ev
+// CHECK:store i32 1000
+
+// CHECK:  define {{.*}}void @_ZN15UnionNonTrivialC2Ev
+// CHECK:call void @_ZN23non_trivial_constructorC1Ev

diff  --git a/clang/test/SemaCXX/cxx0x-nontrivial-union.cpp 
b/clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
index ad1f09fee33f..4a4bf7180a47 100644
--- a/clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ b/clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
@@ -144,3 +144,47 @@ namespace pr16061 {
 
   Test2 t2x;  // expected-error {{call to implicitly-deleted default 
constructor of 'Test2'}}
 }
+
+namespace GH48416 {
+
+struct non_trivial_constructor {
+constexpr non_trivial_constructor() : x(100) {}
+int x;
+};
+
+
+union U1 {
+int a;
+non_trivial_constructor b; // expected-note {{has a non-trivial default 
constructor}}
+};
+
+union U2 {
+int a{1000};
+non_trivial_constructor b;
+};
+
+union U3 {
+int a;
+non_trivial_constructor b{};
+};
+
+union U4 {
+int a{}; // expected-note {{previous initialization is here}}
+non_trivial_constructor b{}; // expected-error {{initializing multiple 
members of union}}
+};
+
+U1 u1; // expected-error {{call to implicitly-deleted default constructor}}
+U2 u2;
+U3 u3;
+U4 u4;
+
+static_assert(U2().a == 1000, "");
+static_assert(U3().a == 1000, "");
+// expected-error@-1 {{static assertion expression is not an integral constant 
expression}

[clang] 6ce272b - [Doc][Clang] Update Clang 16 from 'unreleased' to 'full'

2023-03-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-03-29T14:20:27+03:00
New Revision: 6ce272b3f4ceb54e31cac660371a1a9af94b70d7

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

LOG: [Doc][Clang] Update Clang 16 from 'unreleased' to 'full'

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 79cfca34fb4f3..8b1e8712e3944 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -912,7 +912,7 @@ C++20 implementation status
 

 https://wg21.link/p0857r0";>P0857R0
-Clang 16
+Clang 16
   

 https://wg21.link/p1084r2";>P1084R2
@@ -923,7 +923,7 @@ C++20 implementation status
   

 https://wg21.link/p0848r3";>P0848R3
-
+
   
 Clang 16 (Partial)
 Because of other concepts implementation deficits, the 
__cpp_concepts macro is not yet set to 202002L.
@@ -955,11 +955,11 @@ C++20 implementation status
   
   
 https://wg21.link/p2092r0";>P2092R0
-Clang 16
+Clang 16
   
   
 https://wg21.link/p2113r0";>P2113R0
-Clang 16
+Clang 16
   
 
 
@@ -1044,7 +1044,7 @@ C++20 implementation status
 
   typename optional in more contexts
   https://wg21.link/p0634r3";>P0634R3
-  Clang 16
+  Clang 16
 
 
   Pack expansion in lambda init-capture
@@ -1147,7 +1147,7 @@ C++20 implementation status
 
   Structured binding extensions
   https://wg21.link/p1091r3";>P1091R3
-  Clang 16
+  Clang 16
 
   
 https://wg21.link/p1381r1";>P1381R1
@@ -1445,7 +1445,7 @@ C++2b implementation status
 
   The Equality Operator You Are Looking For
   https://wg21.link/P2468R2";>P2468R2
-  Clang 16
+  Clang 16
 
 
   De-deprecating volatile compound operations
@@ -1465,7 +1465,7 @@ C++2b implementation status
 
   Labels at the end of compound statements
   https://wg21.link/P2324R2";>P2324R2
-  Clang 16
+  Clang 16
 
 
   Delimited escape sequences
@@ -1490,7 +1490,7 @@ C++2b implementation status
 
   static operator()
   https://wg21.link/P1169R4";>P1169R4
-  Clang 16
+  Clang 16
 
 
   Extended floating-point types and standard names
@@ -1515,7 +1515,7 @@ C++2b implementation status
 
   char8_t Compatibility and Portability Fix
   https://wg21.link/P2513R3";>P2513R3
-  Clang 16
+  Clang 16
 
 
   Relax requirements on wchar_t to match existing 
practices
@@ -1531,12 +1531,12 @@ C++2b implementation status
 
   static operator[]
   https://wg21.link/P2589R1";>P2589R1
-  Clang 16
+  Clang 16
 
 
   Permitting static constexpr variables in constexpr functions
   https://wg21.link/P2647R1";>P2647R1
-  Clang 16
+  Clang 16
 
 
   consteval needs to propagate up



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


[clang] da71cba - [Doc][Clang] Update information about default standard version

2023-03-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-03-29T14:25:27+03:00
New Revision: da71cbacfc3f2b7519356ca105b4c1cde0026106

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

LOG: [Doc][Clang] Update information about default standard version

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index 8b1e8712e394..fe2a16d9cee1 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -498,8 +498,7 @@ C++14 implementation status
 href="https://www.iso.org/standard/64029.html";>ISO
 C++ 2014 standard.
 
-By default, Clang builds C++ code according to the C++14 standard.
-You can use Clang in C++14 mode with the -std=c++14 option
+You can use Clang in C++14 mode with the -std=c++14 option
 (use -std=c++1y in Clang 3.4 and earlier).
 
 
@@ -593,7 +592,8 @@ C++17 implementation status
 Clang 5 and later implement all the features of the
 https://www.iso.org/standard/68564.html";>ISO C++ 2017 
standard.
 
-You can use Clang in C++17 mode with the -std=c++17 option
+By default, Clang 16 or later builds C++ code according to the C++17 
standard.
+You can use Clang in C++17 mode with the -std=c++17 option
 (use -std=c++1z in Clang 4 and earlier).
 
 



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


[clang-tools-extra] aa56e66 - [clang-tidy] Tweak 'rule of 3/5' checks to allow defaulting a destructor outside the class.

2023-02-26 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-02-26T15:55:54+02:00
New Revision: aa56e66bf7520512fd1209cbb7d099604a5f6277

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

LOG: [clang-tidy] Tweak 'rule of 3/5' checks to allow defaulting a destructor 
outside the class.

A somewhat common code-pattern is to default a destructor in the source file 
and not in the header.
For example, this is the way to use smart pointers with forward-declared 
classes:

```c++

struct Impl;
struct A {
  ~A(); // Can't be defaulted in the header.

private:
  std::unique_ptr impl;
};
```

To be able to use this check with this pattern, I modified the behavior with 
`AllowSoleDefaultDtor`
to not trigger on destructors if they aren't defined yet.
Since a declared destructor should still be defined somewhere in the program, 
this
won't miss bad classes, just diagnose on less translation units.

Reviewed By: carlosgalvezp

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

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-cxx-03.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions-relaxed.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/special-member-functions.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
index 9bea2a78fa953..d2117c67a76d0 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
@@ -108,10 +108,14 @@ void SpecialMemberFunctionsCheck::check(
   };
 
   if (const auto *Dtor = Result.Nodes.getNodeAs("dtor")) {
-StoreMember({Dtor->isDefaulted()
- ? SpecialMemberFunctionKind::DefaultDestructor
- : SpecialMemberFunctionKind::NonDefaultDestructor,
- Dtor->isDeleted()});
+SpecialMemberFunctionKind DestructorType =
+SpecialMemberFunctionKind::Destructor;
+if (Dtor->isDefined()) {
+  DestructorType = Dtor->getDefinition()->isDefaulted()
+   ? SpecialMemberFunctionKind::DefaultDestructor
+   : SpecialMemberFunctionKind::NonDefaultDestructor;
+}
+StoreMember({DestructorType, Dtor->isDeleted()});
   }
 
   std::initializer_list>
@@ -158,7 +162,8 @@ void SpecialMemberFunctionsCheck::checkForMissingMembers(
   bool RequireThree =
   HasMember(SpecialMemberFunctionKind::NonDefaultDestructor) ||
   (!AllowSoleDefaultDtor &&
-   HasMember(SpecialMemberFunctionKind::DefaultDestructor)) ||
+   (HasMember(SpecialMemberFunctionKind::Destructor) ||
+HasMember(SpecialMemberFunctionKind::DefaultDestructor))) ||
   HasMember(SpecialMemberFunctionKind::CopyConstructor) ||
   HasMember(SpecialMemberFunctionKind::CopyAssignment) ||
   HasMember(SpecialMemberFunctionKind::MoveConstructor) ||
@@ -170,7 +175,8 @@ void SpecialMemberFunctionsCheck::checkForMissingMembers(
  HasMember(SpecialMemberFunctionKind::MoveAssignment);
 
   if (RequireThree) {
-if (!HasMember(SpecialMemberFunctionKind::DefaultDestructor) &&
+if (!HasMember(SpecialMemberFunctionKind::Destructor) &&
+!HasMember(SpecialMemberFunctionKind::DefaultDestructor) &&
 !HasMember(SpecialMemberFunctionKind::NonDefaultDestructor))
   MissingMembers.push_back(SpecialMemberFunctionKind::Destructor);
 

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
index 92815e216242c..2d8b842be5942 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/special-member-functions.rst
@@ -25,15 +25,25 @@ Options
 
 .. option:: AllowSoleDefaultDtor
 
-   When set to `true` (default is `false`), this check doesn't flag classes 
with a sole, explicitly
-   defaulted destructor. An example for such a class is:
+   When set to `true` (default is `false`), this check will only trigger on
+   destructors if they are defined and not defaulted.
 
.. code-block:: c++
 
- struct A {
+ struct A { // This is fine.
virtual ~A() = default;
  };
 
+ struct B { // This is not fine.
+   ~B() {}
+ };
+
+ struct C {
+   // This is 

[clang] fc10715 - Fix broken link on Clang documentation page

2023-03-04 Thread Roy Jacobson via cfe-commits

Author: Tulio Leao
Date: 2023-03-05T00:58:48+02:00
New Revision: fc10715f9bb39741fcfd5373134767481235aa14

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

LOG: Fix broken link on Clang documentation page

While browsing the latest [clang 
manual](https://clang.llvm.org/docs/ReleaseNotes.html), I came across this 
warning and clicked, but it leads to a broken page, apparently because it's 
missing the trailing `/`. Seems to be the only place where it's missing in the 
whole of LLVM monorepo.

{F26690053}
{F26690057}

Reviewed By: brenoguim, royjacobson

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3c152cab15c6..988bcf186098 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -13,7 +13,7 @@ Written by the `LLVM Team `_
   .. warning::
  These are in-progress notes for the upcoming Clang |version| release.
  Release notes for previous releases can be found on
- `the Releases Page `_.
+ `the Releases Page `_.
 
 Introduction
 



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


[clang] c0dc8f7 - [Clang][Doc] Fix inconsistent links in release notes

2023-03-11 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-03-11T18:39:33+02:00
New Revision: c0dc8f7a29e70fb69456517aa32db43d45f9a124

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

LOG: [Clang][Doc] Fix inconsistent links in release notes

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8d880a4fba266..76e0a71931c1c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -79,7 +79,7 @@ C++ Language Changes
 C++20 Feature Support
 ^
 - Support for out-of-line definitions of constrained templates has been 
improved.
-  This partially fixes `https://github.com/llvm/llvm-project/issues/49620`.
+  This partially fixes `#49620 
`_.
 
 C++2b Feature Support
 ^
@@ -95,8 +95,7 @@ Resolutions to C++ Defect Reports
 C Language Changes
 --
 - Support for outputs from asm goto statements along indirect edges has been
-  added. This fixes
-  `Issue 53562 `_.
+  added. (`#53562 `_)
 
 C2x Feature Support
 ^^^
@@ -153,7 +152,7 @@ Improvements to Clang's diagnostics
 ---
 - We now generate a diagnostic for signed integer overflow due to unary minus
   in a non-constant expression context.
-  (`#31643 `)
+  (`#31643 `_)
 - Clang now warns by default for C++20 and later about deprecated capture of
   ``this`` with a capture default of ``=``. This warning can be disabled with
   ``-Wno-deprecated-this-capture``.
@@ -310,7 +309,7 @@ Static Analyzer
 ---
 - Fix incorrect alignment attribute on the this parameter of certain
   non-complete destructors when using the Microsoft ABI.
-  `Issue 60465 `_.
+  (`#60465 `_)
 
 .. _release-notes-sanitizers:
 



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


[clang] 0eb06cb - [Sema] Stop stripping CV quals from *this captures in lambdas

2023-03-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-03-29T23:11:51+03:00
New Revision: 0eb06cb3aa2700508c20da28f22ff91e7b82a436

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

LOG: [Sema] Stop stripping CV quals from *this captures in lambdas

It appears we've been incorrectly stripping CV qualifiers when capturing `this` 
by value inside lambdas.
This patch simply removes the CV stripping code as discussed.

Closes https://github.com/llvm/llvm-project/issues/50866

Reviewed By: #clang-language-wg, cor3ntin, aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/cxx1z-lambda-star-this.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 271e01b8a47d5..44ffca26f26a2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -277,6 +277,9 @@ Bug Fixes to C++ Support
 - No longer issue a pre-C++2b compatibility warning in ``-pedantic`` mode
   regading overloaded `operator[]` with more than one parmeter or for static
   lambdas. (`#61582 `_)
+- Stop stripping CV qualifiers from the type of ``this`` when capturing it by 
value in
+  a lambda.
+  (`#50866 `_)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d5aeb38245ad7..5c3a21583f856 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1135,7 +1135,6 @@ static QualType adjustCVQualifiersForCXXThisWithinLambda(
 auto C = CurLSI->getCXXThisCapture();
 
 if (C.isCopyCapture()) {
-  ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
   if (!CurLSI->Mutable)
 ClassType.addConst();
   return ASTCtx.getPointerType(ClassType);
@@ -1175,7 +1174,6 @@ static QualType adjustCVQualifiersForCXXThisWithinLambda(
 while (Closure &&
IsThisCaptured(Closure, IsByCopyCapture, IsConstCapture)) {
   if (IsByCopyCapture) {
-ClassType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
 if (IsConstCapture)
   ClassType.addConst();
 return ASTCtx.getPointerType(ClassType);
@@ -1362,15 +1360,7 @@ bool Sema::CheckCXXThisCapture(SourceLocation Loc, const 
bool Explicit,
 
 // The type of the corresponding data member (not a 'this' pointer if 'by
 // copy').
-QualType CaptureType = ThisTy;
-if (ByCopy) {
-  // If we are capturing the object referred to by '*this' by copy, ignore
-  // any cv qualifiers inherited from the type of the member function for
-  // the type of the closure-type's corresponding data member and any use
-  // of 'this'.
-  CaptureType = ThisTy->getPointeeType();
-  CaptureType.removeLocalCVRQualifiers(Qualifiers::CVRMask);
-}
+QualType CaptureType = ByCopy ? ThisTy->getPointeeType() : ThisTy;
 
 bool isNested = NumCapturingClosures > 1;
 CSI->addThisCapture(isNested, Loc, CaptureType, ByCopy);

diff  --git a/clang/test/SemaCXX/cxx1z-lambda-star-this.cpp 
b/clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
index 5a471fd6b6940..95bc32b603ddf 100644
--- a/clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
+++ b/clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
@@ -88,13 +88,11 @@ struct X {
   void foo() const { //expected-note{{const}}
 
 auto L = [*this]() mutable {
-  static_assert(is_same);
-  ++d;
+  static_assert(is_same);
   auto M = [this] {
-static_assert(is_same);
-++d;
+static_assert(is_same);
 auto N = [] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -108,9 +106,9 @@ struct X {
 };
   };
   auto M2 = [*this]() mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [] {
-  static_assert(is_same);
+  static_assert(is_same);
 };
   };
 };
@@ -126,9 +124,9 @@ struct X {
   };
 
   auto M2 = [*this](auto a) mutable {
-static_assert(is_same);
+static_assert(is_same);
 auto N = [](auto b) {
-  static_assert(is_same);
+  static_assert(is_same);
 };
 return N;
   };
@@ -143,13 +141,11 @@ struct X {
   ++d; //expected-error{{cannot assign}}
 };
 auto GL = [*this](auto a) mutable {
-  static_assert(is_same);
-  ++d;
+  static_assert(is_same);
   auto M = [this](auto b) {
-static_assert(is_same);
-++d;
+static_assert(is_same);
 auto N = [](auto c) {
-  static_assert(is_same);
+  static_assert(is

[clang] 1d4d21e - [Clang][AST] Fix __has_unique_object_representations computation for unnamed bitfields.

2023-04-01 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-04-02T00:54:45+03:00
New Revision: 1d4d21e2e0950f6c451198e380371ee3142ce2fb

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

LOG: [Clang][AST] Fix __has_unique_object_representations computation for 
unnamed bitfields.

As pointed out in https://github.com/llvm/llvm-project/issues/61336, objects 
with
unnamed bitfields aren't be uniquely representable.

Reviewed By: shafik, Endill

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ASTContext.cpp
clang/test/SemaCXX/type-traits.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4640ecccb9ad4..cd9aae998a503 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -291,6 +291,9 @@ Bug Fixes to C++ Support
   template parameters with 
diff erent nested constraints.
 - Fix type equivalence comparison between auto types to take constraints into
   account.
+- Fix bug in the computation of the ``__has_unique_object_representations``
+  builtin for types with unnamed bitfields.
+  (`#61336 `_)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 612fcd4897c8f..bd4f2ff024949 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2716,6 +2716,11 @@ getSubobjectSizeInBits(const FieldDecl *Field, const 
ASTContext &Context) {
   int64_t FieldSizeInBits =
   Context.toBits(Context.getTypeSizeInChars(Field->getType()));
   if (Field->isBitField()) {
+// If we have explicit padding bits, they don't contribute bits
+// to the actual object representation, so return 0.
+if (Field->isUnnamedBitfield())
+  return 0;
+
 int64_t BitfieldSize = Field->getBitWidthValue(Context);
 if (IsBitIntType) {
   if ((unsigned)BitfieldSize >

diff  --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 7d425acb56813..e3fc65713cedf 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -2828,6 +2828,17 @@ 
static_assert(!has_unique_object_representations::value, "Alignm
 static_assert(!has_unique_object_representations::value, 
"Alignment causes padding");
 static_assert(!has_unique_object_representations::value, 
"Also no arrays that have padding");
 
+struct __attribute__((packed)) PackedNoPadding1 {
+  short i;
+  int j;
+};
+struct __attribute__((packed)) PackedNoPadding2 {
+  int j;
+  short i;
+};
+static_assert(has_unique_object_representations::value, 
"Packed structs have no padding");
+static_assert(has_unique_object_representations::value, 
"Packed structs have no padding");
+
 static_assert(!has_unique_object_representations::value, "Functions 
are not unique");
 static_assert(!has_unique_object_representations::value, 
"Functions are not unique");
 static_assert(!has_unique_object_representations::value, 
"Functions are not unique");
@@ -2878,9 +2889,35 @@ struct AlignedPaddedBitfield {
   char d : 2;
 };
 
+struct UnnamedBitfield {
+  int named : 8;
+  int : 24;
+};
+
+struct __attribute__((packed)) UnnamedBitfieldPacked {
+  int named : 8;
+  int : 24;
+};
+
+struct UnnamedEmptyBitfield {
+  int named;
+  int : 0;
+};
+
+struct UnnamedEmptyBitfieldSplit {
+  short named;
+  int : 0;
+  short also_named;
+};
+
 static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
 static_assert(has_unique_object_representations::value, 
"Bitfield padding");
 
static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(!has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(!has_unique_object_representations::value,
 "Bitfield padding");
+static_assert(has_unique_object_representations::value, 
"Bitfield padding");
+static_assert(sizeof(UnnamedEmptyBitfieldSplit) != (sizeof(short) * 2), "Wrong 
size");
+static_assert(!has_unique_object_representations::value,
 "Bitfield padding");
 
 struct BoolBitfield {
   bool b : 8;



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


[clang] 016970d - [Clang] Fix cast to BigIntType in hasUniqueObjectRepresentations

2023-04-10 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-04-10T22:11:57+03:00
New Revision: 016970d079c40b99c28c6973df8f7a98e8b8d536

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

LOG: [Clang] Fix cast to BigIntType in hasUniqueObjectRepresentations

A bad QualType cast caused us not to detect _BigInt types if they were wrapped 
inside sugar types like SubstTemplateTypeParm.
Fix https://github.com/llvm/llvm-project/issues/62019

Reviewed By: cjdb

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

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/test/SemaCXX/type-traits.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 74826da6703f5..6f36b056c7bb9 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2832,7 +2832,7 @@ bool ASTContext::hasUniqueObjectRepresentations(QualType 
Ty) const {
   // All integrals and enums are unique.
   if (Ty->isIntegralOrEnumerationType()) {
 // Except _BitInt types that have padding bits.
-if (const auto *BIT = dyn_cast(Ty))
+if (const auto *BIT = Ty->getAs())
   return getTypeSize(BIT) == BIT->getNumBits();
 
 return true;

diff  --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index e3fc65713cedf..cc0a83706475d 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -2970,6 +2970,12 @@ namespace ErrorType {
   bool b = __has_unique_object_representations(T);
 };
 
+static_assert(!has_unique_object_representations<_BitInt(7)>::value, 
"BitInt:");
+static_assert(has_unique_object_representations<_BitInt(8)>::value, "BitInt:");
+static_assert(!has_unique_object_representations<_BitInt(127)>::value, 
"BitInt:");
+static_assert(has_unique_object_representations<_BitInt(128)>::value, 
"BitInt:");
+
+
 namespace PR46209 {
   // Foo has both a trivial assignment operator and a non-trivial one.
   struct Foo {



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


[clang-tools-extra] 40af06c - [clang-tidy] Update UnusedReturnValueCheck types

2023-05-29 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-05-29T23:02:32+03:00
New Revision: 40af06ccc7bf9989b8deb410ed78a4795c22aa73

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

LOG: [clang-tidy] Update UnusedReturnValueCheck types

Update the types for UnusedReturnValueCheck after D151383.

1. Add std::errc, std:error_condition
2. Remove `absl::Status` - it's marked as `[[nodiscard]]` anyway so it's 
redundant (and might create double warnings) to check it.

Reviewed By: PiotrZSL

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
index f8139381d7e01..bdc601c2445f5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -127,9 +127,10 @@ 
UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
"::ttyname")),
   CheckedReturnTypes(utils::options::parseStringList(
   Options.get("CheckedReturnTypes", "::std::error_code;"
+"::std::error_condition;"
+"::std::errc;"
 "::std::expected;"
-"::boost::system::error_code;"
-"::abseil::Status"))) {}
+"::boost::system::error_code"))) {}
 
 void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "CheckedFunctions", CheckedFunctions);

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
index 89c781b0fe714..c9b24dbcbb94f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -50,7 +50,7 @@ Options
 
Semicolon-separated list of function return types to check.
By default the following function return types are checked:
-   `::std::error_code`, `::std::expected`, `::boost::system::error_code`, 
`::abseil::Status`
+   `::std::error_code`, `::std::error_condition`, `::std::errc`, 
`::std::expected`, `::boost::system::error_code`
 
 `cert-err33-c <../cert/err33-c.html>`_ is an alias of this check that checks a
 fixed and large set of standard library functions.



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


[clang] b6259ec - [Clang] Export CanPassInRegisters as a type trait

2023-02-13 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-02-13T19:16:23+02:00
New Revision: b6259eca16f6c923d87a1ca1d424931e37d6871a

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

LOG: [Clang] Export CanPassInRegisters as a type trait

While working on D140664, I thought it would be nice to be able to write tests
for parameter passing ABI. Currently we test this by dumping the AST and
matching the results which makes it hard to write new tests.
Adding this builtin will allow writing better ABI tests which
can help improve our coverage in this area.

While less useful, maybe some users would also find it useful for asserting
against pessimisations for their classes.

Reviewed By: erichkeane

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

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/TokenKinds.def
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/type-traits.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 84d5b0ed98108..20c8bb5de0443 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1401,6 +1401,10 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__array_extent(type, dim)`` (Embarcadero):
   The ``dim``'th array bound in the type ``type``, or ``0`` if
   ``dim >= __array_rank(type)``.
+* ``__can_pass_in_regs`` (C++)
+  Returns whether a class can be passed in registers under the current
+  ABI. This type can only be applied to unqualified class types.
+  This is not a portable type trait.
 * ``__has_nothrow_assign`` (GNU, Microsoft, Embarcadero):
   Deprecated, use ``__is_nothrow_assignable`` instead.
 * ``__has_nothrow_move_assign`` (GNU, Microsoft):

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9b9ec23a2f21f..b658ad71e63a1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11794,4 +11794,8 @@ def note_unsafe_buffer_variable_fixit : Note<
   "change type of '%0' to '%select{std::span|std::array|std::span::iterator}1' 
to preserve bounds information">;
 def err_loongarch_builtin_requires_la32 : Error<
   "this builtin requires target: loongarch32">;
+
+def err_builtin_pass_in_regs_non_class : Error<
+  "argument %0 is not an unqualified class type">;
+
 } // end of sema component.

diff  --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 96feae991ccbc..6d35f1bb31fcd 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -523,6 +523,7 @@ TYPE_TRAIT_1(__is_unbounded_array, IsUnboundedArray, KEYCXX)
 TYPE_TRAIT_1(__is_nullptr, IsNullPointer, KEYCXX)
 TYPE_TRAIT_1(__is_scoped_enum, IsScopedEnum, KEYCXX)
 TYPE_TRAIT_1(__is_referenceable, IsReferenceable, KEYCXX)
+TYPE_TRAIT_1(__can_pass_in_regs, CanPassInRegs, KEYCXX)
 TYPE_TRAIT_2(__reference_binds_to_temporary, ReferenceBindsToTemporary, KEYCXX)
 
 // Embarcadero Expression Traits

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index ef012770747ca..eb9a3e65763f2 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4885,6 +4885,7 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, 
TypeTrait UTT,
   case UTT_IsLiteral:
   // By analogy, is_trivially_relocatable imposes the same constraints.
   case UTT_IsTriviallyRelocatable:
+  case UTT_CanPassInRegs:
   // Per the GCC type traits documentation, T shall be a complete type, cv 
void,
   // or an array of unknown bound. But GCC actually imposes the same 
constraints
   // as above.
@@ -5373,6 +5374,11 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return T.isTriviallyRelocatableType(C);
   case UTT_IsReferenceable:
 return T.isReferenceable();
+  case UTT_CanPassInRegs:
+if (CXXRecordDecl *RD = T->getAsCXXRecordDecl(); RD && !T.hasQualifiers())
+  return RD->canPassInRegisters();
+Self.Diag(KeyLoc, diag::err_builtin_pass_in_regs_non_class) << T;
+return false;
   }
 }
 

diff  --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 76a67252c9410..7d425acb56813 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -3055,6 +3055,36 @@ 
static_assert(__is_trivially_relocatable(TrivialAbiNontrivialMoveCtor[]), "");
 
 } // namespace is_trivially_relocatable
 
+namespace can_pass_in_regs {
+
+struct A { };
+
+struct B {
+  ~B();
+};
+
+struct C; // expected-note {{forward declaration}}
+
+union D {
+  int x;
+};
+
+static_assert(__can_pass_in_

[clang] f5aa8d1 - [Clang][docs] Update the release notes page to the new skeleton

2023-02-15 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-02-15T23:53:38+02:00
New Revision: f5aa8d191a5b5ea118281bfa410bdb2ee961c704

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

LOG: [Clang][docs] Update the release notes page to the new skeleton

Was discussed at https://reviews.llvm.org/D142578.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ab7518cc2dc6..abb6f0ae8e92 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -13,7 +13,7 @@ Written by the `LLVM Team `_
   .. warning::
  These are in-progress notes for the upcoming Clang |version| release.
  Release notes for previous releases can be found on
- `the Download Page `_.
+ `the Releases Page `_.
 
 Introduction
 
@@ -23,25 +23,30 @@ frontend, part of the LLVM Compiler Infrastructure, release 
|release|. Here we
 describe the status of Clang in some detail, including major
 improvements from the previous release and new feature work. For the
 general LLVM release notes, see `the LLVM
-documentation `_. All LLVM
-releases may be downloaded from the `LLVM releases web
-site `_.
+documentation `_. For the libc++ 
release notes,
+see `this page `_. All LLVM releases
+may be downloaded from the `LLVM releases web site 
`_.
 
 For more information about Clang or LLVM, including information about the
 latest release, please see the `Clang Web Site `_ or 
the
 `LLVM Web Site `_.
 
-Note that if you are reading this file from a Git checkout or the
-main Clang web page, this document applies to the *next* release, not
-the current one. To see the release notes for a specific release, please
-see the `releases page `_.
-
 Potentially Breaking Changes
 
 These changes are ones which we think may surprise users when upgrading to
 Clang |release| because of the opportunity they pose for disruption to existing
 code bases.
 
+
+C/C++ Language Potentially Breaking Changes
+---
+
+C++ Specific Potentially Breaking Changes
+-
+
+ABI Changes in This Version
+---
+
 What's New in Clang |release|?
 ==
 Some of the major new features and improvements to Clang are listed
@@ -49,33 +54,28 @@ here. Generic improvements to Clang as a whole or to its 
underlying
 infrastructure are described first, followed by language-specific
 sections with improvements to Clang's support for those languages.
 
-Major New Features
---
+C++ Language Changes
+
+- Improved ``-O0`` code generation for calls to ``std::forward_like``. 
Similarly to
+  ``std::move, std::forward`` et al. it is now treated as a compiler builtin 
and implemented
+  directly rather than instantiating the definition from the standard library.
 
-Bug Fixes
--
-- Fix crash on invalid code when looking up a destructor in a templated class
-  inside a namespace. This fixes
-  `Issue 59446 `_.
-- Fix crash when diagnosing incorrect usage of ``_Nullable`` involving alias
-  templates. This fixes
-  `Issue 60344 `_.
-- Fix confusing warning message when ``/clang:-x`` is passed in ``clang-cl``
-  driver mode and emit an error which suggests using ``/TC`` or ``/TP``
-  ``clang-cl`` options instead. This fixes
-  `Issue 59307 `_.
-- Fix crash when evaluating consteval constructor of derived class whose base
-  has more than one field. This fixes
-  `Issue 60166 `_.
+C++20 Feature Support
+^
 
-Improvements to Clang's diagnostics
-^^^
-- We now generate a diagnostic for signed integer overflow due to unary minus
-  in a non-constant expression context. This fixes
-  `Issue 31643 `_
-- Clang now warns by default for C++20 and later about deprecated capture of
-  ``this`` with a capture default of ``=``. This warning can be disabled with
-  ``-Wno-deprecated-this-capture``.
+C++2b Feature Support
+^
+
+Resolutions to C++ Defect Reports
+^
+
+C Language Changes
+--
+
+C2x Featur

[clang] 000ec50 - [Clang] Adjust triviality computation in QualType::isTrivialType to C++20 cases.

2023-02-22 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-02-22T23:27:09+02:00
New Revision: 000ec50ef511243ec46c249c06d7a82cedf6d538

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

LOG: [Clang] Adjust triviality computation in QualType::isTrivialType to C++20 
cases.

Up to C++20, hasDefaultConstructor and !hasNonTrivialDefaultConstructor 
together implied
hasTrivialDefaultConstructor. In C++20, a constructor might be ineligible and 
can set
hasDefaultConstructor without setting hasNonTrivialDefaultConstructor.

Fix this by querying hasTrivialDefaultConstructor instead of 
hasDefaultConstructor.

I'd like to backport this to Clang 16.
I only change isTrivialType and in a way that should only affect code that uses
constrained constructors, so I think this is relatively safe to backport.

Fixes https://github.com/llvm/llvm-project/issues/60697

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/Type.cpp
clang/test/SemaCXX/constrained-special-member-functions.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 24ceac59a96a2..9c89bbc0d1786 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -58,6 +58,8 @@ C++ Specific Potentially Breaking Changes
 
 ABI Changes in This Version
 ---
+- ``__is_trivial`` has changed for a small category of classes with 
constrained default constructors (`#60697 
`_).
+  *FIXME: Remove this note if we've backported this change to the Clang 16 
branch.*
 
 What's New in Clang |release|?
 ==

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index f55cb8db0f728..04359c7d82cbc 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2501,11 +2501,13 @@ bool QualType::isTrivialType(const ASTContext &Context) 
const {
 return true;
   if (const auto *RT = CanonicalType->getAs()) {
 if (const auto *ClassDecl = dyn_cast(RT->getDecl())) {
-  // C++11 [class]p6:
-  //   A trivial class is a class that has a default constructor,
-  //   has no non-trivial default constructors, and is trivially
-  //   copyable.
-  return ClassDecl->hasDefaultConstructor() &&
+  // C++20 [class]p6:
+  //   A trivial class is a class that is trivially copyable, and
+  // has one or more eligible default constructors such that each is
+  // trivial.
+  // FIXME: We should merge this definition of triviality into
+  // CXXRecordDecl::isTrivial. Currently it computes the wrong thing.
+  return ClassDecl->hasTrivialDefaultConstructor() &&
  !ClassDecl->hasNonTrivialDefaultConstructor() &&
  ClassDecl->isTriviallyCopyable();
 }

diff  --git a/clang/test/SemaCXX/constrained-special-member-functions.cpp 
b/clang/test/SemaCXX/constrained-special-member-functions.cpp
index 69d50eb04c572..389f80d80e563 100644
--- a/clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ b/clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -265,3 +265,37 @@ static_assert(__is_trivially_constructible(C), "");
 static_assert(__is_trivially_constructible(D), "");
 
 }
+
+namespace GH60697 {
+
+template 
+struct X {
+X() requires false = default;
+};
+static_assert(!__is_trivial(X));
+
+template 
+struct S {
+S() requires(__is_trivially_constructible(T)) = default;
+
+S() requires(!__is_trivially_constructible(T) &&
+  __is_constructible(T)) {}
+
+T t;
+};
+
+struct D {
+D(int i) : i(i) {}
+int i;
+};
+static_assert(!__is_trivially_constructible(D));
+static_assert(!__is_constructible(D));
+static_assert(!__is_trivial(D));
+
+static_assert(!__is_trivially_constructible(S));
+static_assert(!__is_constructible(S));
+
+static_assert(__is_trivial(S));
+static_assert(!__is_trivial(S));
+
+}



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


[clang] 30af2fb - [NFC][Clang] Remove release note since the patch was backported in time

2023-05-05 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-05-05T17:54:40+03:00
New Revision: 30af2fb33ed2f610abfa50e53df9712887b2bd25

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

LOG: [NFC][Clang] Remove release note since the patch was backported in time

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e0ad5f5e3ae53..a41917a5ed66a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -58,8 +58,7 @@ C++ Specific Potentially Breaking Changes
 
 ABI Changes in This Version
 ---
-- ``__is_trivial`` has changed for a small category of classes with 
constrained default constructors (`#60697 
`_).
-  *FIXME: Remove this note if we've backported this change to the Clang 16 
branch.*
+
 
 What's New in Clang |release|?
 ==



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


[clang] 0f59bee - [Sema] Mark ineligibility of special member functions correctly

2023-05-19 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2023-05-19T17:29:12+03:00
New Revision: 0f59bee3d58f5dc7914d58aa520e65f3ba986705

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

LOG: [Sema] Mark ineligibility of special member functions correctly

I checked if the member function declaration was a copy constructor, but it's 
not sufficient; We need to check
the arguments against the instantiated class.

Fixed https://github.com/llvm/llvm-project/issues/62555

Reviewed By: erichkeane

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/SemaCXX/constrained-special-member-functions.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b0f848d47a67..1dd3d8a0ed80 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -58,7 +58,8 @@ C++ Specific Potentially Breaking Changes
 
 ABI Changes in This Version
 ---
-
+- A bug in evaluating the ineligibility of some special member functions has 
been fixed. This can
+  make some classes trivially copyable that were not trivially copyable 
before. (`#62555 `_)
 
 What's New in Clang |release|?
 ==

diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 3c78343eb861..480cefd1efcd 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2524,9 +2524,6 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl(
 Constructor->getConstexprKind(), InheritedConstructor(),
 TrailingRequiresClause);
 Method->setRangeEnd(Constructor->getEndLoc());
-if (Constructor->isDefaultConstructor() ||
-Constructor->isCopyOrMoveConstructor())
-  Method->setIneligibleOrNotSelected(true);
   } else if (CXXDestructorDecl *Destructor = dyn_cast(D)) {
 Method = CXXDestructorDecl::Create(
 SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo,
@@ -2549,8 +2546,6 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl(
 SemaRef.Context, Record, StartLoc, NameInfo, T, TInfo, SC,
 D->UsesFPIntrin(), D->isInlineSpecified(), D->getConstexprKind(),
 D->getEndLoc(), TrailingRequiresClause);
-if (D->isMoveAssignmentOperator() || D->isCopyAssignmentOperator())
-  Method->setIneligibleOrNotSelected(true);
   }
 
   if (D->isInlined())
@@ -2753,6 +2748,22 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl(
   if (IsExplicitSpecialization && !isFriend)
 SemaRef.CompleteMemberSpecialization(Method, Previous);
 
+  // If the method is a special member function, we need to mark it as
+  // ineligible so that Owner->addDecl() won't mark the class as non trivial.
+  // At the end of the class instantiation, we calculate eligibility again and
+  // then we adjust trivility if needed.
+  // We need this check to happen only after the method parameters are set,
+  // because being e.g. a copy constructor depends on the instantiated
+  // arguments.
+  if (auto *Constructor = dyn_cast(Method)) {
+if (Constructor->isDefaultConstructor() ||
+Constructor->isCopyOrMoveConstructor())
+  Method->setIneligibleOrNotSelected(true);
+  } else if (Method->isCopyAssignmentOperator() ||
+ Method->isMoveAssignmentOperator()) {
+Method->setIneligibleOrNotSelected(true);
+  }
+
   // If there's a function template, let our caller handle it.
   if (FunctionTemplate) {
 // do nothing

diff  --git a/clang/test/SemaCXX/constrained-special-member-functions.cpp 
b/clang/test/SemaCXX/constrained-special-member-functions.cpp
index 389f80d80e56..8ac17e7838ef 100644
--- a/clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ b/clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -299,3 +299,16 @@ static_assert(__is_trivial(S));
 static_assert(!__is_trivial(S));
 
 }
+
+namespace GH62555 {
+
+template 
+struct ExplicitTemplateArgs {
+ExplicitTemplateArgs(ExplicitTemplateArgs&&) = default;
+ExplicitTemplateArgs(ExplicitTemplateArgs&&) requires B {};
+};
+
+static_assert(__is_trivially_copyable(ExplicitTemplateArgs));
+static_assert(__is_trivially_copyable(ExplicitTemplateArgs));
+
+}



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


[clang] 7d58c95 - [Clang] Don't consider default constructors ineligible if the more constrained constructor is a template

2022-12-05 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-12-05T23:02:37+02:00
New Revision: 7d58c95635cce63ce6acd43c953b57f10bf5c686

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

LOG: [Clang] Don't consider default constructors ineligible if the more 
constrained constructor is a template

Partially solves https://github.com/llvm/llvm-project/issues/59206:

We now mark trivial constructors as eligible even if there's a more constrained 
templated default constructor. Although technically non-conformant, this solves 
problems with pretty reasonable uses cases like
```
template
struct Foo {
constexpr Foo() = default;

template
Foo(Ts... vals) requires(sizeof...(Ts) == n) {}
};
```
where we currently consider the default constructor to be ineligible and 
therefor inheriting/containing classes have non trivial constructors. This is 
aligned with GCC: 
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=c75ebe76ae12ac4020f20a24f34606a594a40d15

This doesn't change `__is_trivial`. Although we're technically standard 
conformant in this regard, GCC/MSVC exhibit different behaviors that seem to 
make more sense. An issue has been filed to CWG and we await their response.

Reviewed By: erichkeane, #clang-language-wg

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

Added: 


Modified: 
clang/lib/AST/DeclCXX.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/constrained-special-member-functions.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index bc7589e418f2c..603075702a837 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1378,7 +1378,11 @@ void 
CXXRecordDecl::addedSelectedDestructor(CXXDestructorDecl *DD) {
 }
 
 void CXXRecordDecl::addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD,
-   unsigned SMKind) {
+   unsigned SMKind) {
+  // FIXME: We shouldn't change DeclaredNonTrivialSpecialMembers if `MD` is
+  // a function template, but this needs CWG attention before we break ABI.
+  // See https://github.com/llvm/llvm-project/issues/59206
+
   if (const auto *DD = dyn_cast(MD)) {
 if (DD->isUserProvided())
   data().HasIrrelevantDestructor = false;

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 96ea3fb402e74..0b6e2e5564870 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -18193,8 +18193,11 @@ static bool 
AreSpecialMemberFunctionsSameKind(ASTContext &Context,
   CXXMethodDecl *M1,
   CXXMethodDecl *M2,
   Sema::CXXSpecialMember CSM) {
+  // We don't want to compare templates to non-templates: See
+  // https://github.com/llvm/llvm-project/issues/59206
   if (CSM == Sema::CXXDefaultConstructor)
-return true;
+return bool(M1->getDescribedFunctionTemplate()) ==
+   bool(M2->getDescribedFunctionTemplate());
   if (!Context.hasSameType(M1->getParamDecl(0)->getType(),
M2->getParamDecl(0)->getType()))
 return false;

diff  --git a/clang/test/SemaCXX/constrained-special-member-functions.cpp 
b/clang/test/SemaCXX/constrained-special-member-functions.cpp
index 33ed4050553b8..69d50eb04c572 100644
--- a/clang/test/SemaCXX/constrained-special-member-functions.cpp
+++ b/clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -225,3 +225,43 @@ void func() {
   S<2, 2> s2;
 }
 }
+
+namespace GH59206 {
+
+struct A {
+  A() = default; //eligible, second constructor unsatisfied
+  template
+  A(Args&&... args) requires (sizeof...(Args) > 0) {}
+};
+
+struct B {
+  B() = default; //ineligible, second constructor more constrained
+  template
+  B(Args&&... args) requires (sizeof...(Args) == 0) {}
+};
+
+struct C {
+  C() = default; //eligible, but
+  template //also eligible and non-trivial
+  C(Args&&... args) {}
+};
+
+struct D : B {};
+
+static_assert(__is_trivially_copyable(A), "");
+static_assert(__is_trivially_copyable(B), "");
+static_assert(__is_trivially_copyable(C), "");
+static_assert(__is_trivially_copyable(D), "");
+
+// FIXME: Update when https://github.com/llvm/llvm-project/issues/59206 is
+// resolved.
+static_assert(!__is_trivial(A), "");
+static_assert(!__is_trivial(B), "");
+static_assert(!__is_trivial(C), "");
+static_assert(__is_trivial(D), "");
+static_assert(__is_trivially_constructible(A), "");
+static_assert(__is_trivially_constructible(B), "");
+static_assert(__is_trivially_constructible(C), "");
+static_assert(__is_trivially_constructible(D), "");
+
+}



___
cfe-commits mailing list
cfe-commits@l