cor3ntin updated this revision to Diff 498455. cor3ntin added a comment. - Simplify how we check we are in a dependent context - Fix typos
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D144285/new/ https://reviews.llvm.org/D144285 Files: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaDeclCXX.cpp clang/test/CXX/drs/dr25xx.cpp clang/test/SemaCXX/access-base-class.cpp clang/test/SemaCXX/coroutines-exp-namespace.cpp clang/test/SemaCXX/coroutines.cpp clang/test/SemaCXX/static-assert.cpp clang/test/SemaTemplate/instantiate-var-template.cpp clang/test/SemaTemplate/instantiation-dependence.cpp clang/www/cxx_dr_status.html
Index: clang/www/cxx_dr_status.html =================================================================== --- clang/www/cxx_dr_status.html +++ clang/www/cxx_dr_status.html @@ -14915,7 +14915,7 @@ <td><a href="https://wg21.link/cwg2518">2518</a></td> <td>review</td> <td>Conformance requirements and <TT>#error</TT>/<TT>#warning</TT></td> - <td align="center">Not resolved</td> + <td class="unreleased" align="center">Clang 17</td> </tr> <tr class="open" id="2519"> <td><a href="https://wg21.link/cwg2519">2519</a></td> Index: clang/test/SemaTemplate/instantiation-dependence.cpp =================================================================== --- clang/test/SemaTemplate/instantiation-dependence.cpp +++ clang/test/SemaTemplate/instantiation-dependence.cpp @@ -38,7 +38,7 @@ template<class T> void foo() { static_assert(!__is_void(indirect_void_t<T>)); // "ok", dependent - static_assert(!__is_void(void_t<T>)); // expected-error {{failed}} + static_assert(!__is_void(void_t<T>)); // fixme: can we check a type is dependent? } } Index: clang/test/SemaTemplate/instantiate-var-template.cpp =================================================================== --- clang/test/SemaTemplate/instantiate-var-template.cpp +++ clang/test/SemaTemplate/instantiate-var-template.cpp @@ -31,9 +31,9 @@ static_assert(b<char> == 1, ""); // expected-note {{in instantiation of}} template<typename T> void f() { - static_assert(a<sizeof(sizeof(f(T())))> == 0, ""); // expected-error {{static assertion failed due to requirement 'a<sizeof (sizeof (f(type-parameter-0-0())))> == 0'}} \ - // expected-note {{evaluates to '1 == 0'}} + static_assert(a<sizeof(sizeof(f(T())))> == 0, ""); // fixme: can we check a var is dependent? } + } namespace PR24483 { Index: clang/test/SemaCXX/static-assert.cpp =================================================================== --- clang/test/SemaCXX/static-assert.cpp +++ clang/test/SemaCXX/static-assert.cpp @@ -54,7 +54,7 @@ // Only give one error here. static_assert(false, ""); // expected-error {{static assertion failed}} }; -AlwaysFails<int> alwaysFails; +AlwaysFails<int> alwaysFails; // expected-note {{instantiation}} template<typename T> struct StaticAssertProtected { static_assert(__is_literal(T), ""); // expected-error {{static assertion failed}} Index: clang/test/SemaCXX/coroutines.cpp =================================================================== --- clang/test/SemaCXX/coroutines.cpp +++ clang/test/SemaCXX/coroutines.cpp @@ -1309,7 +1309,7 @@ } }; -template struct DepTestType<int>; // expected-note {{requested here}} +template struct DepTestType<int>; // expected-note 2{{requested here}} template CoroMemberTag DepTestType<int>::test_member_template(long, const char *) const &&; template CoroMemberTag DepTestType<int>::test_static_template<void>(const char *volatile &, unsigned); Index: clang/test/SemaCXX/coroutines-exp-namespace.cpp =================================================================== --- clang/test/SemaCXX/coroutines-exp-namespace.cpp +++ clang/test/SemaCXX/coroutines-exp-namespace.cpp @@ -1288,7 +1288,7 @@ } }; -template struct DepTestType<int>; // expected-note {{requested here}} +template struct DepTestType<int>; // expected-note 2{{requested here}} template CoroMemberTag DepTestType<int>::test_member_template(long, const char *) const &&; template CoroMemberTag DepTestType<int>::test_static_template<void>(const char *volatile &, unsigned); Index: clang/test/SemaCXX/access-base-class.cpp =================================================================== --- clang/test/SemaCXX/access-base-class.cpp +++ clang/test/SemaCXX/access-base-class.cpp @@ -96,14 +96,14 @@ }; template <class T> -struct trait : flag<sizeof(T)> {}; +struct trait : flag<sizeof(T)> {}; // expected-note 2{{here}} -template <class T, bool Inferred = trait<T>::value> +template <class T, bool Inferred = trait<T>::value> // expected-note {{here}} struct a {}; template <class T> class b { - a<T> x; + a<T> x; // expected-note {{here}} using U = a<T>; }; @@ -113,5 +113,5 @@ }; // verify "no member named 'value'" bogus diagnostic is not emitted. -trait<b<Impossible<0>>>::value; +trait<b<Impossible<0>>>::value; // expected-note {{here}} } // namespace T8 Index: clang/test/CXX/drs/dr25xx.cpp =================================================================== --- clang/test/CXX/drs/dr25xx.cpp +++ clang/test/CXX/drs/dr25xx.cpp @@ -1,5 +1,33 @@ // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify +namespace dr2518 { // dr2518: 17 review + +#error one +// expected-error@-1 {{one}} +#if 0 +#error skip +#warning skip // expected-error {{skip}} +#endif +#error two +// expected-error@-1 {{two}} +#warning warn +// expected-warning@-1 {{warn}} + +template <class T> +void f(T t) { + if constexpr (sizeof(T) != sizeof(int)) { + static_assert(false, "must be int-sized"); // expected-error {{must be int-size}} + } +} + +void g(char c) { + f(0); + f(c); // expected-note {{requested here}} +} + +} + + namespace dr2565 { // dr2565: 16 open template<typename T> concept C = requires (typename T::type x) { Index: clang/lib/Sema/SemaDeclCXX.cpp =================================================================== --- clang/lib/Sema/SemaDeclCXX.cpp +++ clang/lib/Sema/SemaDeclCXX.cpp @@ -16799,7 +16799,14 @@ FoldKind).isInvalid()) Failed = true; - if (!Failed && !Cond) { + // CWG2518 + // [dcl.pre]/p10 If [...] the expression is evaluated in the context of a + // template definition, the declaration has no effect. + bool InTemplateDefinition = + getLangOpts().CPlusPlus && CurContext->isDependentContext(); + + if (!Failed && !Cond && !InTemplateDefinition) { + SmallString<256> MsgBuffer; llvm::raw_svector_ostream Msg(MsgBuffer); if (AssertMessage) { Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -59,6 +59,8 @@ - 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. +- Implemented `CWG2518 <https://wg21.link/CWG2518>`_ which allows ``static_assert(false)`` + not to be ill-formed when its condition is evaluated in a non-instantiated templates. C++20 Feature Support ^^^^^^^^^^^^^^^^^^^^^
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits