Type Traits with an empty parameter pack crashes. Also skip arity checks
| Bugzilla Link | 50494 |
| Version | trunk |
| OS | All |
| CC | @DougGregor,@futog,@zygoloid |
Extended Description
See this for example: https://godbolt.org/z/G8onvPEqM
template<typename ...Ts>
bool foo() {
return __is_pointer(Ts...);
}
void instant() {
foo<int>(); // #1
foo<int, int*>(); // #2
foo<>(); // #3
}
#1 works correctly.
#2 should probably emit a diagnostic, since now there are two parameters to a Unary type trait.
#3 should probably ALSO emit a diagnostic, since there are NO parameters to a unary type trait.
Hi, I'm taking a look. Regards, Gergely
Given the very limited intended scope of these builtins, I think it's fine to do whatever's simplest -- neither supporting nor rejecting a pack expansion in this context seems like it should be an explicit goal. If we already make an explicit attempt to make pack expansions work here, it might be easier to add the missing arity check than to remove the support (especially if it means we can share code between N-ary type traits and unary ones). But if we do choose to keep the support, I'd expect things like this to work:
template<typename ...T>
struct A {
template<typename ...U>
static bool b = __is_trivially_copyable(T..., U...);
};
... which we currently reject due to the early arity check.
Can we simply reject pack expansions in the argument of all unary type traits? The traits are only intended for use when implementing the corresponding standard library facilities, and we don't need to support pack expansion for that.
If YOU are ok with it, I am :) I just ran across it while developing a different feature and figured we should capture it.
If that is our approach, this is likely a somewhat easy 'fix', almost beginner level (for anyone watching:) ), since it just requires removing a little code during TreeTransform and during Parsing.
Can we simply reject pack expansions in the argument of all unary type traits? The traits are only intended for use when implementing the corresponding standard library facilities, and we don't need to support pack expansion for that.
assigned to @futog
@llvm/issue-subscribers-clang-frontend
Author: Erich Keane (erichkeane)
Extended Description
See this for example: https://godbolt.org/z/G8onvPEqM
template<typename ...Ts>
bool foo() {
return __is_pointer(Ts...);
}
void instant() {
foo<int>(); // #<!-- -->1
foo<int, int*>(); // #<!-- -->2
foo<>(); // #<!-- -->3
}
#<!-- -->1 works correctly.
#<!-- -->2 should probably emit a diagnostic, since now there are two parameters to a Unary type trait.
#<!-- -->3 should probably ALSO emit a diagnostic, since there are NO parameters to a unary type trait.
@llvm/issue-subscribers-c-11
Author: Erich Keane (erichkeane)
Extended Description
See this for example: https://godbolt.org/z/G8onvPEqM
template<typename ...Ts>
bool foo() {
return __is_pointer(Ts...);
}
void instant() {
foo<int>(); // #<!-- -->1
foo<int, int*>(); // #<!-- -->2
foo<>(); // #<!-- -->3
}
#<!-- -->1 works correctly.
#<!-- -->2 should probably emit a diagnostic, since now there are two parameters to a Unary type trait.
#<!-- -->3 should probably ALSO emit a diagnostic, since there are NO parameters to a unary type trait.
Appears to be fixed in Clang 16: https://godbolt.org/z/o9anj56K3