-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
Incorrect handling of incomplete types in std::derived_from
#121278
Comments
Note that https://cplusplus.github.io/LWG/lwg-active.html#3929 and https://cplusplus.github.io/LWG/lwg-active.html#2939 are related The fact that LWG suggest making it a Mandates (rather than a constraint) makes me question whether GCC is correct and this should always be a hard error (in which case it might be a clang bug) |
IMO we should reject such code, since it can easily result in really hard-to-find bugs. Given that the LWG issues you linked seem to agree with me here, I'd rather have Clang reject both implementations of |
…inae-friendly error 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 llvm#121278
…inae-friendly error 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 llvm#121278
…inae-friendly error 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 llvm#121278
Per https://eel.is/c++draft/meta#lib:is_base_of,
This is generally enforced by
__is_base_of
(the builtin used to implementis_base_of_v
)However, in libc++,
derived_from
is defined asllvm-project/libcxx/include/__concepts/derived_from.h
Line 27 in cb1ad98
And because the constraints are only enforced in
__is_base_of
which is not in the immediate context of theis_base_of_v
constraint, substituting an incomplete class inis_base_of_v
does not result in a substitution failure in the immediate context (which should just causederived_from
to not be satisfied per https://eel.is/c++draft/temp.constr.atomic#3.sentence-2) but instead makes the program ill-formed, which i believe is non-conforming.Note that GCC diverges in all cases. MSVC and EDG exposes what I believe to be the correct behavior.
I think there are 2 solutions:
derived_from
to use__is_base_of
directly (which is what libstdc++ and MS STL do)std::is_base_of_v
to check for completenesshttps://godbolt.org/z/zGrKEKEao
The text was updated successfully, but these errors were encountered: