[clang] 1bbaabb - [clang] Add test for CWG1710 and related issues

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 11 06:24:46 PDT 2023


Author: Vlad Serebrennikov
Date: 2023-07-11T16:24:39+03:00
New Revision: 1bbaabb90dd72f78ea290b71dfe3bf2689ad7403

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

LOG: [clang] Add test for CWG1710 and related issues

Those issues focus on `template` keyword being optional in certain type-only contexts (base specifiers, member initializers, typename specifiers), as opposed to be disallowed by the grammar, or required by some implementations. GCC accepts all the tests this patch touches since 10, others fail on various tests: https://godbolt.org/z/1M6KE3W1a

It should be noted that the wording in [[ https://cplusplus.github.io/CWG/issues/1710.html | 1710 ]] that resolves those issues has been substantially changed by [[ https://wg21.link/p1787 | P1787 ]]. I can't find the post-P1787 wording that covers those issues, but I can't find the intent of changing relevant behavior in P1787 either, so I assume that intent of the 1710 resolution is preserved somewhere.

This patch covers the following issues:
[[ https://cplusplus.github.io/CWG/issues/314.html  | CWG314 ]]
[[ https://cplusplus.github.io/CWG/issues/343.html  | CWG343 ]]
[[ https://cplusplus.github.io/CWG/issues/1710.html | CWG1710 ]]
[[ https://cplusplus.github.io/CWG/issues/1794.html | CWG1794 ]]
[[ https://cplusplus.github.io/CWG/issues/1812.html | CWG1812 ]]

Reviewed By: #clang-language-wg, cor3ntin

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/test/CXX/drs/dr17xx.cpp b/clang/test/CXX/drs/dr17xx.cpp
index e91f4a6d69b3ac..219119d1a4cd08 100644
--- a/clang/test/CXX/drs/dr17xx.cpp
+++ b/clang/test/CXX/drs/dr17xx.cpp
@@ -1,7 +1,22 @@
 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
-// RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+
+namespace dr1710 { // dr1710: no
+// FIXME: all of the following is well-formed
+template <typename T> struct D1 : T::template B<int>::template C<int> {};
+template <typename T> struct D2 : T::B<int>::template C<int> {};
+// expected-error at -1 {{use 'template' keyword to treat 'B' as a dependent template name}}
+template <typename T> struct D3 : T::template B<int>::C<int> {};
+// expected-error at -1 {{use 'template' keyword to treat 'C' as a dependent template name}}
+template <typename T> struct D4 : T::B<int>::C<int> {};
+// expected-error at -1 {{use 'template' keyword to treat 'B' as a dependent template name}}
+// expected-error at -2 {{use 'template' keyword to treat 'C' as a dependent template name}}
+} // namespace dr1710
 
 namespace dr1715 { // dr1715: 3.9
 #if __cplusplus >= 201103L
@@ -146,3 +161,18 @@ namespace dr1778 { // dr1778: 9
   static_assert(noexcept(D()), "");
 #endif
 }
+
+namespace dr1794 { // dr1794: yes
+                   // NB: dup 1710
+#if __cplusplus >= 201103L
+template <template <typename> class Template> struct Internal {
+  template <typename Arg> using Bind = Template<Arg>;
+};
+
+template <template <typename> class Template, typename Arg>
+using Instantiate = Template<Arg>;
+
+template <template <typename> class Template, typename Argument>
+using Bind = Instantiate<Internal<Template>::template Bind, Argument>;
+#endif
+} // namespace dr1794

diff  --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index 3d57f5e5b74dbd..7ac26737382281 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -4,12 +4,23 @@
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
+// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
 
 #if __cplusplus < 201103L
 // expected-error at +1 {{variadic macro}}
 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
 #endif
 
+namespace dr1812 { // dr1812: no
+                   // NB: dup 1710
+#if __cplusplus >= 201103L
+template <typename T> struct A {
+  using B = typename T::C<int>;
+  // expected-error at -1 {{use 'template' keyword to treat 'C' as a dependent template name}}
+};
+#endif
+} // namespace dr1812
+
 namespace dr1813 { // dr1813: 7
   struct B { int i; };
   struct C : B {};

diff  --git a/clang/test/CXX/drs/dr3xx.cpp b/clang/test/CXX/drs/dr3xx.cpp
index 75b50d9ee065ce..aebb33fdd583cf 100644
--- a/clang/test/CXX/drs/dr3xx.cpp
+++ b/clang/test/CXX/drs/dr3xx.cpp
@@ -208,14 +208,20 @@ namespace dr313 { // dr313: dup 299 c++11
 #endif
 }
 
-namespace dr314 { // FIXME 314: dup 1710
-  template<typename T> struct A {
-    template<typename U> struct B {};
-  };
-  template<typename T> struct C : public A<T>::template B<T> {
-    C() : A<T>::template B<T>() {}
-  };
-}
+namespace dr314 { // dr314: no
+                  // NB: dup 1710
+template <typename T> struct A {
+  template <typename U> struct B {};
+};
+template <typename T> struct C : public A<T>::template B<T> {
+  C() : A<T>::template B<T>() {}
+};
+template <typename T> struct C2 : public A<T>::B<T> {
+  // expected-error at -1 {{use 'template' keyword to treat 'B' as a dependent template name}}
+  C2() : A<T>::B<T>() {}
+  // expected-error at -1 {{use 'template' keyword to treat 'B' as a dependent template name}}
+};
+} // namespace dr314
 
 // dr315: na
 // dr316: sup 1004
@@ -591,7 +597,7 @@ namespace dr341 {
 
 // dr342: na
 
-namespace dr343 { // FIXME 343: no
+namespace dr343 { // dr343: no
   // FIXME: dup 1710
   template<typename T> struct A {
     template<typename U> struct B {};

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 702d84ebba9859..07c51401b6b41e 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -1923,7 +1923,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/314.html">314</a></td>
     <td>C++17</td>
     <td><TT>template</TT> in base class specifier</td>
-    <td class="none" align="center">Unknown</td>
+    <td class="none" align="center">No</td>
   </tr>
   <tr id="315">
     <td><a href="https://cplusplus.github.io/CWG/issues/315.html">315</a></td>
@@ -2097,7 +2097,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/343.html">343</a></td>
     <td>C++17</td>
     <td>Make <TT>template</TT> optional in contexts that require a type</td>
-    <td class="none" align="center">Unknown</td>
+    <td class="none" align="center">No</td>
   </tr>
   <tr id="344">
     <td><a href="https://cplusplus.github.io/CWG/issues/344.html">344</a></td>
@@ -10067,7 +10067,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/1710.html">1710</a></td>
     <td>C++17</td>
     <td>Missing <TT>template</TT> keyword in <I>class-or-decltype</I></td>
-    <td class="none" align="center">Unknown</td>
+    <td class="none" align="center">No</td>
   </tr>
   <tr id="1711">
     <td><a href="https://cplusplus.github.io/CWG/issues/1711.html">1711</a></td>
@@ -10571,7 +10571,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/1794.html">1794</a></td>
     <td>C++17</td>
     <td><TT>template</TT> keyword and alias templates</td>
-    <td class="none" align="center">Unknown</td>
+    <td class="full" align="center">Yes</td>
   </tr>
   <tr id="1795">
     <td><a href="https://cplusplus.github.io/CWG/issues/1795.html">1795</a></td>
@@ -10679,7 +10679,7 @@ <h2 id="cxxdr">C++ defect report implementation status</h2>
     <td><a href="https://cplusplus.github.io/CWG/issues/1812.html">1812</a></td>
     <td>C++17</td>
     <td>Omission of <TT>template</TT> in a <I>typename-specifier</I></td>
-    <td class="none" align="center">Unknown</td>
+    <td class="none" align="center">No</td>
   </tr>
   <tr id="1813">
     <td><a href="https://cplusplus.github.io/CWG/issues/1813.html">1813</a></td>


        


More information about the cfe-commits mailing list