Skip to content

[clang] Add tests for some CWG 5xx issues #87909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2024
Merged

[clang] Add tests for some CWG 5xx issues #87909

merged 3 commits into from
Apr 12, 2024

Conversation

Endilll
Copy link
Contributor

@Endilll Endilll commented Apr 7, 2024

This patch covers
CWG393 "Pointer to array of unknown bound in template argument list in parameter",
CWG528 "Why are incomplete class types not allowed with typeid?",
CWG550 "Pointer to array of unknown bound in parameter declarations",
CWG553 "Problems with friend allocation and deallocation functions",
CWG555 "Pseudo-destructor name lookup",
CWG560 "Use of the typename keyword in return types".

CWG393 is on this list, because CWG550 is marked as a duplicate of CWG393.

Test for CWG553 has been already written, but it was missing a status comment. As a drive-by fix, I'm adding missing status comments to CWG1584 and CWG1903 as well.

CWG555 used CWG466 test, and also a variation of that test to test references. CWG466 is now testing non-reference non-pointer case.

CWG560 showcases again that converting warnings to errors in DR tests via -pedantic-errors doesn't make things more clear. By default that test is accepted with an extension warning since we implemented P0634R3 "Down with typename!" in Clang 16.

@Endilll Endilll added clang Clang issues not falling into any other category test-suite c++ labels Apr 7, 2024
@llvmbot
Copy link
Member

llvmbot commented Apr 7, 2024

@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)

Changes

This patch covers
CWG393 "Pointer to array of unknown bound in template argument list in parameter"
CWG528 "Why are incomplete class types not allowed with typeid?"
CWG550 "Pointer to array of unknown bound in parameter declarations"
CWG553 "Problems with friend allocation and deallocation functions"
CWG555 "Pseudo-destructor name lookup"
CWG560 "Use of the typename keyword in return types"

CWG393 is on this list, because CWG550 is marked as a duplicate of CWG393.

Test for CWG553 has been already written, but it was missing a status comment. As a drive-by fix, I'm adding missing status comments to CWG1584 and CWG1903 as well.

I consider CWG555 a pure wording change. I believe that few functional lookup issues that it briefly mentions are tested as a part of CWG466.

CWG560 showcases again that converting warnings to errors in DR tests via -pedantic-errors doesn't make things more clear. By default that test is accepted with an extension warning since we implemented P0634R3 "Down with typename!" in Clang 16.


Full diff: https://github.com/llvm/llvm-project/pull/87909.diff

5 Files Affected:

  • (modified) clang/test/CXX/drs/dr15xx.cpp (+1-1)
  • (modified) clang/test/CXX/drs/dr19xx.cpp (+1-1)
  • (modified) clang/test/CXX/drs/dr3xx.cpp (+12)
  • (modified) clang/test/CXX/drs/dr5xx.cpp (+37)
  • (modified) clang/www/cxx_dr_status.html (+8-8)
diff --git a/clang/test/CXX/drs/dr15xx.cpp b/clang/test/CXX/drs/dr15xx.cpp
index 195c0fa610d579..6e3ad41c748fb1 100644
--- a/clang/test/CXX/drs/dr15xx.cpp
+++ b/clang/test/CXX/drs/dr15xx.cpp
@@ -555,7 +555,7 @@ auto DR1579_lambda_invalid = []() -> GenericMoveOnly<char> {
 #endif
 } // end namespace dr1579
 
-namespace dr1584 {
+namespace dr1584 { // dr1584: 7 drafting 2015-05
 #if __cplusplus >= 201103L
   // Deducing function types from cv-qualified types
   template<typename T> void f(const T *); // #dr1584-f
diff --git a/clang/test/CXX/drs/dr19xx.cpp b/clang/test/CXX/drs/dr19xx.cpp
index 716b1476831ed9..f8c1581f08540e 100644
--- a/clang/test/CXX/drs/dr19xx.cpp
+++ b/clang/test/CXX/drs/dr19xx.cpp
@@ -34,7 +34,7 @@ namespace dr1902 { // dr1902: 3.7
 #endif
 }
 
-namespace dr1903 {
+namespace dr1903 { // dr1903: 2.7
   namespace A {
     struct a {};
     int a;
diff --git a/clang/test/CXX/drs/dr3xx.cpp b/clang/test/CXX/drs/dr3xx.cpp
index 483ebf7a08aadb..6165835e2c183d 100644
--- a/clang/test/CXX/drs/dr3xx.cpp
+++ b/clang/test/CXX/drs/dr3xx.cpp
@@ -1568,6 +1568,18 @@ namespace dr391 { // dr391: 2.8 c++11
 }
 
 // dr392 is in dr392.cpp
+
+namespace dr393 { // dr393: 2.7
+
+template <typename T>
+struct S {};
+
+void f1(S<int (*)[]>);
+void f2(S<int (&)[]>);
+void g(int(*S<int>::*)[]);
+
+} // namespace dr393
+
 // dr394: na
 
 namespace dr395 { // dr395: 3.0
diff --git a/clang/test/CXX/drs/dr5xx.cpp b/clang/test/CXX/drs/dr5xx.cpp
index 426b368b390ae6..981b9d1afca970 100644
--- a/clang/test/CXX/drs/dr5xx.cpp
+++ b/clang/test/CXX/drs/dr5xx.cpp
@@ -18,6 +18,10 @@ namespace std {
 void *operator new(size_t, std::align_val_t); // #dr5xx-global-operator-new-aligned
 #endif
 
+namespace std {
+  struct type_info;
+}
+
 namespace dr500 { // dr500: dup 372
   class D;
   class A {
@@ -265,6 +269,18 @@ namespace dr527 { // dr527: na
   int ax = a.x, bx = b.x, cx = c.x, dx = d.x, ex = E::e->x, fx = F::f->x;
 }
 
+namespace dr528 { // dr528: 2.7
+
+struct S; // #dr528-S
+
+void f() {
+  typeid(S);
+  // expected-error@-1 {{'typeid' of incomplete type 'S'}}
+  //   expected-note@#dr528-S {{forward declaration of 'dr528::S'}}
+}
+
+} // namespace dr528
+
 namespace dr530 { // dr530: yes
   template<int*> struct S { enum { N = 1 }; };
   template<void(*)()> struct T { enum { N = 1 }; };
@@ -618,6 +634,8 @@ namespace dr548 { // dr548: dup 482
   template void dr548::f<int>();
 }
 
+// dr550: dup 393
+
 namespace dr551 { // dr551: yes c++11
   // FIXME: This obviously should apply in C++98 mode too.
   template<typename T> void f() {}
@@ -641,6 +659,7 @@ namespace dr552 { // dr552: yes
   X<Y, 0> x;
 }
 
+// dr553: 2.7
 struct dr553_class {
   friend void *operator new(size_t, dr553_class);
 };
@@ -661,6 +680,10 @@ namespace dr553 {
 }
 
 // dr554: na
+
+// dr555: na
+// NB: name lookup cases that issue briefly touches are covered in our test for CWG466
+
 // dr556: na
 
 namespace dr557 { // dr557: 3.1
@@ -689,6 +712,20 @@ namespace dr558 { // dr558: 2.9
 
 template<typename> struct dr559 { typedef int T; dr559::T u; }; // dr559: yes
 
+namespace dr560 { // dr560: 16
+
+template <class T>
+struct Outer {
+  struct Inner {
+    Inner* self();
+  };
+};
+template <class T>
+Outer<T>::Inner* Outer<T>::Inner::self() { return this; }
+// cxx98-17-error@-1 {{missing 'typename' prior to dependent type name Outer<T>::Inner; implicit 'typename' is a C++20 extension}}
+
+} // namespace dr560
+
 namespace dr561 { // dr561: yes
   template<typename T> void f(int);
   template<typename T> void g(T t) {
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index a4c133c13c493f..15318bab81359b 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -2398,7 +2398,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/393.html">393</a></td>
     <td>CD4</td>
     <td>Pointer to array of unknown bound in template argument list in parameter</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="full" align="center">Clang 2.7</td>
   </tr>
   <tr id="394">
     <td><a href="https://cplusplus.github.io/CWG/issues/394.html">394</a></td>
@@ -3208,7 +3208,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/528.html">528</a></td>
     <td>NAD</td>
     <td>Why are incomplete class types not allowed with <TT>typeid</TT>?</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="full" align="center">Clang 2.7</td>
   </tr>
   <tr class="open" id="529">
     <td><a href="https://cplusplus.github.io/CWG/issues/529.html">529</a></td>
@@ -3342,7 +3342,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/550.html">550</a></td>
     <td>dup</td>
     <td>Pointer to array of unknown bound in parameter declarations</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="full" align="center">Duplicate of <a href="#393">393</a></td>
   </tr>
   <tr id="551">
     <td><a href="https://cplusplus.github.io/CWG/issues/551.html">551</a></td>
@@ -3360,7 +3360,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/553.html">553</a></td>
     <td>NAD</td>
     <td>Problems with friend allocation and deallocation functions</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="full" align="center">Clang 2.7</td>
   </tr>
   <tr id="554">
     <td><a href="https://cplusplus.github.io/CWG/issues/554.html">554</a></td>
@@ -3372,7 +3372,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/555.html">555</a></td>
     <td>CD5</td>
     <td>Pseudo-destructor name lookup</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="na" align="center">N/A</td>
   </tr>
   <tr id="556">
     <td><a href="https://cplusplus.github.io/CWG/issues/556.html">556</a></td>
@@ -3402,7 +3402,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/560.html">560</a></td>
     <td>NAD</td>
     <td>Use of the <TT>typename</TT> keyword in return types</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="full" align="center">Clang 16</td>
   </tr>
   <tr id="561">
     <td><a href="https://cplusplus.github.io/CWG/issues/561.html">561</a></td>
@@ -9312,7 +9312,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/1584.html">1584</a></td>
     <td>drafting</td>
     <td>Deducing function types from cv-qualified types</td>
-    <td align="center">Not resolved</td>
+    <td title="Clang 7 implements 2015-05 resolution" align="center">Not Resolved*</td>
   </tr>
   <tr id="1585">
     <td><a href="https://cplusplus.github.io/CWG/issues/1585.html">1585</a></td>
@@ -11226,7 +11226,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/1903.html">1903</a></td>
     <td>CD4</td>
     <td>What declarations are introduced by a non-member <I>using-declaration</I>?</td>
-    <td class="unknown" align="center">Unknown</td>
+    <td class="full" align="center">Clang 2.7</td>
   </tr>
   <tr id="1904">
     <td><a href="https://cplusplus.github.io/CWG/issues/1904.html">1904</a></td>

@@ -661,6 +680,10 @@ namespace dr553 {
}

// dr554: na

// dr555: na
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth copying these tests.
I agree that the changes are non-behavioral but I'd like @AaronBallman to give a second opinion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not keen to copy tests for an issue that is officially recognized as duplicate.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://cplusplus.github.io/CWG/issues/555.html is not a duplicate, it's marked CD5 not dup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I confused this with CWG550, which is a duplicate.
I still would like to avoid copying tests, though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoiding copying tests is a good idea, that just means we need to come up with different tests. ;-)

CWG466 is solely about cv-qualification and pseudo destructors. CWG555 is more about lookup issues and was resolved by P1131R2. We should be able to devise a different set of tests for both, unless I'm missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a proper test for 555. Basically, I copied 466 test, and derived reference tests from it. In 466, I derived a test for non-pointer and non-reference scalar types.

Finally, there is no place in the Standard that describes the lookup for pseudo-destructor calls of the form p->T::~T() and r.T::~T(), where p and r are a pointer and reference to scalar, respectively.

As we agreed offline, I'm testing just this sentence from 555, as that's the only actionable thing there for us.

Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Endilll Endilll merged commit 5ebeaf2 into llvm:main Apr 12, 2024
@Endilll Endilll deleted the cwg5xx branch April 12, 2024 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ clang Clang issues not falling into any other category test-suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants