[PATCH] D122083: [Concepts] Fix placeholder constraints when references are involved

2022-03-23 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG94fd00f41ebd: [Concepts] Fix placeholder constraints when 
references are involved (authored by royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122083

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

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -171,7 +171,7 @@
 }
 
 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 @@
   }
   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 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 @@
 };
 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_same { static constexpr bool value = true; };
+
+template 
+concept same_as = is_same::value; // expected-note-re 4 {{because {{.*}} evaluated to false}}
+
+int const ();
+
+same_as auto i1 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as'}}
+same_as auto  = f();
+same_as auto & = f(); // expected-error {{deduced type 'const int &' does not satisfy 'same_as'}}
+
+same_as auto i4 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as'}}
+same_as auto  = f(); // expected-error {{deduced type 'const int' does not satisfy 'same_as'}}
+same_as auto & = f();
+
+template 
+concept C = false; // expected-note 3 {{because 'false' evaluated to false}}
+
+int **const ();
+
+C auto **j1 = g();   // expected-error {{deduced type 'int' does not satisfy 'C'}}
+C auto ** = g();  // expected-error {{deduced type 'int' does not satisfy 'C'}}
+C auto **& = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}}
+}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4769,12 +4769,13 @@
   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;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -65,6 +65,10 @@
   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 

[PATCH] D122083: [Concepts] Fix placeholder constraints when references are involved

2022-03-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 417624.
royjacobson added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122083

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

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -171,7 +171,7 @@
 }
 
 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 @@
   }
   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 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 @@
 };
 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_same { static constexpr bool value = true; };
+
+template 
+concept same_as = is_same::value; // expected-note-re 4 {{because {{.*}} evaluated to false}}
+
+int const ();
+
+same_as auto i1 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as'}}
+same_as auto  = f();
+same_as auto & = f(); // expected-error {{deduced type 'const int &' does not satisfy 'same_as'}}
+
+same_as auto i4 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as'}}
+same_as auto  = f(); // expected-error {{deduced type 'const int' does not satisfy 'same_as'}}
+same_as auto & = f();
+
+template 
+concept C = false; // expected-note 3 {{because 'false' evaluated to false}}
+
+int **const ();
+
+C auto **j1 = g();   // expected-error {{deduced type 'int' does not satisfy 'C'}}
+C auto ** = g();  // expected-error {{deduced type 'int' does not satisfy 'C'}}
+C auto **& = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}}
+}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4769,12 +4769,13 @@
   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;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -65,6 +65,10 @@
   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
 ^^^
___
cfe-commits 

[PATCH] D122083: [Concepts] Fix placeholder constraints when references are involved

2022-03-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122083

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


[PATCH] D122083: [Concepts] Fix placeholder constraints when references are involved

2022-03-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 417618.
royjacobson added a comment.

Added release notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122083

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

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -171,7 +171,7 @@
 }
 
 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 @@
   }
   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 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 @@
 };
 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_same { static constexpr bool value = true; };
+
+template 
+concept same_as = is_same::value; // expected-note-re 4 {{because {{.*}} evaluated to false}}
+
+int const ();
+
+same_as auto i1 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as'}}
+same_as auto  = f();
+same_as auto & = f(); // expected-error {{deduced type 'const int &' does not satisfy 'same_as'}}
+
+same_as auto i4 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as'}}
+same_as auto  = f(); // expected-error {{deduced type 'const int' does not satisfy 'same_as'}}
+same_as auto & = f();
+
+template 
+concept C = false; // expected-note 3 {{because 'false' evaluated to false}}
+
+int **const ();
+
+C auto **j1 = g();   // expected-error {{deduced type 'int' does not satisfy 'C'}}
+C auto ** = g();  // expected-error {{deduced type 'int' does not satisfy 'C'}}
+C auto **& = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}}
+}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4769,12 +4769,13 @@
   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;
 }
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -61,6 +61,10 @@
   size expression. This was fixed and ``::getArraySize()`` will now always
   either return ``None`` or a ``llvm::Optional`` wrapping a valid ``Expr*``.
   This fixes `Issue 53742 `_.
+- 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
 ^^^
___

[PATCH] D122083: [Concepts] Fix placeholder constraints when references are involved

2022-03-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D122083#3402523 , @royjacobson 
wrote:

> In D122083#3402445 , @erichkeane 
> wrote:
>
>> 1 more test I'd like to see that doesn't seem covered (ref to ptr),
>
> Added, good idea.
>
>> AND according to @aaron.ballman we need "Release Notes" for this.  Otherwise 
>> LGTM.  Do you have commit rights yet?
>
> Yeah, I got commit rights :)
> This should go into "Bug Fixes" section in `clang/docs/ReleaseNotes.rst`, 
> right? Or "C++20 Feature Support"?

I'd suggest 'bug fixes'.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122083

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


[PATCH] D122083: [Concepts] Fix placeholder constraints when references are involved

2022-03-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

In D122083#3402445 , @erichkeane 
wrote:

> 1 more test I'd like to see that doesn't seem covered (ref to ptr),

Added, good idea.

> AND according to @aaron.ballman we need "Release Notes" for this.  Otherwise 
> LGTM.  Do you have commit rights yet?

Yeah, I got commit rights :)
This should go into "Bug Fixes" section in `clang/docs/ReleaseNotes.rst`, 
right? Or "C++20 Feature Support"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122083

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


[PATCH] D122083: [Concepts] Fix placeholder constraints when references are involved

2022-03-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 417602.
royjacobson added a comment.

Add test for auto**& combination


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122083

Files:
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaTemplate/concepts.cpp

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -171,7 +171,7 @@
 }
 
 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 @@
   }
   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 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 @@
 };
 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_same { static constexpr bool value = true; };
+
+template 
+concept same_as = is_same::value; // expected-note-re 4 {{because {{.*}} evaluated to false}}
+
+int const ();
+
+same_as auto i1 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as'}}
+same_as auto  = f();
+same_as auto & = f(); // expected-error {{deduced type 'const int &' does not satisfy 'same_as'}}
+
+same_as auto i4 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as'}}
+same_as auto  = f(); // expected-error {{deduced type 'const int' does not satisfy 'same_as'}}
+same_as auto & = f();
+
+template 
+concept C = false; // expected-note 3 {{because 'false' evaluated to false}}
+
+int **const ();
+
+C auto **j1 = g();   // expected-error {{deduced type 'int' does not satisfy 'C'}}
+C auto ** = g();  // expected-error {{deduced type 'int' does not satisfy 'C'}}
+C auto **& = g(); // expected-error {{deduced type 'int' does not satisfy 'C'}}
+}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4769,12 +4769,13 @@
   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;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122083: [Concepts] Fix placeholder constraints when references are involved

2022-03-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

In D122083#3402440 , @royjacobson 
wrote:

> In D122083#3402289 , @erichkeane 
> wrote:
>
>> Can you add some tests for the OTHER forms of 'auto' as well?  We have 
>> `decltype(auto)` and `auto_type`, and I want to make sure whatever we do 
>> with those 'looks right'.
>
> Can we have constraints on `__auto_type`? As far as I understand it, it's a C 
> extension with very limited C++ support.

I tried a couple and cannot convince GCC to let me deduce it.

> About decltype(auto) - we can't have `*`/`&` modifiers with it, and that's 
> already covered by tests like p7-cxx14.

Ah, right, thanks!

> So (I think?) it's always invalid code and it fails earlier during parsing.

Yep, thanks for that.

1 more test I'd like to see that doesn't seem covered (ref to ptr), AND 
according to @aaron.ballman we need "Release Notes" for this.  Otherwise LGTM.  
Do you have commit rights yet?




Comment at: clang/test/SemaTemplate/concepts.cpp:207
   }
-  C auto *f2() {
-return (int*)nullptr; // FIXME: should error
+  C auto *f2() { // expected-error {{deduced type 'int' does not satisfy 'C'}}
+return (int*)nullptr;

would also like `C auto*&`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122083

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


[PATCH] D122083: [Concepts] Fix placeholder constraints when references are involved

2022-03-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson marked an inline comment as done.
royjacobson added a comment.

In D122083#3402289 , @erichkeane 
wrote:

> Can you add some tests for the OTHER forms of 'auto' as well?  We have 
> `decltype(auto)` and `auto_type`, and I want to make sure whatever we do with 
> those 'looks right'.

Can we have constraints on `__auto_type`? As far as I understand it, it's a C 
extension with very limited C++ support.
About decltype(auto) - we can't have `*`/`&` modifiers with it, and that's 
already covered by tests like p7-cxx14.

So (I think?) it's always invalid code and it fails earlier during parsing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122083

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


[PATCH] D122083: [Concepts] Fix placeholder constraints when references are involved

2022-03-23 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 417591.
royjacobson added a comment.

Remove the curly brackets from one line loop.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122083

Files:
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaTemplate/concepts.cpp


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -171,7 +171,7 @@
 }
 
 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 @@
   }
   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 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,26 @@
 };
 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_same { static constexpr bool value = true; };
+
+template 
+concept same_as = is_same::value; // expected-note-re 4 {{because {{.*}} 
evaluated to false}}
+
+int const ();
+
+same_as auto i1 = f(); // expected-error {{deduced type 'int' does 
not satisfy 'same_as'}}
+same_as auto  = f();
+same_as auto & = f(); // expected-error {{deduced type 'const 
int &' does not satisfy 'same_as'}}
+
+same_as auto i4 = f(); // expected-error {{deduced type 'int' 
does not satisfy 'same_as'}}
+same_as auto  = f(); // expected-error {{deduced type 'const 
int' does not satisfy 'same_as'}}
+same_as auto & = f();
+
+}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4769,12 +4769,13 @@
   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;
 }


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -171,7 +171,7 @@
 }
 
 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 @@
   }
   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 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 

[PATCH] D122083: [Concepts] Fix placeholder constraints when references are involved

2022-03-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Can you add some tests for the OTHER forms of 'auto' as well?  We have 
`decltype(auto)` and `auto_type`, and I want to make sure whatever we do with 
those 'looks right'.




Comment at: clang/lib/Sema/SemaTemplateDeduction.cpp:4773
+  QualType MaybeAuto = Type.getType().getNonReferenceType();
+  while (MaybeAuto->isPointerType()) {
+MaybeAuto = MaybeAuto->getPointeeType();

We don't do curley braces on single-line blocks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122083

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


[PATCH] D122083: [Concepts] Fix placeholder constraints when references are involved

2022-03-20 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 416803.
royjacobson edited the summary of this revision.
royjacobson added a comment.

I noticed issue #53911 which is very similar so I fixed it as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122083

Files:
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaTemplate/concepts.cpp


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -171,7 +171,7 @@
 }
 
 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 @@
   }
   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 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,26 @@
 };
 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_same { static constexpr bool value = true; };
+
+template 
+concept same_as = is_same::value; // expected-note-re 4 {{because {{.*}} 
evaluated to false}}
+
+int const ();
+
+same_as auto i1 = f(); // expected-error {{deduced type 'int' does 
not satisfy 'same_as'}}
+same_as auto  = f();
+same_as auto & = f(); // expected-error {{deduced type 'const 
int &' does not satisfy 'same_as'}}
+
+same_as auto i4 = f(); // expected-error {{deduced type 'int' 
does not satisfy 'same_as'}}
+same_as auto  = f(); // expected-error {{deduced type 'const 
int' does not satisfy 'same_as'}}
+same_as auto & = f();
+
+}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4769,12 +4769,14 @@
   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;
 }


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -171,7 +171,7 @@
 }
 
 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 @@
   }
   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 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 

[PATCH] D122083: [Concepts] Fix placeholder constraints when references are involved

2022-03-19 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson created this revision.
Herald added a project: All.
royjacobson requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Placeholder types were not checked for constraint satisfaction when modified by 
references.
GitHub issue #54443


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122083

Files:
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/SemaTemplate/concepts.cpp


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -171,7 +171,7 @@
 }
 
 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 @@
   }
   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() {
@@ -222,3 +222,26 @@
 };
 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_same { static constexpr bool value = true; };
+
+template 
+concept same_as = is_same::value; // expected-note-re 4 {{because {{.*}} 
evaluated to false}}
+
+int const ();
+
+same_as auto i1 = f(); // expected-error {{deduced type 'int' does 
not satisfy 'same_as'}}
+same_as auto  = f();
+same_as auto & = f(); // expected-error {{deduced type 'const 
int &' does not satisfy 'same_as'}}
+
+same_as auto i4 = f(); // expected-error {{deduced type 'int' 
does not satisfy 'same_as'}}
+same_as auto  = f(); // expected-error {{deduced type 'const 
int' does not satisfy 'same_as'}}
+same_as auto & = f();
+
+}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4769,7 +4769,8 @@
   return DAR_FailedAlreadyDiagnosed;
   }
 
-  if (const auto *AT = Type.getType()->getAs()) {
+  if (const auto *AT =
+  Type.getType().getNonReferenceType()->getAs()) {
 if (AT->isConstrained() && !IgnoreConstraints) {
   auto ConstraintsResult =
   CheckDeducedPlaceholderConstraints(*this, *AT,


Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -171,7 +171,7 @@
 }
 
 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 @@
   }
   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() {
@@ -222,3 +222,26 @@
 };
 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_same { static constexpr bool value = true; };
+
+template 
+concept same_as = is_same::value; // expected-note-re 4 {{because {{.*}} evaluated to false}}
+
+int const ();
+
+same_as auto i1 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as'}}
+same_as auto  = f();
+same_as auto & = f(); // expected-error {{deduced type 'const int &' does not satisfy 'same_as'}}
+
+same_as auto i4 = f(); // expected-error {{deduced type 'int' does not satisfy 'same_as'}}
+same_as auto  = f(); // expected-error {{deduced type 'const int' does not satisfy 'same_as'}}
+same_as auto & = f();
+
+}
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4769,7 +4769,8 @@
   return DAR_FailedAlreadyDiagnosed;
   }
 
-  if (const auto *AT = Type.getType()->getAs()) {
+  if (const auto *AT =
+  Type.getType().getNonReferenceType()->getAs()) {
 if (AT->isConstrained() && !IgnoreConstraints) {
   auto ConstraintsResult =
   CheckDeducedPlaceholderConstraints(*this, *AT,