Skip to content

Commit

Permalink
[clang] Add test for CWG1710 and related issues
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Endilll committed Jul 11, 2023
1 parent bc49103 commit 1bbaabb
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 15 deletions.
32 changes: 31 additions & 1 deletion clang/test/CXX/drs/dr17xx.cpp
Original file line number Diff line number Diff line change
@@ -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@-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@-1 {{use 'template' keyword to treat 'C' as a dependent template name}}
template <typename T> struct D4 : T::B<int>::C<int> {};
// expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
// expected-error@-2 {{use 'template' keyword to treat 'C' as a dependent template name}}
} // namespace dr1710

namespace dr1715 { // dr1715: 3.9
#if __cplusplus >= 201103L
Expand Down Expand Up @@ -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
11 changes: 11 additions & 0 deletions clang/test/CXX/drs/dr18xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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@+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@-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 {};
Expand Down
24 changes: 15 additions & 9 deletions clang/test/CXX/drs/dr3xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
C2() : A<T>::B<T>() {}
// expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
};
} // namespace dr314

// dr315: na
// dr316: sup 1004
Expand Down Expand Up @@ -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 {};
Expand Down
10 changes: 5 additions & 5 deletions clang/www/cxx_dr_status.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 1bbaabb

Please sign in to comment.