Skip to content

Commit 3f79057

Browse files
authored
[Clang] Make passing incomplete types to builtin type-traits a non-sfinae-friendly error (#121333)
LWG3929 suggests that passing incomplete types to __is_base_of and other builtins supporting [meta.unary] should result in a non-sfinaeable error. This is consistent with GCC's behavior and avoid inconsistency when using a builtin instead of a standard trait in a concept-definition. Fixes #121278
1 parent 69ba565 commit 3f79057

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,9 @@ Bug Fixes to C++ Support
886886
out of a module (which is the case e.g. in MSVC's implementation of ``std`` module). (#GH118218)
887887
- Fixed a pack expansion issue in checking unexpanded parameter sizes. (#GH17042)
888888
- Fixed a bug where captured structured bindings were modifiable inside non-mutable lambda (#GH95081)
889+
- Passing incomplete types to ``__is_base_of`` and other builtin type traits for which the corresponding
890+
standard type trait mandates a complete type is now a hard (non-sfinae-friendly) error
891+
(`LWG3929 <https://wg21.link/LWG3929>`__.) (#GH121278)
889892
- Clang now identifies unexpanded parameter packs within the type constraint on a non-type template parameter. (#GH88866)
890893
- Fixed an issue while resolving type of expression indexing into a pack of values of non-dependent type (#GH121242)
891894

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9361,7 +9361,7 @@ def note_inequality_comparison_to_or_assign : Note<
93619361
"use '|=' to turn this inequality comparison into an or-assignment">;
93629362

93639363
def err_incomplete_type_used_in_type_trait_expr : Error<
9364-
"incomplete type %0 used in type trait expression">;
9364+
"incomplete type %0 used in type trait expression">, NoSFINAE;
93659365

93669366
// C++20 constinit and require_constant_initialization attribute
93679367
def warn_cxx20_compat_constinit : Warning<

clang/test/SemaCXX/type-traits.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5031,3 +5031,18 @@ void remove_all_extents() {
50315031
using SomeArray = int[1][2];
50325032
static_assert(__is_same(remove_all_extents_t<const SomeArray>, const int));
50335033
}
5034+
5035+
namespace GH121278 {
5036+
// https://cplusplus.github.io/LWG/lwg-active.html#3929
5037+
#if __cplusplus >= 202002L
5038+
template <typename B, typename D>
5039+
concept C = __is_base_of(B, D);
5040+
// expected-error@-1 {{incomplete type 'GH121278::S' used in type trait expression}}
5041+
// expected-note@-2 {{while substituting template arguments into constraint expression here}}
5042+
5043+
struct T;
5044+
struct S;
5045+
bool b = C<T, S>;
5046+
// expected-note@-1 {{while checking the satisfaction of concept 'C<GH121278::T, GH121278::S>' requested here}}
5047+
#endif
5048+
}

0 commit comments

Comments
 (0)